Agent Harness Tutorial · End to end · Zoom level 2
Check point 1: Before the loop
Before anything thinks, prove who is asking and decide whether this message should reach the model at all.
Where: front door and router.
| Check | Catches | Kind | Provided by | If it fails |
|---|---|---|---|---|
| verify the token | a forged or expired sign-in | rule | harness | 401, stop |
| kill switch | the agent has been switched off | rule | harness | "paused" reply |
| delivery ledger | the same message sent twice | rule | harness | stored first answer |
| anything waiting? | a payout or a person already on it | rule | harness | the waiting answer |
| router rules | injury, coverage promises, fraud, legal... | rule | agent | hand-off or refusal |
| consent | lists the writes Rohan's own words asked for | rule | agent | used later, at the tool |
Consent is worth a second look. It reads only Rohan's own messages and writes down which writes he asked for, such as request_payout:CLM-010004. Tool results can never add to that list. Check point 4 uses it. Router details: how the router decides.
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_fnol/entrypoint/__init__.py:141Agent.handle: the ledger, then the gates async def handle(
self,
text: str,
*,
identity: Identity,
conversation: Conversation | None = None,
run_id: RunId | None = None,
delivery_id: str | None = None,
gone: agent_loop.Gone | None = None,
) -> tuple[TurnResult, Conversation]:
"""One turn in, one typed result out.
The conversation is returned rather than mutated, so a caller — a test,
or a resumed approval — always holds the state that produced the result
it is looking at.
`gone` is the door's way of saying the caller has left (AHC-0096): asked
before the route's work starts and, on the agentic route, wherever the
loop checks its deadline. A door that cannot tell passes nothing.
"""
# AAC-0076. The guard is outermost: a duplicate delivery must not mint a
# second run, whose idempotency keys would be new. A redelivery after the
# claim expired is the same run, named by the message (A5). Keyed under
# the customer, or another's key reads the first reply (run 2).
conversation, run_id = delivered(identity.customer_id, conversation, run_id, delivery_id)
if self.deliveries is not None and delivery_id is not None:
named = f"{identity.customer_id}:{delivery_id}"
async with req.once(self.deliveries, named, scope=req.Scope.DELIVERY) as claim:
answer = await self._turn(text, identity, conversation, run_id, gone)
# What a redelivery is told. A turn that *raised* settles too,
# with nothing to say — `Scope.DELIVERY` decides that, because
# arriving at the end at all means the turn ran.
if claim is not None:
claim.outcome = ending.as_answer(*answer)Look inside
How we take care of it: verify the tokenCatches a forged or expired sign-in.How we take care of it: kill switchCatches the agent has been switched off.How we take care of it: delivery ledgerCatches the same message sent twice.How we take care of it: anything waiting?Catches a payout or a person already on it.How we take care of it: router rulesCatches injury, coverage promises, fraud, legal....How we take care of it: consentCatches lists the writes Rohan's own words asked for.