Tools and Durable State

A model may propose an action, but deterministic application code must own authority, state and effects. This stage makes tools typed and workflows recoverable across retries, approvals, crashes and ambiguous outcomes.

Section 4 of 8 · 12 units · about 55 hours

0/12

By the end you can Run a kill-and-replay matrix before and after every simulated effect, replay duplicate events without duplicate irreversible actions, and prove every tool call is typed, authorized, bounded, resumable or explicitly ambiguous, and auditable.

Units

Build it

Mini project · about 18 to 24 hours

Durable tools with exact consent and independently verified effects

Extend agentlab in tools/ and workflow/ with a deterministic executor for its grounded workflow. Prove authority and recovery against separately persisted simulated effects before adding autonomy. Use the section's pinned Python libraries and CPU fakes without paid APIs; hosted contracts are reading references only.

  1. 1Inventory read-only, reversible, compensable and simulated irreversible tools with owners and failure policies. Build a strict versioned registry and description rewrite; check canonical arguments, string fidelity, old schemas and malformed, oversized, partial or miscorrelated results against independent fixtures before model use. Retain rejection and unresolved-outcome evidence.
  2. 2Enforce caller-supplied authority outside proposals, using trusted resource ownership. Check two-tenant and forged-identity denials against independent policy tables and recipient state. Persist exact-effect approvals; retain changed-argument, schema/policy drift, rejection, expiry, reuse and revocation-during-pause/restart tests, stating the final recipient admission boundary.
  3. 3Build versioned SQLite transitions with atomic intent, history and dispatch-work commits. Independently persist recipient keys, fingerprints, effects and receipts atomically under the AWS idempotency contract; retain lost-reply, changed-request, retention-expiry and unavailable-lookup tests. Reconcile the original operation or assign ambiguity, never infer failure from missing outcomes.
  4. 4Extend the shared ledger with durable attempts, deadlines, scheduling and cancellation. Test fake-clock restart, hidden retries and poison work against hand-enumerated admissions; retain owned review records and unknown effects. Rebuild state with an independent audit reducer and replay observations without model calls or effect execution.
  5. 5Persist compensation intents and stable keys; compare failed, repeated and restarted compensation with independent business invariants. Enforce durable ordered fencing epochs atomically at the recipient, including compensations; retain delayed distinct stale-operation denials after restart and distinguish pending repair from completed compensation or irreversible history.
  6. 6Expose the registry through the official Python SDK's stdio server/client fixture, including a typed tool and resource. Check captured wire messages against the section's MCP 2026-07-28 discovery, metadata, framing and error contracts; retain host-policy denials proving returned text and advertised capabilities cannot authorize execution.
  7. 7Kill around intent, delivery, recipient commit, outcome and acknowledgement for every effect; restart at every state. Check independent recipient and transition ledgers; retain unsafe-variant detection, safety/recovery classifications, interventions and recovery timings. Optionally add atomic inbox admission, durable work, acknowledgement crashes, stale-generation results and poison-event review.
What you hand in
  • Versioned tools/ registry, capability policy, MCP server and workflow/ executor with exact approvals, budgets and regression tests.
  • Separate recipient fixtures in fakes/, effect inventory, state contract, kill matrix and effect-free replay manifests.
  • Rebuildable reports/ with per-run safety, recovery, ambiguity, compensation and intervention evidence, including unsafe variants and storage-failure limits.
How to check it
How it's graded

Contracts and authority

Pass: Your strict schema, fidelity and independent policy fixtures reject invalid proposals before dispatch; result correlation preserves unknown effects. Exact approval and current authorization tests include changed, expired, revoked and resumed cases.

Great: Description changes retain executable semantics and old fixtures expose breaking changes. Recipient admission closes the declared revocation race; MCP discovery and returned text never become authority.

Durable effect identity

Pass: Your independent recipient ledger validates atomic duplicate suppression, mismatch rejection, lost-reply recovery, retention limits, fencing and compensation. Versioned state/history commits survive process death; unavailable reconciliation remains owned and unresolved.

Great: Unsafe split-commit or deduplication variants fail the same oracle. Distinct stale operations and repeated compensation remain contained after restart, without claiming power-loss durability or erasure of observed history.

Bounded recovery evidence

Pass: Your fake-clock admission tests preserve retry/deadline bounds and cancellation across restart. Independent audit reduction matches stored state; every kill-matrix row retains recipient evidence, recovery classification and interventions, including failures.

Great: Replay makes no dependency calls and regenerates reports. Optional event integration preserves inbox identity and pending work across acknowledgement crashes; safe manual review remains distinct from automatic task recovery.

Resources

  • Durable Tool-Using WorkflowRoadmap-Final

    Build the reduced core through typed tools, one approval, one simulated irreversible effect, one compensable effect, capability policy, idempotency, durable intent and outcome, bounded execution and replay. Run kill tests around every persistence and effect boundary before adding an agent loop.

  • AI Agents in Depth - Tools and Asynchronous InteractionBojie Li

    Read Chapter 4: 4.2 tool design and schema fidelity, 4.3 MCP, 4.5 versus 4.6 (read-only perception tools against execution tools), the "Idempotency and Cancellation Semantics" passage and the observability part of 4.6, and 4.7 human-in-the-loop timeouts. Add 5.1.5 Failure and Error Recovery and 6.2 asynchronous interaction. Translate the advice into explicit state and effect contracts.

  • Model Context Protocol Specification 2026-07-28Model Context Protocol

    Read the 2026-07-28 architecture and versioning pages: there is no initialize handshake, every request carries _meta protocol version, client info and capabilities, and server/discover lists versions and capabilities. Then the stdio and Streamable HTTP bindings, tools/list and tools/call (input and output schemas, isError versus JSON-RPC errors), resources and prompts, the tasks extension, and the roots and sampling deprecations. Build one small stdio server and client, record the wire messages, and keep application authorization outside the protocol.

  • Making Retries Safe with Idempotent APIsAmazon Builders' Library

    Read "Retrying and the potential for undesirable side effects", "Reducing client complexity with idempotent API design", "Semantic equivalence and support for default retry strategies", "Late arriving requests and the life span of unique client request identifiers" and the parameter-mismatch section. Record the key and the effect atomically, scope keys by caller, and reject a reused key with different parameters.

  • Idempotent RequestsStripe

    Read the page as one concrete recipient contract: an Idempotency-Key header, the first result saved and replayed, parameter mismatch rejected, keys pruned after at least 24 hours (API v1), and the different API v2 retry semantics. Encode these cases in your fake effect recipient; do not treat 24 hours as universal.

  • Timeouts, Retries, and Backoff with JitterAmazon Builders' Library

    Read "Timeouts", "Retries and backoff" and "Jitter": a timeout leaves the outcome unknown, side-effecting calls are unsafe to retry without idempotency, and retries belong at one layer with a token-bucket budget. Model the unknown outcome as its own workflow state.

  • How to Do Distributed Locking (fencing tokens)Martin Kleppmann

    Read "What are you using that lock for?", "Protecting a resource with a lock" and "Making the lock safe with fencing". The effect recipient must remember the highest token and reject older ones (34 accepted, delayed 33 rejected); a random lock value is not a fencing token. Fencing rejects stale authority, while idempotency rejects repeated operations.

  • LangGraph Persistence and InterruptsLangChain

    Read persistence (checkpointer versus store; the in-memory saver does not survive a restart), interrupts (interrupt, Command(resume=...), the rules of interrupts, "side effects called before interrupt must be idempotent") and the Functional API determinism and idempotency sections. Resuming restarts the interrupted node from its beginning: reproduce the repeated pre-interrupt action with a SQLite checkpointer across two processes.

  • DBOS Transact Python: Workflows and StepsDBOS

    Read the workflow tutorial ("Workflow IDs and Idempotency", "Determinism"), the step tutorial ("Configurable Retries", "Step Timeouts") and the system-database page (SQLite by default). Kill a process mid-workflow and confirm that completed steps do not rerun while the interrupted step does. Choose this or LangGraph as the implementation companion, not both.

  • Writing Effective Tools for AI AgentsAnthropic

    Read "Running an evaluation" and "Principles for writing effective tools" through "Prompt-engineering your tool descriptions": a small task-shaped tool surface, unambiguous parameter names, bounded and paginated results, actionable errors. Compare with the OpenAI function-definition best practices and rewrite one tool contract.

  • AI Engineering Handbook - Agent EngineeringHandbook Academy

    Study the Part 7 chapters on tool design, MCP and security, human review and long-running agents. Use them to audit user-facing workflow behavior and failure paths after the durable core works.

  • The Hitchhiker's Guide to Agentic AI - Harness and MCPHaggai Roitman

    Use v3 sections 18.4 to 18.7 (tool integration, orchestration with the explicit state machine in 18.5.5, state management and checkpoints, error handling), then Chapter 23 for MCP vocabulary and 23.6 for its security model. Its transport lists predate the 2026-07-28 specification and 18.4.5 contradicts Chapter 23, so take protocol facts from the specification.

  • SagasHector Garcia-Molina and Kenneth Salem

    Read Section 1 (p. 250: compensation does not necessarily restore the earlier state) and Section 9 Designing Sagas, with Sections 4 and 5 on backward and forward recovery. Some actions cannot be compensated; model failed compensation and manual handling explicitly.

  • Temporal: Workflow Replay, Activity Retries and TestingTemporal

    Read Event History and replay, the Python workflow logic requirements, "Make Activities idempotent", the default retry policy (unlimited attempts unless set) and Signals versus Updates. Activities may run more than once, so replay does not make an external effect exactly-once.