Agents & Workflows
When an LLM should follow a fixed workflow and when it should act as an agent that plans and uses tools in a loop; common workflow patterns, memory, multi-agent systems, MCP, and keeping agents safe and affordable.
Workflows and agents
Once a model can call tools (previous topic), you can combine calls into bigger systems. A useful distinction, popularised by Anthropic's guide Building effective agents:
- A workflow follows steps your code defines: first extract, then classify, then draft a reply. Predictable, testable and cheap.
- An agent lets the model decide the steps: it works in a loop of think → call a tool → look at the result → decide what next until the task is done. Flexible, but slower, costlier and harder to predict.
Start with the simplest thing that works: a single well-written prompt, then a workflow, and an agent only when the steps genuinely cannot be known in advance (for example, fixing a bug in an unfamiliar codebase, or open-ended research).
Common workflow patterns
| Pattern | What it does | Example |
|---|---|---|
| Prompt chaining | each call's output feeds the next, with checks in between | outline → check outline → write the report |
| Routing | a first call classifies the input and sends it to a specialised prompt or model | billing questions to one prompt, clinical ones to a human |
| Parallelisation | independent calls run at the same time, then are combined | review a contract for privacy, cost and risk separately |
| Orchestrator and workers | one call plans subtasks; worker calls do them | split a literature review into one search per subtopic |
| Evaluator and optimiser | one call drafts, another critiques against criteria, repeat | draft a plain-English summary, check reading level, revise |
Watch an agent work
A research assistant agent is asked: "Which of our clinics had the most missed appointments last month, and why might that be?" Step through its loop.
Interactive: this part runs in your browser.
Memory, multi-agent systems and MCP
- Short-term memory is just the conversation and tool results in the context window. Long tasks overflow it, so agents summarise old steps or save notes to a file.
- Long-term memory stores facts between sessions (in a database or files) and retrieves them when relevant, which is RAG over the agent's own notes.
- Multi-agent systems split work between several agents with different roles or tools (a planner, researchers, a reviewer). They can help on broad tasks but multiply cost and failure points; one capable agent with good tools is often enough.
- MCP (Model Context Protocol) lets an agent use any tool published as an MCP server (files, calendars, databases, browsers) without custom code for each.
Keeping agents safe and affordable
- Least privilege: give each agent only the tools and permissions it needs (read-only where possible). OWASP calls the opposite "excessive agency".
- Humans approve risky actions: payments, sending messages, deleting or changing records.
- Budgets: cap steps, tokens, time and money per task, and stop with a clear message when a cap is hit.
- Sandboxes: run agent-written code in an isolated environment, never directly on your servers.
- Treat everything the agent reads as untrusted: a web page or email can contain instructions aimed at the agent (prompt injection).
- Log every step so you can see why it did what it did.
Quiz
1. Every support email must be classified, then answered from a template. Workflow or agent?
2. What is the core loop of an agent?
3. Which is an example of "excessive agency"?
📚 Further reading
Trusted, mostly free sources: official documentation, well-known textbooks and courses. When you want to confirm or go deeper on anything here, start with these.
- Anthropic: Building effective agents ↗ workflows vs agents and the common patterns, from real projects
- Model Context Protocol documentation ↗ the open standard for connecting tools and data to AI apps