Sub topic 3
Workflows, Agents, and Production Trade-offs
Assume you can write Python, call web APIs, handle JSON, and use basic LLM prompts. This chapter focuses on choosing an architecture and making it safe to operate.
Workflows versus autonomous agents
A workflow has a fixed sequence of steps. For example, it can extract an invoice, validate its fields, and save the result. Each transition is known before execution.
An autonomous agent chooses its next action from the current goal and observations. It may call a search tool, inspect the result, and then decide whether another call is needed.
| Use a workflow when | Use an agent when |
|---|---|
| Steps and decisions are predictable | The path depends on changing observations |
| Consistency and auditability matter most | The task needs flexible tool selection |
| You need easy testing | You can tolerate bounded uncertainty |
Guardrails and approval
Guardrails limit what an agent can do. Validate tool arguments, check permissions for every sensitive operation, and restrict tools to the minimum required scope. Use a human approval step before irreversible actions such as sending money, deleting data, or publishing content.
Return tool failures as structured results. The agent can then recover or stop instead of treating an exception as a successful observation.
Evaluation and tracing
Evaluate an agent with representative test tasks, not only final-answer examples. Record whether it selected the right tool, used valid arguments, stopped within the limit, and respected approval requirements.
Tracing records each model request, tool call, result, latency, token usage, and termination reason. A trace helps distinguish a bad prompt from a failing API or an excessive retry loop.
Standards, frameworks, and multi-agent designs
Use the provider's function-calling format or a shared protocol such as MCP when tools must be reusable across clients. Frameworks can provide state handling and tracing, but add dependencies and abstraction. Keep the underlying tool contracts understandable.
Multiple agents can divide work into specialist roles, such as researcher and verifier. This can improve separation of concerns, but increases coordination traffic, latency, cost, and failure modes. Start with one agent unless specialization provides a measurable benefit.
Production decisions
Set maximum steps, timeouts, retry limits, token budgets, and concurrency limits. Cache safe results and choose smaller models for routine steps. Monitor cost, latency, tool errors, approval rates, and task success. Use a workflow for stable sections and an agent only where flexibility earns its cost.
Exercise
A report generator has five fixed validation steps and must never publish without approval. Should it be an autonomous agent?
Show answer
Use a workflow with explicit validation and human approval. Add an agent only for a bounded subtask whose path is genuinely variable.