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 1.5 hr Python (stdlib)

Prerequisites: Phase 19 · 20-24 (Track A1: agent loop, tool registry, message store, prompt builder, model router), Phase 14 · 33 (instructions as constraints), Phase 14 · 36 (scope contracts), Phase 14 · 38 (verification gates)

#Learning Objectives

  • 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.
Full Access lesson

Keep going. The rest of this lesson is one step away.

Unlock all 503 lessons, video, code, quizzes and every future update. Pay in your own currency with Paystack.

The text and code of this lesson are based on AI Engineering from Scratch by Rohit Ghumare, MIT licensed.