What Is an Agent?
What you’ll learn. A working definition of “agent” you can defend in a design review; the four ingredients (model, tools, memory, loop); the difference between a workflow and an agent; the formal view of an agent as a policy acting in a partially observable environment; and a decision rule for when an agent is the wrong tool.
Why a definition matters
Section titled “Why a definition matters”“Agent” is one of the most overloaded words in the field. Marketing uses it for anything with a chat box. Reinforcement-learning textbooks use it for any decision-making entity. For engineering purposes we need something sharper, because the choice between “a prompt”, “a pipeline” and “an agent” determines cost, latency, testability and failure modes.
A useful working definition:
An LLM agent is a system in which a language model repeatedly decides what to do next, acts on an external environment through tools, observes the result, and continues until it judges the task complete (or a budget is exhausted).
The key phrase is decides what to do next. If a human-written program fixes the sequence of steps, the LLM is a component in a workflow. If the model chooses the sequence at runtime, it is an agent.
The four ingredients
Section titled “The four ingredients” +-------------------------------+ | LOOP | | (stop conditions, budgets) | | | task ----> | +-------+ action +----+ | | | MODEL | ---------> | TOOLS | --> environment | +-------+ <--------- +----+ | (files, web, APIs, shell) | ^ observation | | | | | +--------+ | | | MEMORY | | | +--------+ | +-------------------------------+- Model. The policy. An LLM that maps a context (instructions, history, observations) to the next action. Its quality bounds everything else, but its reliability over many steps matters more than single-turn benchmark scores.
- Tools. Typed interfaces to the world: search, code execution, file edits, database queries, browsers, other agents. Without tools, the model can only emit text. See Tool use and MCP.
- Memory. Everything the model can condition on at step : the system prompt, the transcript so far (short-term, in-context), and anything retrieved from external stores (long-term). See Memory and context engineering.
- Loop. The control structure that feeds observations back and decides when to stop. It is usually a dozen lines of ordinary code, and it is where budgets, timeouts and safety checks live.
Planning, reflection and other “capabilities” are not extra ingredients; they are patterns for how the model uses these four. See Agent design patterns.
The formal view
Section titled “The formal view”Cast the agent as acting in a partially observable Markov decision process (POMDP). At step the agent sees observation , keeps history , and samples an action from its policy:
The environment returns . An episode ends when the agent emits a finish action or a budget runs out, and an outcome function (tests pass, user is satisfied) gives a reward . This framing earns its keep in three places:
- Evaluation: success is a property of the trajectory, not a single output. See Evaluation and benchmarks.
- Compounding errors: if each step is correct with probability and steps are roughly independent, a 20-step task succeeds with probability about . At that is about 36%; at about 82%. Long-horizon reliability is exponentially sensitive to per-step accuracy.
- Training: the same formalism underlies reinforcement learning for agents.
Note that the action space here is text: a tool call is a structured string the harness parses and executes. The “environment” includes the tool implementations, which is why tool design is half the engineering.
Workflows versus agents
Section titled “Workflows versus agents”A widely used distinction (popularized by Anthropic’s “Building effective agents” essay) separates:
- Workflows: LLMs and tools orchestrated through predefined code paths. Prompt chaining, routing, parallelization are all workflows.
- Agents: LLMs dynamically direct their own process and tool usage, deciding how to accomplish the task.
| Property | Workflow | Agent |
|---|---|---|
| Control flow | Written by developer | Chosen by model at runtime |
| Predictability | High | Lower |
| Cost / latency | Bounded, known | Variable, long tail |
| Debuggability | Step-level, deterministic skeleton | Needs trajectory inspection |
| Handles novel tasks | Poorly | Well |
| Typical use | Extraction, classification, report generation | Coding, research, open-ended support |
These are ends of a spectrum. Many production systems are a workflow whose individual nodes are small agents, or an agent whose tools are themselves workflows.
A concrete example
Section titled “A concrete example”Task: “Summarize each customer support ticket and tag it with a category.”
- Workflow: for each ticket, one LLM call with a fixed prompt and a JSON schema. Cost is predictable, accuracy is measurable per ticket. No agent needed.
- Agent: “Investigate why checkout failures spiked yesterday.” The steps are unknown ahead of time: query logs, read a deploy diff, check a status page, form and test hypotheses. A fixed pipeline cannot be written in advance.
The minimal agent loop
Section titled “The minimal agent loop”The whole concept fits in a screen of Python. This sketch uses a generic llm callable that returns either text or a tool call; Build an agent from scratch develops a complete version.
def run_agent(llm, tools, task, max_steps=15): messages = [{"role": "user", "content": task}] for step in range(max_steps): reply = llm(messages, tools=list(tools.values())) messages.append(reply) if not reply.get("tool_calls"): # model chose to stop return reply["content"] for call in reply["tool_calls"]: try: result = tools[call["name"]]["fn"](**call["arguments"]) except Exception as e: # errors are observations too result = f"ERROR: {e}" messages.append({"role": "tool", "id": call["id"], "content": str(result)}) return "Stopped: step budget exhausted."Notice what is not here: no planner module, no graph, no framework. Most of the rest of this course is about making that loop reliable, cheap, safe and good.
Degrees of autonomy
Section titled “Degrees of autonomy”It helps to think in levels rather than a binary:
- Single call. Prompt in, answer out.
- Augmented call. Retrieval or one tool call, then answer (RAG).
- Fixed workflow. Several calls in a developer-defined order.
- Router/branching. The model picks a branch among developer-defined paths.
- Tool-loop agent. The model chooses tools and number of steps.
- Multi-agent / long-running. Agents spawn or coordinate other agents, run for hours, persist state across sessions.
Each level up buys flexibility and costs predictability. A good rule: use the lowest level that solves the problem, and move up only when you can show with an evaluation that the lower level fails.
When not to build an agent
Section titled “When not to build an agent”- The task has a known, stable procedure. Write the procedure.
- Errors are expensive and irreversible (payments, deletions) and you cannot add verification or human approval.
- Latency budget is tight (interactive autocomplete). A multi-step loop may take tens of seconds.
- You have no way to measure success. An agent you cannot evaluate is a liability.
- A single well-prompted call with retrieval already hits your quality bar.
What changed between 2023 and 2026
Section titled “What changed between 2023 and 2026”Early agent systems (AutoGPT-style, 2023) mostly failed because models were poor at long-horizon tool use and recovering from errors. Three shifts changed this:
- Native tool-calling and structured outputs trained into models, replacing brittle text parsing.
- Reasoning models trained with reinforcement learning on verifiable tasks, which plan and self-correct inside a step (Test-time compute).
- Longer, cheaper contexts and better harnesses (coding agents with file editing, shell, and context management).
The consequence is that agentic coding and research are now genuinely useful, while many other domains remain unreliable. This is fast-moving; treat specific capability claims as perishable.
Key takeaways
Section titled “Key takeaways”- An agent is an LLM in a loop that chooses its own next action, acts through tools, and observes results.
- The four ingredients are model, tools, memory and loop; everything else is a pattern on top.
- Workflows fix the control flow in code; agents let the model decide it. Prefer the least autonomous design that works.
- Multi-step success decays roughly as , so per-step reliability and error recovery dominate.
- If you cannot measure success or bound cost and risk, do not build an agent yet.
Exercises
Section titled “Exercises”- Conceptual. Classify each as workflow or agent: (a) a pipeline that OCRs an invoice, extracts fields with an LLM, validates them; (b) a bot that, given a bug report, searches a repo, edits files and runs tests until green; (c) an LLM that picks one of three canned responses.
- Compute. A 12-step agent has 97% per-step success (independent). What is the end-to-end success rate? What per-step rate is needed for 90%?
- Design. Pick a task from your job. Place it on the autonomy levels above and justify why a lower level would or would not suffice.
- Hands-on. Implement
run_agentabove with a fakellmthat returns scripted tool calls, and add amax_stepsguard test and a test that tool exceptions are fed back instead of crashing.
Solutions (2)
. For 90%: , so about 99.1% per step.
Further reading
Section titled “Further reading”- Anthropic, “Building effective agents” (2024), the workflows-vs-agents distinction.
- Yao et al., “ReAct: Synergizing Reasoning and Acting in Language Models” (2023).
- Russell and Norvig, Artificial Intelligence: A Modern Approach, chapters on agents and environments.
- Weng, “LLM Powered Autonomous Agents” (Lil’Log, 2023).
- See also Agents and tool use in the NLP/LLM section.