cleandataengineering.aiAgent Harness, drawn simply
You are here: End to end › Checks › 1 · Before the loop

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.

The strip at the top is the whole turn; the dark box is where you are. Click a check, or what it catches, to see how we took care of it. Dashed boxes are not built yet.
CheckCatchesKindProvided byIf it fails
verify the tokena forged or expired sign-inruleharness401, stop
kill switchthe agent has been switched offruleharness"paused" reply
delivery ledgerthe same message sent twiceruleharnessstored first answer
anything waiting?a payout or a person already on itruleharnessthe waiting answer
router rulesinjury, coverage promises, fraud, legal...ruleagenthand-off or refusal
consentlists the writes Rohan's own words asked forruleagentused 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