Generative AI & LLM Apps
Topic 8 · Building LLM apps · ⏱ about 3 h

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.

Show:
In this topic
Beginner

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).

Beginner

Common workflow patterns

PatternWhat it doesExample
Prompt chainingeach call's output feeds the next, with checks in betweenoutline → check outline → write the report
Routinga first call classifies the input and sends it to a specialised prompt or modelbilling questions to one prompt, clinical ones to a human
Parallelisationindependent calls run at the same time, then are combinedreview a contract for privacy, cost and risk separately
Orchestrator and workersone call plans subtasks; worker calls do themsplit a literature review into one search per subtopic
Evaluator and optimiserone call drafts, another critiques against criteria, repeatdraft a plain-English summary, check reading level, revise
Try it

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.

Beginner

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.
Beginner

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.
Check yourself

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"?

Go deeper

📚 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.

Ready