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

Agent Harness Tutorial · End to end · Zoom level 3

How we take care of it: router rules

router rules catches injury, coverage promises, fraud, legal....

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 readsRohan's words, with odd spaces andlook-alike letters folded firstrouter rulesrule · agentpassCarries onfailIf it failsa hand-off or a polite refusalWHERE IN THE CODE: route() → _decide() · F router/__init__.py
The strip at the top shows every check point where this check runs, in dark.

How we took care of it.

  1. Three hand-off rules: injury (handles "nobody was hurt"), asks for a person, roadside or tow.
  2. Six refusal rules: R-COVERAGE, R-LIABILITY, R-OTHER-HOLDER, R-POLICY-CHANGE, R-FRAUD, R-LEGAL.
  3. Each fixed reply is written in advance, so the model never improvises a refusal.
It readsRohan's words, with odd spaces and look-alike letters folded first
Kindrule
Provided byagent
If it failsa hand-off or a polite refusal
Where in the coderoute() → _decide() · F router/__init__.py
Runs at1 · Before the loop
Real exampleFlow 5: "Will my claim be approved?" matched R-COVERAGE: 164 ms, no model.

More on this: How it decides.

How it is done: the real code

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

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()})