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.
How we took care of it.
- Check a hand-off first, then a payout.
- Ask DBOS for that workflow's state.
- Still waiting: answer "a colleague has this" and stop. Finished: answer from its state and clear it.
| It reads | pending_approval_id and pending_escalation_id in the saved conversation |
| Kind | rule |
| Provided by | harness |
| If it fails | the waiting answer; no router, no model |
| Where in the code | Agent._gates · F entrypoint/__init__.py:234 |
| Runs at | 1 · Before the loop |
Real exampleFlow 6, turn 2: "This is with a colleague in our claims team — your reference is E-4A818C40." 201 ms.
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