Skip to content

Guardrails and production

Building agents · topic building-agents/production

Running an agent for real means surrounding it with controls and treating its changes like any other risky deployment. This topic covers layered defenses, gating deploys on evaluation results, rolling changes out gradually, managing cost, operating the model API itself, the security risks specific to agents, and the protocols agents use to talk to tools and to each other.

Concepts

Defense layers
No single control stops every bad outcome, so production agents stack several: policy in the system prompt, input and output filtering, permission limits on tools, human approval at irreversible steps, monitoring and alerting, and the ability to stop the agent. Each layer catches what the previous ones miss, and the design assumes the model itself will sometimes be fooled. glossary
Eval-gated deploys
Treating any change to prompt, tools, model or harness as a release that must pass the evaluation suite before it reaches users, the same way code must pass tests. The gate turns evaluation from an occasional study into a continuous control and catches the regression that a small wording change or a model update introduces. glossary
Rollout strategies
Releasing a change to a fraction of traffic first, comparing its metrics with the current version, and widening or reverting based on what is observed. Shadow runs, canaries and gradual percentages all apply to agents. Because model behavior is non-deterministic and evaluation is imperfect, gradual rollout is the check that evaluation cannot give. glossary
Cost
What an agent spends per task in tokens, tool calls and time, and how that scales with users. Agents multiply model cost by their number of turns, and a runaway loop or verbose tool can multiply it again. Track cost per run, set budgets that stop a run, cache what repeats, and route simple steps to smaller models. glossary
Provider operations
The mechanics of calling a model provider reliably. Pin an exact model ID, one that names a single fixed version, so the model changes only when you choose. Use prompt caching so the stable prefix of a system prompt and tool list is processed once and read back at a lower price on later calls. Retry retriable errors, such as rate limits and overload, with a backoff. Report terminal ones, such as an invalid request or a content refusal, to the caller. Set timeouts on every call. glossary
Agent-specific security risks
Risks that appear when a model can act: prompt injection through content the agent reads, exfiltration through tools that send data outward, over-permissioned tools that turn a wrong decision into real damage, and confused-deputy situations where the agent spends its own authority for whoever wrote the text it acts on. They are mitigated by limiting capability and reviewing actions, not by better prompts. glossary
Protocols (MCP, A2A)
Standards for how agents connect to things. The Model Context Protocol standardizes how an agent reaches tools and data through servers. Agent-to-agent protocols standardize how one agent discovers, delegates to and exchanges results with another across organizations. Shared protocols reduce integration work and also widen the attack surface, so each connection is a trust decision. glossary

Lessons

Your reference

Each lesson above adds its takeaways and its example here once you finish it. Your reference lists every lesson you have finished.

How a running agent gets attacked

Unlocks when you finish How a running agent gets attacked.

Protocols for tools and for other agents

Unlocks when you finish Protocols for tools and for other agents.

Cost, caching and pinning the model

Unlocks when you finish Cost, caching and pinning the model.

Gating a deploy on the evaluation

Unlocks when you finish Gating a deploy on the evaluation.

Guardrails in layers

Unlocks when you finish Guardrails in layers.

Sources