<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Thinking in Tokens - AI Agents</title><link href="https://blog.sijanb.com.np/" rel="alternate"/><link href="https://blog.sijanb.com.np/feeds/ai-agents.atom.xml" rel="self"/><id>https://blog.sijanb.com.np/</id><updated>2026-09-13T00:00:00+02:00</updated><entry><title>The beginner's guide to AI Agents</title><link href="https://blog.sijanb.com.np/articles/2026/09/the-beginners-guide-to-ai-agents/" rel="alternate"/><published>2026-09-13T00:00:00+02:00</published><updated>2026-09-13T00:00:00+02:00</updated><author><name>Sijan Bhandari</name></author><id>tag:blog.sijanb.com.np,2026-09-13:/articles/2026/09/the-beginners-guide-to-ai-agents/</id><summary type="html">&lt;p&gt;AI agents are not magic employees or fully autonomous intelligence. They are model-driven software systems that can choose actions within a defined environment.&lt;/p&gt;</summary><content type="html">&lt;p&gt;The word "agent" gets attached to everything right now-usually to something that sounds either miraculous or completely made up.&lt;/p&gt;
&lt;p&gt;This guide skips the hype. It explains what an AI agent actually is, how it differs from a chatbot, and what you need to understand before building one.&lt;/p&gt;
&lt;h2&gt;The whole idea&lt;/h2&gt;
&lt;p&gt;An AI agent is a software system that uses a language model to choose actions, observe the results, and decide what to do next.&lt;/p&gt;
&lt;p&gt;Instead of answering a question once and stopping, it operates in a loop:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Goal -&amp;gt; decision -&amp;gt; action -&amp;gt; result -&amp;gt; next decision&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;That is the core idea. Everything else is implementation detail.&lt;/p&gt;
&lt;p&gt;The model itself is not necessarily an agent. An agent is the model &lt;strong&gt;plus&lt;/strong&gt; the tools, context, permissions, and control logic that let it operate in an environment. &lt;/p&gt;
&lt;h2&gt;Chatbot vs. agent: what actually changes?&lt;/h2&gt;
&lt;p&gt;A regular LLM interaction looks like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;You ask a question -&amp;gt; model generates text -&amp;gt; done
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;An agent looks more like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;You give a goal
-&amp;gt; model chooses an action
-&amp;gt; action runs
-&amp;gt; model receives the result
-&amp;gt; model chooses the next action
-&amp;gt; repeats until the goal is complete or the process stops
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The difference is not necessarily that the agent uses a "smarter" model. The important difference is the loop.&lt;/p&gt;
&lt;p&gt;A chatbot has one main opportunity to produce an answer. An agent can act, inspect what happened, and adjust-similar to debugging code:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Run the program.&lt;/li&gt;
&lt;li&gt;Read the error.&lt;/li&gt;
&lt;li&gt;Change something.&lt;/li&gt;
&lt;li&gt;Run it again.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;That does not make an agent intelligent in the human sense. It makes the system capable of taking multiple steps toward a goal.&lt;/p&gt;
&lt;h2&gt;Chatbot, workflow, or agent?&lt;/h2&gt;
&lt;p&gt;These terms are often used interchangeably, but they describe different levels of flexibility.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Chatbot:&lt;/strong&gt; Responds to a user's input, usually with text.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"Explain how gradient descent works."&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;Workflow:&lt;/strong&gt; Follows a predefined sequence.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Receive a support ticket -&amp;gt; classify it -&amp;gt; search the knowledge base -&amp;gt; draft a response.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;Agent:&lt;/strong&gt; Chooses the sequence dynamically.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Investigate this customer's billing problem and recommend a resolution.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;A workflow follows a path that developers have mostly specified. An agent determines some of that path at runtime. Anthropic describes this distinction as the difference between predefined workflows and systems that dynamically direct their own process and tool use.&lt;/p&gt;
&lt;h2&gt;The four common pieces of an agent&lt;/h2&gt;
&lt;p&gt;Not every agent has exactly the same architecture, but most contain these four ingredients.&lt;/p&gt;
&lt;h3&gt;1. A model&lt;/h3&gt;
&lt;p&gt;The model interprets the goal, considers the available information, and selects the next step.&lt;/p&gt;
&lt;p&gt;It might decide to search a database, call an API, ask the user a question, or stop and report that it cannot continue.&lt;/p&gt;
&lt;h3&gt;2. Tools&lt;/h3&gt;
&lt;p&gt;Tools are functions the model can call, such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Searching the web&lt;/li&gt;
&lt;li&gt;Running code&lt;/li&gt;
&lt;li&gt;Querying a database&lt;/li&gt;
&lt;li&gt;Reading files&lt;/li&gt;
&lt;li&gt;Checking a monitoring system&lt;/li&gt;
&lt;li&gt;Sending an email&lt;/li&gt;
&lt;li&gt;Updating a ticket&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Without tools, a model can still reason or generate text, but it cannot meaningfully interact with external systems.&lt;/p&gt;
&lt;p&gt;Tools are often divided into three groups: &lt;strong&gt;data tools&lt;/strong&gt; for retrieving information, &lt;strong&gt;action tools&lt;/strong&gt; for changing something, and &lt;strong&gt;orchestration tools&lt;/strong&gt; for delegating work to another agent or service.&lt;/p&gt;
&lt;h3&gt;3. Context or memory&lt;/h3&gt;
&lt;p&gt;The system needs to keep track of what has already happened during the task.&lt;/p&gt;
&lt;p&gt;That may include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Previous messages&lt;/li&gt;
&lt;li&gt;Tool calls and their results&lt;/li&gt;
&lt;li&gt;Files or documents&lt;/li&gt;
&lt;li&gt;A summary of earlier steps&lt;/li&gt;
&lt;li&gt;Information retrieved from a database or vector store&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;"Memory" does not necessarily mean human-like long-term memory. In many systems, it simply means maintaining enough relevant context for the next decision.&lt;/p&gt;
&lt;h3&gt;4. A control loop&lt;/h3&gt;
&lt;p&gt;The control loop is the code that runs the process:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Ask the model what to do.&lt;/li&gt;
&lt;li&gt;Execute the selected action.&lt;/li&gt;
&lt;li&gt;Feed the result back to the model.&lt;/li&gt;
&lt;li&gt;Repeat-or stop.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This is the part many tutorials gloss over. It is also what makes an agent different from a script that calls an API once.&lt;/p&gt;
&lt;h2&gt;A concrete example&lt;/h2&gt;
&lt;p&gt;Suppose you want an agent that answers:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"Is the latest deployment healthy? If not, why?"&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;A plain LLM call cannot reliably answer that. It has no access to your monitoring dashboards, deployment system, or logs. Without that information, it can only guess.&lt;/p&gt;
&lt;p&gt;An agent could:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Check the deployment status through a CI tool.&lt;/li&gt;
&lt;li&gt;Find that a test failed.&lt;/li&gt;
&lt;li&gt;Retrieve the logs for that test.&lt;/li&gt;
&lt;li&gt;Analyze the error.&lt;/li&gt;
&lt;li&gt;Decide whether it looks like a code defect or a flaky environment.&lt;/li&gt;
&lt;li&gt;Report the likely cause-or gather more information if necessary.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;That is a working agent: a model, several tools, a control loop, and a clearly defined goal.&lt;/p&gt;
&lt;h2&gt;Where beginners get stuck&lt;/h2&gt;
&lt;h3&gt;The loop needs a stopping condition&lt;/h3&gt;
&lt;p&gt;Without limits, an agent can continue calling tools indefinitely, wasting time and money.&lt;/p&gt;
&lt;p&gt;Use safeguards such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A maximum number of steps&lt;/li&gt;
&lt;li&gt;A time limit&lt;/li&gt;
&lt;li&gt;A token or cost budget&lt;/li&gt;
&lt;li&gt;A list of actions that require approval&lt;/li&gt;
&lt;li&gt;A clear success condition&lt;/li&gt;
&lt;li&gt;A fallback when the agent cannot verify its answer&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Tool descriptions matter&lt;/h3&gt;
&lt;p&gt;The model only knows what a tool does from the name and description you provide.&lt;/p&gt;
&lt;p&gt;A vague description such as:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;get_data()&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;is much less useful than:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;get_deployment_logs(deployment_id, since_minutes): returns error and warning logs from the specified deployment during the requested time window.&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Clear names, arguments, descriptions, and examples improve tool selection.&lt;/p&gt;
&lt;h3&gt;More tools are not always better&lt;/h3&gt;
&lt;p&gt;An agent with three well-defined tools may outperform one with fifteen overlapping tools.&lt;/p&gt;
&lt;p&gt;Too many tools create ambiguity:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Which search tool should it use?&lt;/li&gt;
&lt;li&gt;Which database contains the authoritative data?&lt;/li&gt;
&lt;li&gt;Is it allowed to send the message or only draft it?&lt;/li&gt;
&lt;li&gt;What happens if two tools return conflicting results?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Add tools when they solve a demonstrated limitation-not simply because the framework makes them easy to add.&lt;/p&gt;
&lt;h3&gt;Agents can fail silently&lt;/h3&gt;
&lt;p&gt;A bad tool call may not crash the system. It may return incomplete, stale, or incorrect information. The model then reasons from that information and continues as if everything is fine.&lt;/p&gt;
&lt;p&gt;During development, log:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The model's selected action&lt;/li&gt;
&lt;li&gt;The tool arguments&lt;/li&gt;
&lt;li&gt;The tool result&lt;/li&gt;
&lt;li&gt;Errors and retries&lt;/li&gt;
&lt;li&gt;The reason the agent stopped&lt;/li&gt;
&lt;li&gt;Any human approvals or overrides&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Without those logs, debugging becomes guesswork.&lt;/p&gt;
&lt;h2&gt;How to build your first agent&lt;/h2&gt;
&lt;p&gt;You do not need a framework to understand the basic mechanism. Conceptually, the core loop looks like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;done&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;action&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;decide&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;goal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;requires_human_approval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;action&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;get_human_approval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

    &lt;span class="n"&gt;done&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;check_if_finished&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;goal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;A real implementation also needs input validation, authentication, error handling, logging, rate limits, and permission controls. But the basic idea is still this simple.&lt;/p&gt;
&lt;p&gt;Frameworks such as LangChain, CrewAI, and model-provider agent SDKs can handle parts of the plumbing: tool schemas, message formatting, retries, tracing, and orchestration. They can be useful, but they can also hide the underlying mechanics.&lt;/p&gt;
&lt;p&gt;If the loop does not make sense yet, build a small version by hand first. Otherwise, a framework may add a layer of abstraction over confusion.&lt;/p&gt;
&lt;h2&gt;When to use an agent-and when not to&lt;/h2&gt;
&lt;p&gt;Agents are useful when:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A task involves several steps&lt;/li&gt;
&lt;li&gt;The exact sequence cannot be known in advance&lt;/li&gt;
&lt;li&gt;The system must choose among multiple tools&lt;/li&gt;
&lt;li&gt;Inputs are varied or unstructured&lt;/li&gt;
&lt;li&gt;A human would otherwise coordinate several software systems&lt;/li&gt;
&lt;li&gt;The result can be checked or reviewed&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;An agent may be the wrong choice when:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A normal API call solves the problem&lt;/li&gt;
&lt;li&gt;The process is completely predictable&lt;/li&gt;
&lt;li&gt;Mistakes are unacceptable&lt;/li&gt;
&lt;li&gt;Very low latency is required&lt;/li&gt;
&lt;li&gt;There is no reliable way to verify the output&lt;/li&gt;
&lt;li&gt;The cost of repeated model calls outweighs the benefit&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A simple workflow is often cheaper, faster, and easier to test. Both OpenAI and Anthropic recommend starting with the simplest architecture that meets the task's requirements. &lt;/p&gt;
&lt;h2&gt;The risks that matter&lt;/h2&gt;
&lt;p&gt;Agents can affect the outside world, so their risks are different from those of a text-only chatbot.&lt;/p&gt;
&lt;h3&gt;Incorrect actions&lt;/h3&gt;
&lt;p&gt;An agent may misunderstand the goal, choose the wrong tool, or continue from a false assumption. Errors can compound across multiple steps.&lt;/p&gt;
&lt;h3&gt;Excessive permissions&lt;/h3&gt;
&lt;p&gt;An agent that can read every file, modify production systems, send messages, or spend money has a large potential blast radius.&lt;/p&gt;
&lt;p&gt;Give it the minimum access required. Read-only access is a good starting point.&lt;/p&gt;
&lt;h3&gt;Prompt injection&lt;/h3&gt;
&lt;p&gt;A webpage, email, document, or issue tracker entry may contain instructions designed to manipulate the agent.&lt;/p&gt;
&lt;p&gt;For example, an agent asked to summarize a webpage might encounter hidden text telling it to reveal confidential information or call an unrelated tool. Treat external content as data-not automatically as trusted instructions.&lt;/p&gt;
&lt;h3&gt;Untrusted tools&lt;/h3&gt;
&lt;p&gt;Third-party tools may return incorrect data, expose sensitive information, or contain security weaknesses. Tool access should be reviewed as carefully as model access.&lt;/p&gt;
&lt;h3&gt;Weak accountability&lt;/h3&gt;
&lt;p&gt;When several tools and agents interact, it can become difficult to explain why a particular action occurred. Logging, approval checkpoints, monitoring, and clear ownership are essential. Cybersecurity guidance for agentic systems emphasizes incremental deployment, human oversight, continuous monitoring, and carefully scoped tasks. &lt;/p&gt;
&lt;h2&gt;A safe first project&lt;/h2&gt;
&lt;p&gt;Build a small research agent that:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Accepts a topic&lt;/li&gt;
&lt;li&gt;Searches a limited set of trusted sources&lt;/li&gt;
&lt;li&gt;Extracts key claims&lt;/li&gt;
&lt;li&gt;Records citations&lt;/li&gt;
&lt;li&gt;Produces a structured brief&lt;/li&gt;
&lt;li&gt;Requires human review before publication&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Start with read-only tools. Do not begin with unrestricted shell access, financial transactions, production deployment, or automatic email sending.&lt;/p&gt;
&lt;p&gt;A sensible progression is:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Make one model call.&lt;/li&gt;
&lt;li&gt;Add one read-only tool.&lt;/li&gt;
&lt;li&gt;Add structured output.&lt;/li&gt;
&lt;li&gt;Add a verification step.&lt;/li&gt;
&lt;li&gt;Log every action and result.&lt;/li&gt;
&lt;li&gt;Add human approval.&lt;/li&gt;
&lt;li&gt;Test against known examples.&lt;/li&gt;
&lt;li&gt;Expand the toolset only when necessary.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You will learn more from a small, observable agent than from a complicated multi-agent demo that you cannot explain or debug.&lt;/p&gt;
&lt;h2&gt;Where to go from here&lt;/h2&gt;
&lt;p&gt;Once the basic loop makes sense, explore:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Planning versus one-step reaction&lt;/li&gt;
&lt;li&gt;Tool selection and structured outputs&lt;/li&gt;
&lt;li&gt;Short-term context versus long-term memory&lt;/li&gt;
&lt;li&gt;Retrieval-augmented generation&lt;/li&gt;
&lt;li&gt;Agent evaluation and observability&lt;/li&gt;
&lt;li&gt;Human approval patterns&lt;/li&gt;
&lt;li&gt;Multi-agent coordination&lt;/li&gt;
&lt;li&gt;Security and prompt-injection defenses&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;None of these ideas matters if the basic architecture is unclear. Start with the four foundations: a model, tools, context, and a control loop.&lt;/p&gt;
&lt;p&gt;Build a toy agent this week-even one that checks the weather and decides whether to remind you to bring an umbrella. A small working system will teach you more than most hype-heavy explanations.&lt;/p&gt;
&lt;h2&gt;The takeaway&lt;/h2&gt;
&lt;p&gt;AI agents are not magic employees or fully autonomous intelligence.&lt;/p&gt;
&lt;p&gt;They are model-driven software systems that can choose actions within a defined environment. Their usefulness depends less on how impressive the model sounds than on the quality of the tools, permissions, evaluation, and human oversight around it.&lt;/p&gt;
&lt;p&gt;That is the practical way to think about agents:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Not a chatbot with a bigger marketing budget, but a model placed inside a controlled loop that can act, observe, and try again.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;</content><category term="AI Agents"/><category term="ai-agents"/><category term="llm"/></entry></feed>