// Agentic Engineering — Field Notes
What It Takes to Run
Agents in Production.
The patterns and constraints I apply when designing agentic systems shared by several teams, on an open-source stack. Each one is here because something broke without it.
Principles
Autonomy has to pay for its error rate
Errors compound across steps: an agent that is right 95% of the time per step finishes a ten-step task about 60% of the time. Every autonomous step is a liability until it earns its place. The default is a deterministic workflow with LLM calls at the points of judgment; open-ended agent loops are reserved for tasks whose path cannot be known in advance.
Reliability lives in the harness
The model is a component. Typed state, bounded loops, checkpoints, validated tool calls and explicit termination are what make the system operable. Swapping the model should change quality, not behaviour.
Measure consistency, not best case
pass@k tells you an agent can succeed. pass^k, the probability it succeeds on all k attempts, tells you whether a business can depend on it. Production gates are set on the second number.
Orchestration patterns — when, and how they fail
Prompt chaining & routing
Use Fixed decomposition, classifiable inputs.
Failure mode Brittle when inputs drift outside the routes; needs a fallback route and route-level evals.
Orchestrator–workers
Use Subtasks unknown until the input is read.
Failure mode Workers duplicate effort or leave gaps unless each receives an explicit objective, output contract and boundary.
Evaluator–optimizer
Use Clear quality criteria and measurable improvement per iteration.
Failure mode Unbounded refinement loops; needs a stopping rule and an evaluator that is not the generator in disguise.
Planner–executor with replanning
Use Long tasks where steps fail or reveal new information.
Failure mode Plans that are never revised; replanning must be triggered by observed state, not by a fixed cadence.
Parallel fan-out (map-reduce)
Use Independent subtasks: candidate models, document batches, search breadth.
Failure mode Reducer becomes the bottleneck and the hallucination point; the merge step is designed and evaluated on its own.
Sub-agents with isolated context
Use Exploration that would flood the main context.
Failure mode Several times the tokens of a single agent; justified only when the work is parallel or the context isolation is the point.
Handoffs / swarm
Use Conversations that move between specialised domains.
Failure mode Lost state on transfer and agents bouncing the task; the handoff carries a typed payload, not the transcript.
01 / Durable execution
Agents are long-running processes, so treat them like one.
- • Graph state checkpointed after each step, so a crash resumes from the last step rather than replaying the run.
- • Human approval modelled as an interrupt on a typed state transition, resumed with the reviewer's decision as input — no external callback, no race.
- • Time-travel on checkpoints to replay a run from any step with a corrected state: the fastest debugging loop available for agents.
- • Tools that change the world are idempotent (request keys) and paired with a compensating action, saga-style, for multi-step side effects.
- • Step budgets, token budgets and wall-clock limits enforced by the runtime, not requested in the prompt.
02 / Context engineering
The context window is a budget, and most failures are budget failures.
- • Context rot is real: quality degrades as the window fills, well before the limit. Long runs compact their history into structured summaries at defined thresholds.
- • Progressive disclosure for skills: only names and one-line descriptions sit in context; full instructions, scripts and references load when a skill is selected.
- • Just-in-time retrieval: agents hold identifiers (paths, keys, queries) and fetch content when needed, instead of pre-loading everything a RAG step might want.
- • Memory split by kind: working state in the graph, episodic memory of past runs, procedural memory as versioned skills — each with its own write policy.
- • Prompt layout ordered for caching: stable system prompt and tool definitions first, volatile content last. Cache hit rate is tracked as a cost metric.
03 / Tool design
Tools are an interface for a model, and deserve the care of a public API.
- • Typed input and output schemas (Pydantic), with output validators that send a precise retry message back to the model instead of failing the run.
- • Parameters designed so the wrong call is hard to make: absolute identifiers, enums over free text, no ambiguous defaults.
- • Error messages written for the model: what was wrong and what to do next. A stack trace is a dead end; a corrective instruction is a recovery.
- • Results paginated, truncated and summarised by default; a tool that can return a million rows will eventually do so.
- • Fewer, higher-level tools beat many thin ones. When a task needs dozens of chained calls, letting the agent write code against the tools (code as action) cuts round-trips and tokens.
04 / Agents over enterprise data
A text-to-SQL agent is a security boundary before it is a feature.
- • Database role in read-only mode, scoped to allowlisted schemas; row-level policies inherited from the caller, never from the agent.
- • A semantic layer that names business entities and metrics, so the model reasons over meaning rather than raw column names.
- • Schema linking before generation: retrieve the relevant tables and verified example queries, then write SQL.
- • Static checks and EXPLAIN before execution, with row and cost ceilings; database errors fed back for self-correction.
05 / Interoperability
Stable contracts, replaceable runtimes.
- • A2A between agents: capability discovery through agent cards, a task lifecycle (submitted, working, input-required, completed) and streaming or push updates for long tasks. Agents stay opaque to each other.
- • MCP between agents and tools; skills for procedural knowledge. Each layer can change without touching the others.
- • The orchestration runtime — open-source graph frameworks or a managed agent development kit — is chosen on portability, state persistence, human-in-the-loop support and observability, because the protocol layer keeps that choice reversible.
06 / Evaluation
Evaluate the trajectory, not just the answer.
- • Outcome evals check the final state; trajectory evals check that the right tools were called, with valid arguments, in a sensible order, without loops.
- • Error analysis first: read traces, label failure modes, then write the evals that target them. Generic metrics measure what is easy, not what breaks.
- • Simulated users drive multi-turn agents through scripted goals and adversarial behaviour before real users do.
- • LLM-as-judge with explicit rubrics, calibrated against human labels, with agreement tracked over time to catch judge drift.
- • Suites run in CI on every prompt, tool or model change, and on sampled production traces online.
07 / Security
Prompt injection is not solved, so the architecture has to contain it.
- • The lethal trifecta — private data, untrusted content and a way to send data out — never meets in a single agent context.
- • Untrusted content (documents, web pages, emails) is read by a quarantined component with no side-effecting tools; it returns structured data, not instructions (dual-LLM and CaMeL-style designs).
- • Least privilege per tool and per run, short-lived credentials, and human approval on irreversible or external actions.
- • Guardrails as a separate, testable layer on inputs, tool calls and outputs — not as sentences in the system prompt.
08 / Operations & economics
Cost per resolved task is the only unit that does not lie.
- • Every step traced with OpenTelemetry GenAI conventions: prompt version, retrieved context, tool calls, tokens, latency, evaluation scores.
- • Model cascades: small models take the tractable majority, escalation goes to larger ones on low confidence or failed validation.
- • Per-team cost attribution in the same plane as latency and error rate, with budgets enforced by the runtime.
See it assembled
The reference architecture puts these building blocks in one picture.
Reference architecture