Agent Harness Tutorial · End to end · Zoom level 2
Hand-off to a person
Sometimes the right answer is a person. The router hands off at once for injuries or when Rohan asks for a human; the after-loop rules hand off when a conversation is going badly. Either way, a DBOS workflow holds the hand-off until someone picks it up.
While a hand-off is queued, the front door answers every new message with "a colleague has this" and the model is not called. That stops the agent and a person both answering at once.
Code view: input, process, output, the call stack, the classes
Goes inA message the router decides must go to a person
What happensAn escalation record is written by a durable DBOS workflow that waits for a colleague's resolution or its own expiry, and the next turn checks it before doing anything else
Comes outAn Escalated reply now; the conversation handed back once resolved
How it is done: the real code
Cut from the live repositories each time the site is built, so it always matches what runs.
agent_harness/escalation/dbos.py:60The hand-off workflow@DBOS.workflow(name=WORKFLOW)
async def _wait(raised: Raise) -> Escalation:
now = int(await box.now())
escalation = Escalation(
id=raised.id,
conversation_id=raised.conversation_id,
run_id=raised.run_id,
customer_id=raised.customer_id,
tier=raised.tier,
context=raised.context,
rule_id=raised.rule_id,
rules_version=raised.rules_version,
reason=raised.reason,
state=EscalationState.QUEUED,
created_at=now,
expires_at=now + raised.ttl_s,
)
await _publish(escalation)
accepted: box.Ballot | None = None
while escalation.open:
moment = await box.now()
if moment >= escalation.expires_at:
# The lapse, as a timer rather than as somebody remembering to sweep.
escalation = escalation.model_copy(
update={"state": EscalationState.EXPIRED, "resolved_at": int(moment)}
)
break
ballot = await box.next_ballot(TOPIC, escalation.expires_at - moment)
if ballot is None:
continue
why = _judge(escalation, ballot.decision, int(await box.now()))
if why is not None:
await box.reply(ballot, box.Answer(refused=why))
continue