Phase 10 · Agentic AI/
Lesson 10.11advanced3 h

Building production agents

State machines, durable execution, harness design, observability, cost control and release

The gap between an agent demo and an agent product is the gap between "it worked once" and "it works, visibly, at a known cost, for thousands of users, and fails safely". Closing it is software engineering: explicit state, persistence, retries, tracing, budgets, approvals and tests. This lesson collects the practices that production teams converged on by 2026 — graph-based control flow, durable execution, harness design for long-running work, the 12-factor agents principles — so your capstone (10.12 Project: build a research agent with tools, an MCP server and an eval harness) is built like a product from day one.

You'll be able to

  • Model an agent as an explicit state machine or graph and explain the benefits for testing, resumption and human review
  • Implement durable execution: checkpoints, idempotent tools, pause/resume for human approvals, and long-running harness artifacts
  • Instrument agents with traces and metrics and connect them to the evaluation harness
  • Control cost and reliability with budgets, routing, caching, retries and loop detection, and apply the 12-factor agents principles

Key ideas

  1. Production means reliable, observable, bounded, safe, resumable and maintainable — each maps to a concrete practice.
  2. Model control flow as an explicit graph/state machine with a typed state object: testable nodes, replay, human interrupts as nodes, clear termination ('own your control flow').
  3. Durable execution: checkpoint every step, pause/resume across hours for approvals, idempotent tools, and separate the model loop (brain) from sandboxed execution (hands).
Show 4 more key ideas
  1. Long-running harness: initializer writes structured artifacts; bounded clean-context sessions read them, do one unit, verify, commit, update — state lives in artifacts.
  2. Trace everything (prompts, tools, latency, tokens, cost, versions) and turn production failures into eval tasks; dashboard success, pass^k, cost per success, latency, tool errors.
  3. Reliability/cost levers: retries with backoff, timeouts, circuit breakers, budgets and loop detection, model routing, compaction, prompt caching, fallbacks; measure cost per successful task.
  4. 12-factor agents: own prompts, context and control flow; tools as structured outputs; small focused agents; stateless reducer; pause/resume; contact humans via tool calls.

Suggested path through this lesson