cleandataengineering.aiAgent Harness, drawn simply
You are here: End to end › Checks › 7 · After the loop › Tier-2 hand-off rules

Agent Harness Tutorial · End to end · Zoom level 3

How we take care of it: Tier-2 hand-off rules

Tier-2 hand-off rules catches declined, loop exhausted, tool down, second refusal, 10+ turns.

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 readsthe whole turn and theconversation's countersTier-2 hand-off rulesrule · agentpassCarries onfailIf it failshand to a personWHERE IN THE CODE: F escalation/rules.py · H entrypoint/handoff.py:191
The strip at the top shows every check point where this check runs, in dark.

How we took care of it.

  1. Six rules: declined, loop exhausted, tool unavailable, the same intent repeated, a second refusal, 10 or more turns.
  2. Any of them starts a DBOS hand-off to a person.
It readsthe whole turn and the conversation's counters
Kindrule
Provided byagent
If it failshand to a person
Where in the codeF escalation/rules.py · H entrypoint/handoff.py:191
Runs at7 · After the loop
Real exampleFlow 19: turn 10 fired turns-exceeded and raised E-8E24C2A1.

More on this: 19 · A long conversation.

How it is done: the real code

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

DEFAULT_RULES: tuple[Tier2Rule, ...] = (
    Tier2Rule(
        id="declined",
        when=(Condition(field="termination", equals=("declined",)),),
        reason="a payout the policyholder's account can no longer receive",
        priority=1,
        ttl_s=30 * 60,
    ),
    Tier2Rule(
        id="loop-exhausted",
        when=(Condition(field="termination", equals=TERMINATED_BADLY),),
        reason="the agent could not complete this and stopped",
        priority=2,
        ttl_s=15 * 60,
    ),
    Tier2Rule(
        id="tool-unavailable",
        when=(Condition(field="consecutive_failed", at_least=2),),
        reason="the claims system is not responding",
        priority=2,
        ttl_s=15 * 60,
    ),
    Tier2Rule(
        id="repeated-intent",
        when=(Condition(field="repeated_intent", at_least=3),),
        reason="the policyholder has asked for the same thing three times without resolution",
        priority=3,
        ttl_s=30 * 60,
    ),
    Tier2Rule(
        id="second-refusal",
        when=(Condition(field="refusals", at_least=2),),
        reason="the agent has refused this policyholder twice and a person should decide",
        priority=4,