Practical technical guides / Agent-era architecture

Find Overlapping Agent Workflow Guards Before Any Action Runs

When an agent supplies facts to a workflow state, check every guard against every input combination first: gaps strand requests, overlaps pick a route silently.

By Sandeep Belgavi · Published 2026-11-21

When an agent supplies facts to a workflow state, check every guard against every input combination first: gaps strand requests, overlaps pick a route silently.

The problem in one state

Many agent workflows keep an explicit state machine around the model. The model does the reading and judging, and the machine decides what is allowed to happen next. That split works well until the transition guards themselves stop agreeing with each other. A guard is a boolean condition on a transition. When an agent starts supplying the facts those guards read, two quiet failures appear. A gap is an input for which no guard is true, so the request has nowhere to go. An overlap is an input for which two or more guards are true, so something other than your intent picks the route.

Take one state from a refund workflow at the fictional Belgavi's Book Store. A refund request waits in review. Three facts decide where it goes. verified says whether the customer's identity check passed, and it comes from a deterministic service. over_limit says whether the refund is above the amount an automated path may pay, and it comes from arithmetic on the order. confident says whether the agent that read the help-desk conversation is confident the item qualifies, and it is the only fact a model produces. Three transitions leave the state:

  • T1 to auto_refund when verified and not over_limit and confident
  • T2 to human_review when verified and (over_limit or not confident)
  • T3 to verify_identity when not verified

Three boolean facts give exactly eight input combinations. With that few, there is no reason to argue about coverage. Enumerate the combinations and count how many guards are true for each one.

What SCXML does when guards disagree

The W3C SCXML Recommendation is useful here because it states the rule plainly. A transition with an event and a condition is selected only if the event matches and the condition evaluates to true. If more than one transition matches, the first one in document order is taken. If none matches, no transition is selected and the machine stays where it is. Many workflow engines and hand-written routers behave the same way, whether or not they document it. A match statement, an if-else chain, a rules table read top to bottom: each one resolves an overlap by position and turns a gap into either a stuck item or an unhandled branch.

Neither behaviour is wrong in itself. Document order is a perfectly good tie-break when the author meant it. The trouble is that a guard edited months later, often to accommodate a new agent signal, can create an overlap that nobody chose, and the router will resolve it without a word.

A worked example with three fixtures

The companion example checks three versions of the same state. In the complete version, each of the eight combinations makes exactly one guard true. Four combinations with verified false go to T3. Of the four with verified true, one goes to T1 and three go to T2.

In the gap version, T2 was shortened to verified and over_limit, dropping the half about confidence. One combination now matches nothing: verified, not over the limit, and not confident. That is the case where the agent hesitated, which is the case you most wanted a person to see. With document-order routing and no fallback, that request stays in review indefinitely.

In the overlap version, T1 lost its verified term during an edit, so it reads not over_limit and confident. One combination now matches two guards: an unverified customer, a small amount, and a confident agent. T1 and T3 are both true. Document order takes T1, so an unverified customer gets an automatic refund. Reverse the transition order and the same input goes to verify_identity. The behaviour of the system now depends on the line order of a configuration file.

from itertools import product

FACTS = ('verified', 'over_limit', 'confident')

def coverage(transitions):
    report = []
    for values in product((False, True), repeat=len(FACTS)):
        facts = dict(zip(FACTS, values))
        matches = [t['name'] for t in transitions if t['guard'](facts)]
        kind = 'ok' if len(matches) == 1 else ('gap' if not matches else 'overlap')
        report.append((facts, matches, kind))
    return report

def accept(transitions, fallback=False):
    kinds = [k for _, _, k in coverage(transitions)]
    return 'overlap' not in kinds and ('gap' not in kinds or fallback)

Running the example prints zero gaps and zero overlaps for the complete fixture, one gap for the gap fixture, and one overlap for the overlap fixture, with the priority pick T1. In strict mode the overlap fixture is refused before any request is routed.

Strict routing versus priority routing

There are two defensible policies, and the important thing is to choose one on purpose.

Strict routing treats every gap and every overlap as a defect. The check runs when the workflow definition is loaded or deployed, and a machine that fails it never starts. This fits states where a wrong route has a cost you cannot undo: paying money, sending a message to a customer, deleting data. It also makes edits safer, because the person who shortens a guard finds out immediately which combinations moved.

Priority routing accepts overlaps and resolves them by order, which is what SCXML specifies. It fits states where the routes are ranked by design. A common example is a list of increasingly general escalation rules. If you choose it, record the overlaps the check found and the transition that wins each one, and review that list whenever the guards change. A transition that never wins any combination is dead code, and the example reports those as well.

A catch-all fallback, a final transition whose guard is always true, closes gaps but not overlaps. In the example, the gap fixture with a fallback to escalate_to_person passes the strict check, and the lonely request goes to a person. The overlap fixture still fails, because a fallback cannot tell you which of two true guards the author meant.

What stays deterministic

The point of this design is that the model contributes one input and never the routing. Concretely:

  • The guards are code or configuration under review, never text the model writes at run time.
  • verified and over_limit come from deterministic services and are recomputed, not taken from the agent's summary of them.
  • The agent's confident signal is a typed boolean or a calibrated score compared with a threshold in code. Its free-text reasoning is logged for people to read but does not reach a guard.
  • The coverage check runs in continuous integration and again at load time. It can be exhaustive because the input domain is finite.

When a fact is numeric, the domain is no longer eight rows, but it is usually still finite in the way that matters. Guards compare a number with a small set of thresholds, so the boundary values and one value inside each interval form a complete test set. Enumerate those instead of every amount. For guards over strings, dates or several numbers combined, a satisfiability solver can find the overlapping inputs, but a table of boundary cases reviewed by a person catches most real mistakes.

Migration steps for an existing workflow

  1. Pick one state where an agent signal already feeds a branch, and write its guards down as separate named predicates rather than an if-else chain.
  2. List the facts each guard reads and the type and source of each fact. Mark the ones a model produces.
  3. Enumerate the input domain, or the boundary values for numeric facts, and run the coverage report against the current guards. Expect to find something. In practice the most common finding is a gap where the agent is uncertain.
  4. Decide strict or priority for this state, write the decision next to the guards, and fix or explicitly accept each finding.
  5. Add the report to the test suite so that a guard edit that creates a new gap or overlap fails the build, and log the transition name with each routed request so production traffic can be compared with the table.
  6. Only then let the agent's signal into more states.

Failure modes to test

The coverage table covers the definition. These checks cover what happens around it:

  • A fact arrives missing or null. Decide whether that is a ninth input value, or a validation error before routing, and test it. Treating missing as false silently makes verified false for a request whose check simply timed out.
  • The agent returns a confidence score where a boolean was expected, or a string such as "yes". Validate the type before the guard sees it.
  • Two transitions have the same target but different side effects in their actions. Coverage by target hides that, so report by transition name.
  • The order of transitions changes because a configuration loader sorts keys. If you use priority routing, keep order in a list, not a map.
  • A request sits in a gap state with no timeout. Every state that waits needs a timer transition, and it belongs in the coverage table too.

When the agent is unnecessary

If every fact a guard reads can be computed from records, there is no reason to put a model in the state at all. The example's verified and over_limit facts are like that. An agent earns its place when it turns unstructured input, such as a customer's message about a damaged book, into a typed fact that rules could not extract. Even then, it should change one input to a deterministic decision rather than choose the transition. If your agent is being asked to choose between auto_refund and human_review directly, you have moved the routing logic into a prompt where no coverage check can reach it.

Verification checklist

  • The coverage report shows zero gaps and zero overlaps, or each one is listed with an owner and a reason.
  • Reversing the transition order does not change any route in a strict state.
  • A test sends the overlap combination and asserts the intended target, not merely that some target was chosen.
  • Missing, null and mistyped facts are rejected before routing, and the rejection is logged with the request.
  • The interactive lab reproduces the three fixtures and lets you route one request under either policy, so a reviewer can see the gap and the overlap without reading code.

Run the example yourself

The coverage report, strict and priority routing, the three fixtures and six tests for every result quoted here. Companion code on GitHub; its README lists the prerequisites, exact commands, expected output and limits.

Interactive experiment

Agent guard coverage: find gaps and conflicting transitions. Synthetic inputs computed in your browser; read the lab notes on assumptions and limits before drawing conclusions.

Primary references and authorship

Sources read 21 November 2026. Original explanation, measurements and synthetic examples by Sandeep Belgavi. Views are my own and do not represent any employer, past or present.

Related on this site: