Thinking in Tokens

The beginner's guide to AI Agents

The word "agent" gets attached to everything right now-usually to something that sounds either miraculous or completely made up.

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.

The whole idea

An AI agent is a software system that uses a language model to choose actions, observe the results, and decide what to do next.

Instead of answering a question once and stopping, it operates in a loop:

Goal -> decision -> action -> result -> next decision

That is the core idea. Everything else is implementation detail.

The model itself is not necessarily an agent. An agent is the model plus the tools, context, permissions, and control logic that let it operate in an environment.

Chatbot vs. agent: what actually changes?

A regular LLM interaction looks like this:

You ask a question -> model generates text -> done

An agent looks more like this:

You give a goal
-> model chooses an action
-> action runs
-> model receives the result
-> model chooses the next action
-> repeats until the goal is complete or the process stops

The difference is not necessarily that the agent uses a "smarter" model. The important difference is the loop.

A chatbot has one main opportunity to produce an answer. An agent can act, inspect what happened, and adjust-similar to debugging code:

  1. Run the program.
  2. Read the error.
  3. Change something.
  4. Run it again.

That does not make an agent intelligent in the human sense. It makes the system capable of taking multiple steps toward a goal.

Chatbot, workflow, or agent?

These terms are often used interchangeably, but they describe different levels of flexibility.

Chatbot: Responds to a user's input, usually with text.

"Explain how gradient descent works."

Workflow: Follows a predefined sequence.

Receive a support ticket -> classify it -> search the knowledge base -> draft a response.

Agent: Chooses the sequence dynamically.

Investigate this customer's billing problem and recommend a resolution.

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.

The four common pieces of an agent

Not every agent has exactly the same architecture, but most contain these four ingredients.

1. A model

The model interprets the goal, considers the available information, and selects the next step.

It might decide to search a database, call an API, ask the user a question, or stop and report that it cannot continue.

2. Tools

Tools are functions the model can call, such as:

Without tools, a model can still reason or generate text, but it cannot meaningfully interact with external systems.

Tools are often divided into three groups: data tools for retrieving information, action tools for changing something, and orchestration tools for delegating work to another agent or service.

3. Context or memory

The system needs to keep track of what has already happened during the task.

That may include:

"Memory" does not necessarily mean human-like long-term memory. In many systems, it simply means maintaining enough relevant context for the next decision.

4. A control loop

The control loop is the code that runs the process:

  1. Ask the model what to do.
  2. Execute the selected action.
  3. Feed the result back to the model.
  4. Repeat-or stop.

This is the part many tutorials gloss over. It is also what makes an agent different from a script that calls an API once.

A concrete example

Suppose you want an agent that answers:

"Is the latest deployment healthy? If not, why?"

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.

An agent could:

  1. Check the deployment status through a CI tool.
  2. Find that a test failed.
  3. Retrieve the logs for that test.
  4. Analyze the error.
  5. Decide whether it looks like a code defect or a flaky environment.
  6. Report the likely cause-or gather more information if necessary.

That is a working agent: a model, several tools, a control loop, and a clearly defined goal.

Where beginners get stuck

The loop needs a stopping condition

Without limits, an agent can continue calling tools indefinitely, wasting time and money.

Use safeguards such as:

Tool descriptions matter

The model only knows what a tool does from the name and description you provide.

A vague description such as:

get_data()

is much less useful than:

get_deployment_logs(deployment_id, since_minutes): returns error and warning logs from the specified deployment during the requested time window.

Clear names, arguments, descriptions, and examples improve tool selection.

More tools are not always better

An agent with three well-defined tools may outperform one with fifteen overlapping tools.

Too many tools create ambiguity:

Add tools when they solve a demonstrated limitation-not simply because the framework makes them easy to add.

Agents can fail silently

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.

During development, log:

Without those logs, debugging becomes guesswork.

How to build your first agent

You do not need a framework to understand the basic mechanism. Conceptually, the core loop looks like this:

while not done:
    action = model.decide(goal, history)

    if requires_human_approval(action):
        action = get_human_approval(action)

    result = run(action)
    history.append((action, result))

    done = model.check_if_finished(goal, history)

A real implementation also needs input validation, authentication, error handling, logging, rate limits, and permission controls. But the basic idea is still this simple.

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.

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.

When to use an agent-and when not to

Agents are useful when:

An agent may be the wrong choice when:

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.

The risks that matter

Agents can affect the outside world, so their risks are different from those of a text-only chatbot.

Incorrect actions

An agent may misunderstand the goal, choose the wrong tool, or continue from a false assumption. Errors can compound across multiple steps.

Excessive permissions

An agent that can read every file, modify production systems, send messages, or spend money has a large potential blast radius.

Give it the minimum access required. Read-only access is a good starting point.

Prompt injection

A webpage, email, document, or issue tracker entry may contain instructions designed to manipulate the agent.

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.

Untrusted tools

Third-party tools may return incorrect data, expose sensitive information, or contain security weaknesses. Tool access should be reviewed as carefully as model access.

Weak accountability

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.

A safe first project

Build a small research agent that:

  1. Accepts a topic
  2. Searches a limited set of trusted sources
  3. Extracts key claims
  4. Records citations
  5. Produces a structured brief
  6. Requires human review before publication

Start with read-only tools. Do not begin with unrestricted shell access, financial transactions, production deployment, or automatic email sending.

A sensible progression is:

  1. Make one model call.
  2. Add one read-only tool.
  3. Add structured output.
  4. Add a verification step.
  5. Log every action and result.
  6. Add human approval.
  7. Test against known examples.
  8. Expand the toolset only when necessary.

You will learn more from a small, observable agent than from a complicated multi-agent demo that you cannot explain or debug.

Where to go from here

Once the basic loop makes sense, explore:

None of these ideas matters if the basic architecture is unclear. Start with the four foundations: a model, tools, context, and a control loop.

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.

The takeaway

AI agents are not magic employees or fully autonomous intelligence.

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.

That is the practical way to think about agents:

Not a chatbot with a bigger marketing budget, but a model placed inside a controlled loop that can act, observe, and try again.