---
title: "Agent Capstone"
description: "Follow a question through retrieval, tools, and verification: a successful call can still return the wrong item."
source: https://vizlearn.app/capstones/projects/agent-capstone
---

# Agent Capstone

An agent workflow needs evidence for its answer, even when every tool call reports success.
This Agent Capstone follows a stock question through policy retrieval, a tool call, calculation,
and validation. A receipt for the wrong item produces correct subtraction but an unsupported
answer; checking identity stops it before delivery.

You ask how many M4 pieces to reorder. The tool politely says `ok` and hands back M6 stock.
The subtraction will not complain. Something has to compare the returned item with the item
you actually asked about.

## How the Agent Capstone Works

The request fixes the item, M4, and the unit, pieces. A small document lookup finds the current
M4 policy, `restock-v2`. It specifies a target of 50 pieces and the rule
`reorder = max(0, target - available)`. The policy establishes what should be in stock; an
inventory receipt establishes what is available in the fixed snapshot.

The execution harness calls `read_stock(M4)`. The receipt keeps the requested item separate
from the returned item. It also records the quantity, unit, call id, and inventory row id.
The `ok` status means the call executed. It does not certify that those fields answer the request.

Calculation creates a candidate, not a deliverable. Validation first checks item and unit.
If they match, it recomputes the quantity from the policy and receipt and checks the candidate's
references. Only a candidate that passes all four checks reaches the answer dock.

| Artifact | What the next stage needs from it |
| --- | --- |
| Request | The item and unit the answer must describe |
| Current policy | The target and restock rule |
| Stock receipt | Available quantity, returned identity, and source id |
| Candidate | A proposed quantity with its exact policy and receipt references |
| Validation | Evidence that the specified consistency checks passed |

## Agent Capstone Step by Step

The default has the policy available and injects a wrong-item response on the first call only.
The inventory snapshot contains 18 M4 pieces and 31 M6 pieces.

1. **Request M4.** The question fixes the item and unit before any data is retrieved.
2. **Retrieve the policy.** The lookup selects current M4 policy `restock-v2`; the unrelated
   packing note supplies no restock rule. The selected target is 50 pieces.
3. **Read stock.** Call 1 requests M4. `receipt-1` reports execution `ok`, but its returned item
   is M6 and its available quantity is 31 pieces.
4. **Calculate the candidate.** `max(0, 50 - 31) = 19`. The number is held as an unverified
   M4 candidate, with the policy and receipt attached.
5. **Check identity.** M4 and M6 do not match. The quantity is rejected before delivery, even
   though the subtraction is correct. The failed receipt stays in the attempt history.
6. **Spend one retry.** The harness retains the current policy and calls `read_stock(M4)` again.
   This is a fixed recovery rule, not a model deciding to correct itself.
7. **Read the second receipt.** `receipt-2` returns M4, 18 pieces. The new candidate is
   `max(0, 50 - 18) = 32` pieces.
8. **Check each requirement.** Item M4 matches, then unit piece matches. Recompute 32 from
   policy target 50 and receipt stock 18. Finally compare the candidate's policy and receipt IDs
   with `restock-v2` and `receipt-2`; rejected `receipt-1` is explicitly excluded. The four check
   marks appear in order before the answer card expands.
9. **Deliver within scope.** The card says “Passed four consistency checks” and releases 32 M4
   pieces with both sources. This does not establish external stock truth. No order is placed.

The moving candidate stays outside the answer dock until validation passes. The rejected
19-piece ticket moves into a faded history bay; it never becomes evidence for the second answer.

## What Do the Four Checks Establish?

It means four specified consistency checks passed. The workflow has not independently measured
the warehouse, proved that the policy is sensible, or established that a live stock count remains
current. A consistent answer can still inherit false information from its sources.

Change **Tool response** while leaving **Evidence** available. Correct returns 32 on one call.
Wrong once rejects 19, then returns 32 on the second call. Always wrong rejects both candidates
and ends without a numeric answer. Then remove the policy: every response setting stops before
a stock call because there is no supported target to use.

## Edge Cases

- **Missing policy:** the packing note remains retrievable but cannot supply a restock target.
  The workflow stops before calling the stock tool.
- **Persistent wrong item:** a second M6 receipt exhausts the one-retry budget. Repetition does
  not turn it into M4 evidence.
- **Correct first response:** identity passes immediately; calculation and reference checks
  still run before delivery.
- **Stock at or above target:** the restock formula yields zero, never a negative order. The
  fixed lesson snapshot stays below target; the arithmetic engine also checks these boundaries.

## Common Mistakes

- Treating `ok` as permission to release an answer without checking returned fields.
- Copying the requested M4 label over an M6 response, erasing the evidence of the mismatch.
- Checking subtraction while ignoring which item and unit its operands describe.
- Reusing a rejected receipt's id when the second candidate is accepted.
- Guessing a target when retrieval found no current restock policy.

## A Note on Simplification

This is a deterministic harness simulation with authored documents and frozen inventory.
Retrieval uses exact metadata lookup, not embeddings. There is no live language model,
natural-language planner, warehouse connection, authentication, or order placement. Fault
settings change which inventory row the tool returns; the same validator processes every run.
One retry bounds this demonstration, not agents in general.

For the components compressed here, see [RAG](https://vizlearn.app/ai/agents/rag),
[Tool Calling](https://vizlearn.app/ai/agents/tool-calling), and [Error Recovery](https://vizlearn.app/ai/agents/error-recovery).
