Skip to content

1. What an agent is

Intermediate · 10 min read

"Agent" is one of the most overused words in GenAI. A useful definition: an agent is an LLM that decides its own next step in a loop. It chooses which tool to call, reads the result, and decides again, until it judges that the goal is met. If your code decides every step and the LLM only fills in text, you have a workflow, which is often the better choice.

1.1 Workflows vs agents

Workflow Agent
Who decides the next step Your code The LLM
Number of steps Fixed, known in advance Varies per task
Predictability, testing High Lower: the same input can take different paths
Cost and latency Bounded Varies; can run away without limits
Good for Known processes: extract → validate → store, RAG, routing Open-ended tasks: research, debugging, multi-system support

Most production "AI agents" are workflows with one or two agentic steps. That's a strength, not a compromise.

1.2 The agent loop

flowchart LR
    G[Goal + context] --> D{LLM: what next?}
    D -->|tool call| T[Run tool] --> O[Observation added to context] --> D
    D -->|final answer| F[Done]
    D -.->|step limit hit| S[Stop safely]

Every agent, from a 40-line script to a multi-agent system, is a version of this loop:

  1. Send the goal, the conversation so far and the available tools to the model.
  2. The model replies with either a tool call or a final answer.
  3. For a tool call, your code runs the tool and adds the result (the observation) to the context.
  4. Repeat, until a final answer or a limit (steps, time, cost).

The model never runs anything itself. It only asks; your code acts. That's where every safety control lives.

1.3 The components

Component What it does Page
Model Reasons and chooses the next action Choosing a model
Tools Act on the world: search, APIs, code, databases Tools and MCP
Loop / orchestration Runs steps, enforces limits, handles errors ReAct from scratch, LangGraph agents
Planning Breaks a goal into steps, re-plans on failure Planning
Memory Short-term context, long-term facts, past episodes Memory
Guardrails Limits, approvals, permissions, validation Safety and human approval
Evaluation Measures success, path quality and cost Evaluating agents

1.4 Levels of autonomy

Level Example Who decides
0 · Single call Summarise this email Code decides everything
1 · Chain / workflow Classify → retrieve → answer Code decides the steps
2 · Router Pick which of 4 pipelines handles this request LLM picks one branch
3 · Tool-using agent Answer a support question, calling order and refund tools as needed LLM picks tools in a loop
4 · Planning agent Research a topic: plan, search, read, write a report LLM plans and re-plans
5 · Multi-agent / autonomous Several agents coordinate; few human checkpoints LLMs delegate to LLMs

Move up a level only when the task needs it. Each level adds flexibility, and failure modes.

1.5 Why reliability compounds

An agent's success depends on every step going right. Even a good per-step success rate falls off quickly over long tasks:

for per_step in (0.99, 0.95, 0.90):
    row = [f"{per_step ** steps:5.0%}" for steps in (1, 5, 10, 20)]
    print(f"per-step {per_step:.0%}:  " + "   ".join(f"{n:>2} steps {r}" for n, r in zip((1, 5, 10, 20), row)))
Output
per-step 99%:   1 steps   99%    5 steps   95%   10 steps   90%   20 steps   82%
per-step 95%:   1 steps   95%    5 steps   77%   10 steps   60%   20 steps   36%
per-step 90%:   1 steps   90%    5 steps   59%   10 steps   35%   20 steps   12%

This is the main reason to keep agent tasks short, give agents good tools (fewer steps, fewer chances to fail), check intermediate results, and add human approval at the risky points.

1.6 When not to build an agent

  • The steps are known: build a workflow, which is cheaper, faster and testable.
  • One retrieval and one answer solve it: that's RAG.
  • It needs exact, deterministic results (maths, totals, compliance rules): use code or SQL, with the LLM for language only.
  • Latency must be under a second or two: agent loops make several model calls.
  • Mistakes are costly and can't be reviewed: keep a human in the loop, or don't automate the decision.

Interview questions

What is the difference between an agent and a workflow?

In a workflow, code defines the sequence of steps and the LLM performs some of them. In an agent, the LLM decides the next step at run time in a loop (which tool to call, whether to continue) based on observations. Workflows are predictable and cheaper; agents handle open-ended tasks. Many production systems are workflows with a few agentic steps.

What are the core components of an agent?

A model that reasons, tools that act, an orchestration loop with limits, and often planning, memory, guardrails and evaluation. The model only requests actions; the orchestrator executes them, which is where permissions, validation and approvals are enforced.

Why are long-running agents unreliable, and what do you do about it?

Errors compound: at 95% per-step success, a 20-step task succeeds about 36% of the time. Keep tasks short, use fewer but more capable tools, validate intermediate results, allow re-planning, cap steps and cost, add human checkpoints for risky actions, and evaluate trajectories, not just final answers.

Practice

  • Change the code in 1.5 to find how many steps a 95%-per-step agent can take while staying above 80% success.
  • Take a task from your job and place it on the autonomy levels in 1.4. What's the lowest level that works?

Next: 2. ReAct from scratch Back to: AI Agents overview · Notes overview