Agents and tools
Agents and agent architectures
Workflows vs agents, the core patterns, ReAct loops, planning and knowing when to stop.
An agent is a model-directed loop: the model chooses tools and next steps until a goal is met or a budget runs out. A workflow is a path you defined — prompt chaining, a router, a fixed graph — where the model fills in steps but does not invent the control flow.
That distinction is the most useful one in AI engineering. Most production "agents" that work well are mostly workflows with a little autonomy at the edges. Full open-ended agents shine when the path cannot be scripted: research, debugging, multi-step ops. They also burn tokens, drift from the goal and fail in ways that are hard to replay unless you design for it.
Start with the simplest thing that ships. Add autonomy only where branching cannot be enumerated. A surprising fraction of roadmap items labeled "build an agent" collapse into a router plus two chains once you write down the real user journeys. That is a win.
Concept
Chip Huyen frames agents as systems that perceive, plan and act over multiple steps with external tools. The hard parts are not the loop boilerplate. They are tool reliability, context growth and knowing when to stop.
| Workflow | Agent | |
|---|---|---|
| Control flow | Code or graph you wrote | Model chooses the next step |
| Predictability | High | Lower |
| Cost per task | Bounded and easier to forecast | Can spike 10 to 100× |
| Best for | Known stages, compliance, high volume | Open-ended goals, exploration |
| Failure mode | Brittle when a stage is wrong | Loops, tool misuse, cost blowups |
If 80% of requests follow three paths, encode those paths as a workflow and reserve an agent for the long tail.
Concepts in this section
Read them in order. Each one builds on the one before.
| Step | Concept | What it answers |
|---|---|---|
| 1 | Workflow patterns | Which fixed shapes cover most products? |
| 2 | The ReAct loop | How does an open loop choose the next tool? |
| 3 | Agent planning | Plan first, or pick the next action as you go? |
| 4 | Autonomy and stopping | How much freedom, and what makes it stop? |
A support ticket, worked out
"Where is my order?" at high volume.
Wrong first move: an open-ended agent with run_sql, web browse and email send. Cost per ticket explodes. A wrong refund is one bad trajectory away.
Better shape:
- Router classifies: tracking, cancel, billing or other.
- Tracking workflow forces
get_order, then a template answer with status and ETA. Escalate ifnot_found. - Cancel workflow runs
get_order, a policy check in code, optional human approve, thencancel_order. - Other is a small agent with help-doc search only, a 4-step cap and no write tools.
Most tickets never pay for an open loop.
Common mistakes
- Autonomy theater. The user journeys were enumerable. You built a loop anyway.
- No budgets. Step, token, dollar and wall-clock caps are part of the design.
- Debugging from the final paragraph. You need the trajectory: tools, observations, stop reason.
Key takeaways
- Prefer workflows. Add agent loops only where paths cannot be enumerated.
- Compose the five workflow patterns before you invent a framework.
- ReAct is reason → act → observe, with hard caps.
- Plan-then-execute when you need approval. Interleave when the environment is uncertain.
- Recover with structured errors and external verification. Escalate after repeated failure.
Further learning
Building effective agents (Anthropic)Discover how Anthropic approaches the development of reliable AI agents. Learn about our research on agent capabilities, safety considerations, and technical framework for building trustworthy AI.anthropic.com
ReAct: Synergizing Reasoning and Acting in Language ModelsWhile large language models (LLMs) have demonstrated impressive capabilities across tasks in language understanding and interactive decision making, their abilities for reasoning (e.g. chain-of-thought prompting) and …arXiv.org
Agents (Chip Huyen)Intelligent agents are considered by many to be the ultimate goal of AI. The classic book by Stuart Russell and Peter Norvig, Artificial Intelligence: A Modern Approach (Prentice Hall, 1995), defines the field of AI r…Chip Huyen
Start with workflow patterns.
Related
Tool use and function calling
Letting models call your code: tool schemas, the tool loop, and designing tools models use well.
Multi-agent systems
When multiple agents beat one: orchestrator-subagent designs, context isolation and the cost of coordination.
Agent infrastructure
Running agents for real: sandboxes, durable execution, state, permissions and long-running tasks.