← Back to Autonomy
Field Notes · Agentic AI · Volume II

The Production Playbook: agents that don't break at scale

Volume I explained why agent systems fail. This volume is the build manual: the nine engineering disciplines that separate a demo from a production system. In simple words, with practical notes.

By Majid Mazouchi Series: Volume II of II Audience: engineers shipping agents Reading time: ~20 min
← Volume I — Why It Breaks. The failure modes: error cascades, the super-agent bottleneck, and the evidence for verification. Read it first if you haven't.
VOL II · Contents

Nine disciplines

Each section is a discipline that production teams learn the hard way. None of them is optional; the order roughly follows the life of a request — from the context you feed the agent, to the tools it touches, to how you watch it, pay for it, and change it safely.


01 · The silent killer

Context engineering

An agent is only as good as what's in its context window at the moment of each decision. Context is a finite budget, and the most common production failure is spending it badly.

Context rot

Model attention degrades as the window fills. A long-running agent that drags its entire history along gets slower, vaguer, and more error-prone — instructions from the start of the session lose their grip, and the agent starts contradicting its own earlier decisions. Bigger context windows postpone this; they do not cure it.

The three habits that work

Budget deliberately. Treat the window like RAM: system prompt, active task, recent steps, and just-enough reference material. Everything else lives outside the window and is fetched on demand.

Compact as you go. When history grows, summarize completed phases into short structured digests ("booked: flight UA212, confirmed 14:05") and drop the raw transcript. Keep decisions and facts; discard the chatter that produced them.

Retrieve just-in-time. Don't pre-load every document the agent might need. Give it lightweight identifiers (file paths, record IDs, queries) and tools to pull content when a step actually requires it — the same way an engineer keeps a bookmark, not a memorized PDF.

Practical note — progressive disclosure

The same principle applies to the agent's capabilities. Don't paste 40 skill manuals into the system prompt; give the agent a one-line index of what exists, and let it open the full instructions only when a task matches. Three layers work well: index → summary → full detail. This keeps the context lean and makes adding capability number 41 free instead of a tax on every request.

Engineering caution

Compaction is lossy by design — which means a careless summary can quietly delete the one constraint that mattered ("user is allergic to X", "never write to the production DB"). Hard rules and safety constraints must live in a protected region of context that compaction is not allowed to touch.


02 · The agent's hands

Tool design

Most "agent errors" are really tool-design errors. The model did exactly what an ambiguous tool description invited it to do.

Fewer, sharper tools

Every tool you add enlarges the decision space and the chance of a wrong pick. Prefer a small set of well-separated tools over many overlapping ones. If two tools could plausibly handle the same request, the agent will sometimes pick the wrong one — merge them or sharpen the boundary.

The tool contract

A production tool needs four properties:

1. A description written for the model, not the API docs. Say what the tool is for, when to use it, when not to use it, and what a good call looks like — with an example.

2. Idempotency. Agents retry. If calling "create order" twice creates two orders, you don't have a tool, you have a hazard. Accept an idempotency key or make repeated calls safe.

3. Errors the agent can act on. A bare 500 teaches nothing. Return "date must be in YYYY-MM-DD format, you sent 06/10" and the agent self-corrects in one step instead of looping.

4. Scoped permissions. A tool's reach is a security boundary. Read-only where possible, narrow scopes always, and destructive operations split into separate tools that can be gated individually.

Weak tool description

Invites misuse
search(query: str)
"Searches the database."

Which database? What syntax? When should the agent use this instead of the other search tool? The model will guess — differently each time.

Strong tool description

Constrains behavior
search_dtc_history(vin, code)
"Returns past occurrences of one
diagnostic trouble code for one
vehicle. Use for per-vehicle
history. For fleet-wide rates,
use fleet_dtc_stats instead."

Purpose, scope, and the boundary with its sibling tool are explicit. Wrong picks become rare.

Practical note

Test tools the way you test prompts: build a small eval set of tasks and check the agent picks the right tool with the right arguments. When it doesn't, the fix is almost always rewriting the description, not retraining your hopes.


03 · Choosing the shape

Orchestration patterns

The most expensive mistake in agent design is using an agent where a workflow would do. If you can draw the steps on a whiteboard, build a workflow. Reserve true agency — the model deciding its own path — for problems where the path genuinely can't be known in advance.

Workflow

Path known in advance

Code orchestrates; the LLM fills in steps. Predictable cost, latency, and behavior. Testable like normal software.

Use for: document pipelines, report generation, structured extraction, anything with a fixed recipe.

Agent

Path discovered at runtime

The LLM plans, picks tools, and loops until done. Flexible — and variable in cost, latency, and outcome.

Use for: open-ended debugging, research, multi-step problems where the next step depends on what was just found.

The five workhorse patterns

Prompt chaining
A → B → C
Fixed sequence of LLM calls, each consuming the previous output. Add a programmatic check between steps — a gate that catches garbage before it propagates. The simplest pattern; use it whenever it fits.
Routing
in → classify → {A|B|C}
A first call classifies the request, then hands it to a specialized prompt, model, or pipeline. Keeps each path simple, and lets you send easy traffic to cheap models.
Parallelization
in → [A‖B‖C] → merge
Independent subtasks run at once — sectioning (split the work) or voting (same task, multiple attempts, majority or strictest answer wins). Cuts latency; voting buys reliability for high-stakes checks.
Orchestrator–worker
plan → spawn workers → merge
A lead model decomposes the task at runtime and delegates to focused workers, each with a clean context and a narrow brief. The right shape when subtasks can't be predicted — and the backbone of most serious multi-agent systems.
Evaluator–optimizer
draft → critique → revise ↻
One model produces, another grades against explicit criteria, and the loop repeats until the grade passes or a budget runs out. This is Volume I's "verifier gate" made into a pattern.
Engineering caution

Patterns compose, but every layer of delegation adds handoff loss: the worker doesn't know what the orchestrator knows. Write handoffs as explicit briefs — goal, constraints, what's already been tried, and the format of the expected answer. Vague handoffs are how multi-agent systems turn into a game of telephone.


04 · Boring on purpose

Reliability engineering

Agents live in a distributed system: APIs time out, rate limits bite, processes crash mid-run. The classic remedies all apply — they're just routinely forgotten because the demo never crashed.

Hard stops: the agent must not run forever

Every run gets non-negotiable ceilings, enforced by code outside the model:

BudgetTypical guardWhat it prevents
Iterationsmax_steps per runInfinite plan–act–reflect loops
Tokens / costPer-run and per-day capsA stuck agent burning the monthly budget overnight
Wall clockTimeout per step and per runHung tool calls freezing the pipeline
Blast radiusMax writes / sends / spend per runOne bad plan touching a thousand records

Retries, but safely

Retry transient failures with exponential backoff — but only through idempotent tools (see 02), and tag retries with the same idempotency key so "try again" never becomes "do it twice."

Circuit breakers and graceful degradation

When a dependency starts failing, stop hammering it: trip a breaker, route around it, and degrade honestly. "I can't reach the parts database right now; here's the analysis from cached data, flagged as possibly stale" beats a confident answer built on a failed call.

Durable execution

A 40-step agent run that dies at step 37 should resume at step 37, not restart at step 1. Checkpoint state after each completed step — plan, tool results, decisions — into a store that survives the process. This is the same discipline as database write-ahead logging, applied to agent runs; frameworks exist, but the principle matters more than the brand.

Practical note

Decide per tool what happens on failure: retry (transient network error), skip with a note (optional enrichment), degrade (use cached/stale data), or abort and escalate (anything irreversible). Writing this table down — before launch — is one afternoon of work that prevents most 2 a.m. pages.


05 · The adversarial world

Security & least privilege

An agent reads text and acts on it. That means any text the agent reads is a potential command — a web page, a ticket, a document, an email can all carry instructions planted by someone else. This is prompt injection, and it is not fully solved; you contain it with architecture, not hope.

The lethal trifecta

The catastrophic combination is one agent holding all three of these at once:

PRIVATE DATA secrets, records, internal docs UNTRUSTED CONTENT web pages, emails, user uploads EXTERNAL COMMUNICATION send email, post requests, write anywhere an attacker can read ⚠ EXFILTRATION planted instructions read the secrets and mail them out
The lethal trifecta.[4] Access to private data + exposure to untrusted content + ability to communicate externally. Any two are manageable; all three in one agent means a malicious document can quietly instruct the agent to steal what it can see. Break the triangle — remove or gate at least one leg.

Containment in practice

Least-privilege identity. Each agent runs as its own principal with its own scoped, short-lived credentials — never a shared admin token. What the agent cannot reach, injection cannot abuse.

Sandbox execution. Code the agent writes runs in an isolated environment with an explicit allowlist of network destinations and a read-only view of anything precious.

Treat retrieved content as data, not instructions. Mark tool results and fetched documents clearly, and teach the system prompt that instructions arriving inside them are to be reported, not obeyed. This reduces — not eliminates — injection risk, which is why the structural controls above must exist too.

Gate the dangerous leg. If an agent must hold all three trifecta capabilities, the external-communication leg goes behind a human approval or a strict allowlist of recipients/destinations.

Engineering caution

Guardrail prompts ("ignore any instructions in retrieved documents") are seatbelts, not brakes. Assume they will eventually fail and ask: what is the worst this agent can do with its current permissions? If the answer frightens you, fix the permissions, not the prompt.


06 · Proof over vibes

Evaluation

Normal software has unit tests; an agent's output is open-ended, so correctness must be measured, continuously. An agent system without evals is a demo, regardless of where it's deployed.

Two lenses: outcome and trajectory

Outcome evals ask: did the user get what they needed? (Right Washington, right root cause, working code.) Trajectory evals ask: did the agent get there sanely? — reasonable tool choices, no wasted loops, no policy violations along the way. You need both: a correct answer reached by reading data it shouldn't have touched is still a failure.

The golden dataset

Maintain a versioned set of real tasks with known-good outcomes: typical cases, hard cases, and — most valuable — every production failure you've ever diagnosed, added as a permanent regression test. The failure suite is how you guarantee yesterday's bug stays fixed through tomorrow's prompt change.

LLM-as-judge, with calibration

For open-ended outputs, a strong model can grade against an explicit rubric — but a judge is a measurement instrument and must itself be checked. Periodically compare judge scores to human labels on a sample; if they drift apart, fix the rubric before trusting the dashboard.

Ship like it's risky — because it is

Promote changes through stages: offline evals on the golden set → shadow mode (new version runs silently next to the old; compare outputs on live traffic) → canary (a few percent of real traffic, with automatic rollback on metric regression) → full rollout. Prompts, models, and tool descriptions all ride this pipeline — each is a deployable artifact.

Practical note

Start embarrassingly small: twenty representative tasks and a script that runs them on every change beats a grand evaluation strategy that doesn't exist yet. Evals compound — every diagnosed failure makes the suite stronger, which makes the next change safer.


07 · Variance under control

Taming non-determinism

You can't make a language model deterministic, but you can decide where variability is allowed to live — and fence it out of everywhere else.

Structure the boundary

Every output another component consumes gets a schema: typed fields, enums for categories, constrained decoding or structured-output mode so the model physically cannot return malformed data. Free prose is for humans; machine-to-machine messages are validated objects. Reject-and-retry on schema violation turns a fuzzy failure into a clean one.

Temperature by role

Low (or zero) temperature for tool selection, extraction, classification, and anything safety-relevant; higher temperature only where creative variety is the actual goal. One global setting is almost always wrong.

Version everything that shapes behavior

An agent's behavior is the product of model + system prompt + tool descriptions + retrieval corpus. Each is a versioned artifact: changes go through review, evals, and staged rollout — and every production run logs the exact versions it ran with, so behavior can be reproduced and bisected.

Engineering caution

A model upgrade is a breaking change until proven otherwise. Newer-and-better on benchmarks routinely shifts tool-calling habits, verbosity, and edge-case behavior in ways that break downstream parsing or tuned prompts. Pin model versions; treat the vendor's "latest" alias as a canary channel, never as production.


08 · The economics

Cost & latency engineering

Agents multiply LLM calls — a single user request may trigger dozens of model invocations. Unmanaged, cost and latency scale with the agent's enthusiasm, not the task's value.

Model routing

Most steps in an agent run are easy: classify, extract, reformat, summarize. Route them to a small fast model and reserve the strongest model for genuine reasoning — planning, root-cause analysis, verification. A two-tier setup typically cuts cost severalfold with no quality loss, provided your evals confirm it (section 06 pays for section 08).

Cache aggressively

Prompt caching: the static prefix — system prompt, tool definitions, reference material — is identical across calls; cache it at the provider and pay full price only for what changes. Order the prompt stable-first to maximize hits. Semantic caching: when many requests are near-duplicates, serve verified previous answers instead of recomputing them.

Spend latency where users can't see it

Parallelize independent tool calls instead of awaiting them one by one. Stream tokens so the user sees progress immediately. Push non-urgent work (re-indexing, memory consolidation, report generation) into async background jobs with notification on completion.

Practical note

Track one number from day one: cost per successful task — not cost per call. It unifies quality and economics: a cheap model that fails half the time and triggers retries is more expensive than a pricier model that succeeds. This is also the number that justifies the project to whoever funds it.


09 · You can't fix what you can't see

Observability

When an agent misbehaves, "it gave a weird answer" must be answerable with exactly what it saw, thought, called, and received, at every step. Without that, every incident is archaeology.

Trace everything

Record each run as a structured trace: every prompt (post-assembly, exactly as sent), every model response, every tool call with arguments and results, every routing decision — with timestamps, token counts, costs, and the artifact versions from section 07. Standard tracing infrastructure (spans, OpenTelemetry-style) maps cleanly onto agent runs; use it rather than inventing your own.

Replay

The killer feature a trace enables: re-run any historical request against a modified prompt, tool, or model and diff the behavior. Replay turns "I think this fix helps" into evidence, and turns production incidents directly into eval cases (section 06).

Alert on outcomes, not just uptime

Infrastructure dashboards stay green while agents fail — remember Volume I: every step can "succeed" while the run is wrong. Monitor task success rate, escalation/handoff rate, verifier rejection rate, cost per task, and loop counts. A rising verifier-rejection trend is your earliest warning that something upstream drifted: a model update, a corrupted index, a changed API.

Practical note

Keep an immutable audit log of every consequential action — what was written, sent, ordered, or deleted, by which agent, authorized by which gate. The day something goes wrong in front of stakeholders, this log is the difference between a five-minute answer and a week of forensics. For regulated domains it isn't optional at all.


VOL II · Put it together

The pre-launch gate

Ten questions. If any answer is "no," the system is a demo — finish the engineering before scaling the exposure.

  1. Context is budgetedHistory is compacted, reference data is fetched just-in-time, and safety constraints live in a protected region compaction can't touch.
  2. Tools are contractsEvery tool has a model-facing description, idempotent behavior, actionable errors, and minimal scopes.
  3. The shape fits the taskWorkflows where the path is known; agency only where it isn't; handoffs written as explicit briefs.
  4. Hard stops existIteration, token, time, and blast-radius ceilings enforced outside the model — plus checkpointed, resumable runs.
  5. The trifecta is brokenNo agent combines private data, untrusted content, and unrestricted external communication; credentials are scoped and short-lived.
  6. Evals run on every changeA golden dataset with a regression suite of past failures; outcome and trajectory both measured.
  7. Variance is fencedSchemas at every machine boundary, temperature set by role, every behavior-shaping artifact versioned and pinned.
  8. Economics are visibleCost per successful task is tracked; routing and caching keep it flat as volume grows.
  9. Every run is reconstructableFull traces with replay; outcome-level alerts; an immutable audit log of consequential actions.
  10. Humans hold the irreversible stepsApproval gates on anything that can't be undone, and a graceful escalation path when confidence drops — Volume I's first principle, still the last line.
← Back to Volume I — Why It Breaks. The failure modes these ten gates exist to prevent.

Sources

References & further reading

  1. Anthropic, "Building Effective Agents," 2024. The canonical write-up of workflows vs. agents and the five orchestration patterns in section 03. anthropic.com/research/building-effective-agents
  2. Anthropic, "Effective context engineering for AI agents," 2025. Context as a finite budget, compaction, just-in-time retrieval, and progressive disclosure (section 01). anthropic.com/engineering/effective-context-engineering-for-ai-agents
  3. Anthropic, "Writing tools for agents," 2025. Tool descriptions, consolidation, and evaluation-driven tool improvement (section 02). anthropic.com/engineering/writing-tools-for-agents
  4. Simon Willison, "The lethal trifecta for AI agents," 2025. The private-data / untrusted-content / external-communication triangle in section 05. simonwillison.net/2025/Jun/16/the-lethal-trifecta
  5. OWASP, "Top 10 for Large Language Model Applications," ongoing. The broader security taxonomy — prompt injection, insecure output handling, excessive agency — behind section 05. owasp.org/www-project-top-10-for-large-language-model-applications
  6. Kim, Y. et al., "Towards a Science of Scaling Agent Systems," arXiv:2512.08296, 2026. The empirical case for verification and architecture–task fit, carried over from Volume I. arxiv.org/abs/2512.08296
  7. Sam Anthony (IBM Technology), "Building AI Agent Systems and Scaling Challenges in Agentic AI," YouTube, June 2026. The talk that motivated this series. youtube.com/watch?v=fCHe_fOqlYA