What is an AI agent, and how is it different from a workflow?
Learning path, stage 4 of 5: Agents, tools and MCP · question 1 of 10An AI agent is an LLM that works in a loop: it decides which tool to call, looks at the result, and repeats until the goal is met, choosing its own path. A workflow also uses LLMs and tools, but your code fixes the sequence of steps. Agents suit open-ended tasks. Workflows are more predictable, cheaper and easier to test.
The building blocks
- Model: does the reasoning and decides the next step.
- Tools: functions or APIs it can call (search, code execution, database, email).
- Memory and context: the conversation, retrieved knowledge, saved notes.
- Loop and stop conditions: done, step limit, budget, or a person stepping in.
When to build an agent
- The task is multi-step and hard to script in advance (debugging, research, coding).
- Mistakes can be caught and undone (tests, review, sandbox).
- The value is worth the extra cost and latency.
Otherwise, start with a single call or a fixed workflow. Anthropic's guidance is to use the simplest thing that works and add autonomy only when it measurably helps.
Sources
Code example
1// Workflow vs agent, side by side.2declare function llm(prompt: string): Promise<string>;34// WORKFLOW: code decides the steps5export async function summariseAndTranslate(doc: string) {6 const summary = await llm(`Summarise:\n${doc}`);7 return llm(`Translate to Spanish:\n${summary}`);8}910// AGENT: the model decides the steps (see the agent loop question for the real thing)11type Action = { tool: string; input: string } | { done: string };12declare function decide(goal: string, log: string[]): Promise<Action>;13declare function runTool(tool: string, input: string): Promise<string>;1415export async function agent(goal: string, maxSteps = 10) {16 const log: string[] = [];17 for (let i = 0; i < maxSteps; i++) {18 const action = await decide(goal, log);19 if ("done" in action) return action.done;20 log.push(`${action.tool}(${action.input}) -> ${await runTool(action.tool, action.input)}`);21 }22 throw new Error("Step limit reached");23}
To run it: follow the one-time setup guide, add npm i @anthropic-ai/sdk zod @modelcontextprotocol/sdk, save the code as a .ts file and run npx tsx file.ts. Anything marked declare is a part you supply.
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the AI Agents & LLMs set.