What is an agent? Loops, autonomy and workflows vs agents
The perceive–reason–act loop, and when not to build one
Everything after this lesson — tools (10.2 Tool use and function calling), planning (10.3 Reasoning and planning for agents), memory (10.4 Memory and context engineering), multi-agent systems (10.6 Multi-agent systems) — is a refinement of one loop. Understanding that loop precisely, and the difference between a workflow whose control flow you wrote and an agent whose control flow the model decides, is what separates engineers who ship reliable systems from those who ship demos. It also tells you when the right answer is "do not build an agent at all".
You'll be able to
- State the perceive–reason–act loop formally and map each component to code you will write
- Distinguish workflows from agents using Anthropic's definition and place a system on the autonomy spectrum
- Recount the 2022–2026 history of LLM agents and explain why early attempts failed and what changed
- Estimate token cost and reliability consequences of agentic designs before building them
Key ideas
- An agent = a model in a loop whose outputs (tool calls) change the environment; the harness, not the model, executes actions.
- Workflow: you wrote the control flow. Agent: the model decides its own steps and when to stop. Start with the simplest level of autonomy that works.
- Environment feedback (tests, search results, API responses) is what makes agents reliable; tasks with cheap, trustworthy feedback were automated first.
Show 3 more key ideas
- The 2023 AutoGPT wave failed on plumbing (no structured tool calls, small contexts, no verification); function calling, MCP and reasoning models fixed the plumbing by 2025.
- Agents cost roughly 4× (single) to 15× (multi-agent) the tokens of a chat turn, and reliability decays like pⁿ with the number of steps.
- Do not build an agent for fixed sequences, unverifiable high-stakes actions, tight latency budgets, or anything you cannot evaluate.
Suggested path through this lesson
The loop
A language model by itself is a function from text to text. An agent is what you get when you put that function inside a loop and let its outputs change the world:
state = initial task + environment
repeat:
observation = render(state) # what the model sees (its context)
action = model(observation) # text, or a structured tool call
if action is a final answer: stop
state = environment.step(action) # run the tool, update the world
Three things hide in those five lines. The observation is the model's entire world at that step: system prompt, tool definitions, history, retrieved documents — this is the context window, and curating it is the subject of 10.4 Memory and context engineering. The action is either plain text or a tool call, a structured request that your code executes (10.2 Tool use and function calling). The environment is whatever the tools touch: files, a browser, a database, an API, another agent. The crucial asymmetry: the model proposes, the harness disposes. The model never runs anything; the code around it does. That code — the loop, the tools, the budgets, the permission checks — is the harness, and most of agent engineering is harness engineering (10.11 Building production agents).
Intuition. In reinforcement-learning language (4.11 Reinforcement learning essentials) an agent is a policy that picks an action given the history . For an LLM agent the policy is a frozen (or lightly RL-tuned, 8.3 Alignment: RLHF, PPO, DPO, GRPO and Constitutional AI) model, and all "learning" during a task happens in the history, i.e. in context. That is why context quality dominates behavior: you cannot change the weights at run time, only what the policy conditions on.
Workflows versus agents
Anthropic's Building effective agents (December 2024) drew the distinction most teams now use:
- Workflows are systems where LLMs and tools are orchestrated through predefined code paths. You wrote the control flow; the model fills in steps. A chain "summarize → classify → draft" is a workflow even if every step is an LLM call.
- Agents are systems where the LLM dynamically directs its own process and tool usage, deciding how to accomplish the task and when it is done.
Both are "agentic systems", and the practical advice is to start with the simplest thing that works. A useful way to see the space is as an autonomy spectrum:
| level | who decides the control flow | typical example | typical failure |
|---|---|---|---|
| fixed pipeline | your code, entirely | translate a document in 3 steps | brittle to inputs it was not written for |
| router / classifier | model picks among paths you wrote | support triage to specialist prompts | misrouting; no path for novel requests |
| bounded agent | model, within a step/tool/time budget | "fix this failing test", "answer with these 4 tools" | burns budget wandering; needs verification |
| long-running agent | model across sessions, with checkpoints | implement a feature over hours | context loss, drift, compounding errors |
| autonomous system | model + sub-agents + memory, minimal oversight | research assistant that plans, searches, writes | cost blow-ups; unsafe actions; untraceable mistakes |
Moving right buys flexibility and pays with latency, tokens and variance. The right level is the leftmost one that solves the problem.
Anatomy of an agent
- Model. The reasoning engine; today usually a frontier model with native tool use and, often, a reasoning mode (8.6 Reasoning models and test-time compute).
- Tools. Functions with schemas the model can call: search, code execution, file edits, browsers, other agents (10.2 Tool use and function calling).
- Memory / context. Working memory is the context window; long-term memory is whatever you store outside it and retrieve later (10.4 Memory and context engineering).
- Planning. Explicit or implicit decomposition of the task (10.3 Reasoning and planning for agents).
- Environment feedback. The thing that makes agents work at all: test results, compiler errors, search hits, API responses give the model ground truth it cannot hallucinate away. Tasks with cheap, trustworthy feedback (code) are where agents succeeded first (10.8 Coding agents and computer use).
- Harness and controls. Budgets, permission checks, human approvals, logging, retries (10.10 Agent safety and security, 10.11 Building production agents).
A short history
2022–2023: the ideas. ReAct (October 2022) showed that interleaving reasoning traces with actions beat either alone. Toolformer taught a model to call APIs by self-supervision. Spring 2023 brought the AutoGPT/BabyAGI wave: GPT-4 in a loop with a to-do list and web access. They were thrilling and mostly useless: no reliable structured tool calling (actions were parsed from free text), tiny context windows, no verification, and costs that spiraled as the loop wandered. The same year Generative Agents simulated a village of 25 characters with memory and reflection, Voyager learned Minecraft skills as a growing library of code, and HuggingGPT used an LLM to orchestrate other models.
Mid-2023–2024: the plumbing. Function-calling APIs made tool use structured and reliable. SWE-bench (October 2023) gave the field a hard, verifiable target; a year later agents were solving a large fraction of it. Computer use arrived as a public beta (Anthropic, October 2024). τ-bench showed how unreliable agents were across repeated trials. Building effective agents (December 2024) codified patterns and the "start simple" discipline.
2025: agents in production. The Model Context Protocol (announced November 2024) became the standard way to plug tools into models and was adopted across the industry during 2025 (10.7 MCP and interoperability (plus Agent Skills and A2A)). Coding agents (Claude Code, Codex-style tools, agentic IDEs) moved from autocomplete to multi-step work (10.8 Coding agents and computer use). OpenAI's Agents SDK, Google's ADK and the A2A protocol appeared. Reasoning models became the default planners. Security researchers named the "lethal trifecta" (10.10 Agent safety and security).
2025–2026: long-running and managed agents. The frontier moved to agents that work for hours or days: harness design with progress files and clean-context sessions, agent memory as a first-class component, sandboxed execution separated from the model's reasoning loop, and serious agent evaluation. Each is a lesson in this phase.
When you should not build an agent
- The task has a known, fixed sequence of steps → write a workflow; it is cheaper, faster and testable.
- Errors are costly and hard to verify (money moves, data is deleted, messages go out) and you cannot insert a human check → do not automate the decision, automate the preparation.
- Latency or budget is tight: a single chat turn costs one model call; an agent may cost dozens.
- You have no evaluation set. An agent you cannot measure will regress silently (10.9 Evaluating agents).
Cost and reliability, up front
Anthropic's multi-agent research write-up reported that in their systems a single-agent interaction used roughly 4× the tokens of a chat turn and multi-agent systems roughly 15×. Reliability compounds the other way: if each of steps succeeds with probability , the task succeeds with probability about — at and that is (10.9 Evaluating agents). Every design decision in this phase is, at bottom, an attempt to raise (better tools, context, verification) or reduce (better decomposition, more capable steps) while keeping the token bill and the blast radius bounded.
Where this shows up later
- The loop becomes real code with tool schemas in 10.2 Tool use and function calling; the "reason" step is expanded in 10.3 Reasoning and planning for agents; the observation is engineered in 10.4 Memory and context engineering.
- The autonomy spectrum becomes concrete patterns in 10.5 Agentic workflow patterns and multi-agent topologies in 10.6 Multi-agent systems.
- The reliability math returns with benchmarks in 10.9 Evaluating agents; the "costly, irreversible actions" caveat becomes the security model of 10.10 Agent safety and security.
Common pitfalls (4)
- Calling a prompt chain an 'agent': if your code decides every step, you have a workflow — which is often the better design.
- Believing the model 'does' things: it only emits text/tool calls; every side effect is your code's responsibility and your security surface.
- Adding autonomy before adding evaluation; without a task set you cannot tell whether the agent or your prompt tweak made things better.
- Judging an agent by one impressive demo run; variance across runs is the real metric (pass^k, 10.9).
Recap: all 6 key points
- An agent = a model in a loop whose outputs (tool calls) change the environment; the harness, not the model, executes actions.
- Workflow: you wrote the control flow. Agent: the model decides its own steps and when to stop. Start with the simplest level of autonomy that works.
- Environment feedback (tests, search results, API responses) is what makes agents reliable; tasks with cheap, trustworthy feedback were automated first.
- The 2023 AutoGPT wave failed on plumbing (no structured tool calls, small contexts, no verification); function calling, MCP and reasoning models fixed the plumbing by 2025.
- Agents cost roughly 4× (single) to 15× (multi-agent) the tokens of a chat turn, and reliability decays like pⁿ with the number of steps.
- Do not build an agent for fixed sequences, unverifiable high-stakes actions, tight latency budgets, or anything you cannot evaluate.
Watch
Barry Zhang and Erik Schluntz on workflows vs agents, keeping it simple, and what agents are good for.
Read
Exercises
- Classify ten systems on the autonomy spectrum
Take ten AI products or scripts you know (an email summarizer, a coding assistant, a support bot, a deep-research tool, a cron job that calls an LLM…). For each, write who decides the control flow, what environment feedback exists, and which level of the table it sits at. Expected: at least half of them are workflows, not agents.
- Write the loop in pseudo-code for one real task
Pick a task you want automated (e.g. "find the three most-cited papers on X and summarize them"). Write the loop with concrete observations, actions and stopping conditions, then list every point where a wrong action is irreversible. Expected: a list of 2–5 irreversible points — these become your approval gates in 10.10 Agent safety and security.
- Estimate the bill
Assume a 2,000-token system prompt and tool list, 500 tokens per model output, and tool results of 1,500 tokens. Compute total tokens for a 1-step chat, a 12-step single agent (remember the history is re-sent each step), and an orchestrator with 4 sub-agents of 8 steps each. Expected: the ratios roughly match the 1× / 4× / 15× pattern reported by Anthropic.
Quiz
Flashcards
These cards are now in your spaced-repetition queue. Review all due cards →