Phase 19: Capstone Projects

Capstone Lesson 25: Verification Gates and the Observation Budget

An agent harness without a verification layer is a wish in a trenchcoat. This lesson builds the deterministic gate chain that decides whether a tool call is allowed to fire, how much of its output the agent is allowed to see, and when the loop has to stop because the agent has read too much. The chain is a function of small, named gates plus an observation ledger that tracks every token the model has been shown. Build a VerificationGate protocol with a deterministic evaluate(call) method. Compose budget, recency, whitelist, and regex gates into a chain with short-circuit semantics. Track every observation through an ObservationLedger keyed by tool and turn. Refuse a tool call when the cumulative observation budget would be exceeded. Surface a structured GateDecision record that downstream observability can ingest. When an agent harness lets the model call tools freely, three classes of bug appear within the first hour of real use. The first is unbounded observation. A grep across a 200K-line repo dumps half a million tokens of output into the next turn. The model sees one match per kilobyte and the rest of the context is wasted. The token bill is large and the agent is now worse, not better, at the task. The second is stale recency. A long-running task accumulates fifty tool calls. The…

Capstone Lesson 25: Verification Gates and the Observation Budget: An agent harness without a verification layer is a wish in a trenchcoat. This lesson builds…

This free lesson is part of the AI Engineering from Scratch curriculum. Read the full explanation, run the lesson code, and verify the result in the interactive reader or from the repository source.

Browse the complete course catalog or open this lesson on GitHub.