cleandataengineering.aiAgent Harness, drawn simply
You are here: End to end › Router › How it decides

Agent Harness Tutorial · End to end · Zoom level 2

How the router decides

The router asks four questions, always in the same order. The first "yes" decides the path. If all four say no, the message goes to the loop.

1. Must a person handle this?injury · asks for a human · roadside or towyesOpen: EscalateEscalatezoom in ›no2. Must we refuse?6 rules: coverage, liability, someone else's policy, policy change, fraud, legalyesRefuseno3. Which intents are in it?7 intents, e.g. claim_status, report_claim, payout_request4. Exactly one read, one reference?one intent · read-only · one CLM- or POL- numberyesOpen: DirectDirectzoom in ›noOpen: Agentic: the loopAgentic: the loopzoom in ›
The order matters. Hand-offs are checked first, so we never refuse half a message while ignoring an injury in the other half.

Question 1 handles "not" properly. "Nobody was hurt" does not count as an injury.

Question 4 is strict on purpose. All three must hold: exactly one intent, that intent only reads (claim status, payout status, policy status), and exactly one reference of the right kind. Two claim numbers, a typo like "pol 1", or any write all go to the loop instead.

The rules have a version (v1 today), recorded on every trace, and a test checks every example message from the spec. Change a rule and the version goes up.

Limits. The rules read English words, not the database, so "my claim" always goes to the loop. Not built yet: a small local classifier for messages the rules can't place (it needs about 500 labelled examples), and a small model as a last resort.

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/router/__init__.py:260The four questions, in order
def _decide(text: str, rules: Rules) -> Route:
    for rule_id, reason, pattern in rules.escalate:
        if pattern.search(text):
            return Escalate(reason=reason, rule_id=rule_id, tier=1)

    for rule_id, reason, pattern in rules.refuse:
        if pattern.search(text):
            return Refuse(reason=reason, alternative=ALTERNATIVE, rule_id=rule_id)

    matched = intents_of(text, rules)
    if len(matched) != 1 or matched[0] not in DIRECT_HANDLERS:
        return Agentic(goal=text.strip(), candidate_intents=matched)

    # P-DIRECT: exactly one intent and exactly one claim or policy — of the kind
    # the handler reads. Several, or none, is the loop's.
    intent = matched[0]
    named = references(text)
    if len(named) != 1 or not next(iter(named)).startswith(KEYED_BY[intent]):
        return Agentic(goal=text.strip(), candidate_intents=matched)
    return Direct(intent=intent, handler=DIRECT_HANDLERS[intent], args={"id": named.pop()})