Suryanand/ Bootcamp
suryanand.com ↗Let's talk
← AgentsAI guideBeginner#agents#tool-use#architecture#fundamentals
Frame · ai-engineering / agents / 01-what-is-an-agent.mdGuide 025 / 103

What an AI agent is, and when not to build one

"Agent" is the most overloaded word in AI engineering right now. In this guide I use a narrow, practical definition: an agent is a language model that decides which tools to call, observes the results, and keeps looping until it reaches a stop condition. Everything else (memory, planning, multi-agent setups) is built on top of that loop, so it pays to understand the loop first and to be honest about when you do not need one.

Why it matters

Anthropic's "Building effective agents" post draws a useful line between two kinds of systems. Workflows are systems where models and tools are orchestrated through predefined code paths. Agents are systems where the model dynamically directs its own process and tool usage. Both are "agentic" in marketing copy, but they behave very differently in production.

The distinction matters because autonomy costs something. An agent trades latency and money for flexibility, and because it makes many decisions in sequence, small errors compound. A model that is right 95% of the time per step is not right 95% of the time over twenty steps. If your task has a known shape, a workflow is cheaper, faster, easier to test and easier to explain to an auditor.

So the first engineering decision is not "which agent framework", it is "does this problem actually need the model to choose its own path?"

How it works

At its core an agent is a while loop around a model call. You send the conversation plus a list of tool definitions. The model either answers in plain text (done) or asks to call one or more tools. Your code runs those tools, appends the results to the conversation, and calls the model again.

Rendering diagram…

Three ingredients make this an agent rather than a chatbot:

  1. Tools. Functions with a name, a description and an input schema. The model never runs code itself; it emits a structured request and your application executes it. That boundary is where all of your control lives.
  2. The loop. The model sees the outcome of each action and decides the next one. This is what lets it recover from a failed search or a compiler error.
  3. Stop conditions. Without them you have an expensive infinite loop. Common ones:
    • The model returns a final answer with no tool calls (the natural end).
    • A maximum number of turns or iterations is reached.
    • A token, dollar or wall-clock budget is exhausted.
    • A tool signals a terminal state (task submitted, ticket closed).
    • A human checkpoint is needed, so the run pauses rather than ends.

The Anthropic post calls the base building block an "augmented LLM": a model with retrieval, tools and memory attached. An agent is that augmented LLM placed inside a feedback loop with the environment.

Reference architecture

In practice I draw the system like this. The loop is small; most of the engineering is in the boxes around it.

Rendering diagram…

The policy check and budgets are not optional extras. They are what make the difference between a demo and something you can leave running.

Code

Here is a complete agent loop with the Anthropic Python SDK, written by hand so you can see every moving part. It has one tool and two stop conditions: a natural finish and a turn limit.

import anthropic

client = anthropic.Anthropic()

TOOLS = [{
    "name": "get_order_status",
    "description": "Look up the shipping status of an order by its ID, for example 'A-1042'.",
    "input_schema": {
        "type": "object",
        "properties": {"order_id": {"type": "string"}},
        "required": ["order_id"],
    },
}]

def get_order_status(order_id: str) -> str:
    fake_db = {"A-1042": "shipped, arriving Thursday"}
    return fake_db.get(order_id, "not found")

def run_agent(task: str, max_turns: int = 8) -> str:
    messages = [{"role": "user", "content": task}]
    for _ in range(max_turns):
        response = client.messages.create(
            model="claude-opus-5-5",
            max_tokens=1024,
            tools=TOOLS,
            messages=messages,
        )
        messages.append({"role": "assistant", "content": response.content})

        if response.stop_reason != "tool_use":
            return "".join(b.text for b in response.content if b.type == "text")

        results = []
        for block in response.content:
            if block.type == "tool_use" and block.name == "get_order_status":
                output = get_order_status(**block.input)
                results.append({
                    "type": "tool_result",
                    "tool_use_id": block.id,
                    "content": output,
                })
        messages.append({"role": "user", "content": results})

    return "Stopped: turn limit reached before the task finished."

print(run_agent("Where is my order A-1042?"))

Every SDK now ships a helper that hides this loop (the Anthropic tool runner, the OpenAI Agents SDK Runner, LangGraph's prebuilt agents). Use them, but write the raw loop once so you know what they do for you.

Trade-offs and pitfalls

When not to build an agent. I reach for a plain model call or a fixed workflow when:

  • The steps are known in advance. If you can draw the flowchart, code the flowchart.
  • One well-crafted call with retrieval and a few examples already hits your quality bar. Anthropic's advice is to start with the simplest solution and add complexity only when it measurably helps.
  • Latency budgets are tight. Each loop iteration is a full model round trip.
  • Mistakes are expensive and hard to reverse, and you cannot put a human checkpoint in front of them.
  • You cannot evaluate it. If you have no test set, you will not know whether the agent is getting better or worse.

Pitfalls when you do build one:

  • No turn limit. Models can get stuck retrying the same failing tool. Always cap turns and spend.
  • Vague tools. The model only knows what the tool description tells it. Ambiguous names and missing examples cause most "the agent is dumb" bug reports.
  • Swallowed errors. Return tool errors to the model as results, with a clear message. It can often fix its own input.
  • Trusting tool output. Anything a tool returns (web pages, emails, file contents) can contain prompt injection. Treat it as data, and gate side-effectful tools behind policy.
  • Overusing frameworks early. Abstractions can hide the prompts and responses you need to debug. Start with direct API calls, then adopt a framework when you understand what it replaces.

Checklist

  • Can you write the steps down in advance? If yes, build a workflow, not an agent.
  • Every tool has a clear name, description, input schema and example values.
  • The loop has a turn limit, a token or cost budget, and a wall-clock timeout.
  • Tool errors are returned to the model as results, not raised and lost.
  • Side-effectful tools pass through a policy check or human approval.
  • Every run is traced: each model call, tool call, input, output and cost.
  • You have an evaluation set before you start tuning prompts.

Further reading

Why this exists README

I learn best by explaining things, so I record the explanations. Everything here is free, with no sign-up. If a lesson helps you ship something, I'd love to hear about it.