Agent Harness Tutorial · End to end · Zoom level 2
Check point 5: The tool itself
The far end does not trust the harness either. It checks again, on its own.
Where: on the claims system's side.
| Check | Catches | Kind | Provided by | If it fails |
|---|---|---|---|---|
| token again | wrong audience or missing scope | rule | claims system | error result |
| only his rows | another customer's claim | rule | claims system | not found |
| approval covers it | a payout without a matching, recorded approval | rule | claims system | refused |
| idempotency key | the same write twice | rule | claims system | first answer again |
| cut to 8,000 chars | huge results | rule | harness | "[truncated]" mark |
Why check twice? Because the claims system may one day be called by other agents too. Each side protects itself, so a bug on one side cannot leak data on its own.
How it is done: the real code
Cut from the live repositories each time the site is built, so it always matches what runs.
claims_system/server.py:222The claims system's own gate@dataclass(frozen=True)
class _Gate:
"""Who is asking, and whether money may move: this system's checks."""
store: Store
authorise: Authorise
approvals: ApprovalRecordReader | None
clock: Callable[[], float]
limits: Settings
async def record(self, meta: Mapping[str, object]) -> ApprovalRecord | None:
named = meta.get(APPROVAL_META)
if self.approvals is None or not isinstance(named, str):
return None
return await self.approvals.approval(named)
async def holder(
self, operation: str, arguments: dict[str, Any], ctx: Context | None
) -> str | None:
meta = _meta(ctx)
call = Call(operation, SCOPES.get(operation, READ_SCOPE), _bearer(ctx, meta), meta)
try:
caller = await self.authorise(call)
except CallRefused as exc:
raise NotAuthorised(f"{operation} refused: {exc}") from None
if caller.holder is not None or not _workflow(caller):
return caller.holder
return _on_approval(await self.record(meta), operation, arguments)
async def payable(self, claim_id: str, who: str, ctx: Context | None) -> None:
"""The far end's own check on money moving (AHC-0057)."""
claim = await self.store.get_claim(who, claim_id)
if not claim.get("found"):
return # answered as unknown by the store, never as refusedLook inside
How we take care of it: token againCatches wrong audience or missing scope.How we take care of it: only his rowsCatches another customer's claim.How we take care of it: approval covers itCatches a payout without a matching, recorded approval.How we take care of it: idempotency keyCatches the same write twice.How we take care of it: cut to 8,000 charsCatches huge results.