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

Agent Harness Tutorial · End to end · Zoom level 3

How we take care of it: anything waiting?

anything waiting? catches a payout or a person already on it.

Open: 11before loopopen ›Open: 22before modelopen ›Open: 33after modelopen ›Open: 44before toolopen ›Open: 55the toolopen ›Open: 66after toolopen ›Open: 77after loopopen ›Open: 88before replyopen ›It readspending_approval_id andpending_escalation_id in the savedanything waiting?rule · harnesspassCarries onfailIf it failsthe waiting answer; no router, noWHERE IN THE CODE: Agent._gates · F entrypoint/__init__.py:234
The strip at the top shows every check point where this check runs, in dark.

How we took care of it.

  1. Check a hand-off first, then a payout.
  2. Ask DBOS for that workflow's state.
  3. Still waiting: answer "a colleague has this" and stop. Finished: answer from its state and clear it.
It readspending_approval_id and pending_escalation_id in the saved conversation
Kindrule
Provided byharness
If it failsthe waiting answer; no router, no model
Where in the codeAgent._gates · F entrypoint/__init__.py:234
Runs at1 · Before the loop
Real exampleFlow 6, turn 2: "This is with a colleague in our claims team — your reference is E-4A818C40." 201 ms.

More on this: DBOS.

How it is done: the real code

Cut from the live repositories each time the site is built, so it always matches what runs.

    async def _gates(
        self, conversation: Conversation, identity: Identity, run_id: RunId
    ) -> tuple[TurnResult | None, Conversation]:
        """Work already in someone else's hands comes before anything the customer says.

        A result means the turn ends here; `None` means proceed, with the
        conversation as the gates left it.

        The escalation is checked first. A person owns this conversation, and
        nothing the customer says should start work the colleague may be about to
        make pointless. When nothing holds it any more — resolved, missing, or no
        store to read — the stale flag is cleared here rather than left to
        re-answer the same question on every future turn.
        """
        if conversation.pending_escalation_id is not None:
            held = await self.desk.hold(conversation)
            if held is not None:
                return held
            conversation = conversation.returned()  # P-ESC-FRESH, P-ESC-ONCE

        if conversation.pending_approval_id is not None:
            resumed = await self.pending.resume(conversation, identity, run_id, self.tools)
            if resumed is not None:
                return resumed

        return None, conversation