Keep the deterministic straight-through path and put the agent in the exception queue. A synthetic shift compares backlog and unreviewed errors per design.
The pattern that already works
Most record-processing systems already have the shape an agent needs. A pipeline takes in orders, returns, invoices or address changes, runs them through deterministic rules, and passes the clean ones straight through. Records that fail a rule land in an exception queue, where a person looks at them, fixes what is wrong and sends them back. Integration people call this straight-through processing with exception handling. It has lasted because it puts expensive judgement only where the rules give up.
When teams add an agent, the tempting design is to route every record through it, so the agent "understands" each one and the rules can retire. This guide argues for the opposite. Keep the straight-through path deterministic and unchanged. Put the agent in the exception queue, where its job is to propose a fix for a record a rule rejected. Then decide, per exception type, whether a person approves the proposal or a confidence rule lets it apply. The agent replaces the slowest part of the current process, which is a person working out the fix from scratch. It keeps established deterministic checks on the routine path; their own correctness and latency still need testing.
The running example is the returns desk of Belgavi's Book Store. Return requests arrive at 2,000 an hour on a busy day. Rules check the order number, the purchase date against the return window, whether the item is returnable and whether the refund amount matches the line. About 4 percent of requests fail a rule: a typo in the order number, a gift purchase with no receipt, a partial refund on a bundle. Tanishka runs the exceptions team with three reviewers. The companion lab and the example agent_exception_queue model the hour-by-hour queue and are the source of every number below.
Worked example: eight hours on the returns desk
Each reviewer takes 6 minutes to work out an exception from scratch and 2 minutes to check a proposed fix. The agent is confident on 60 percent of the exceptions it sees, and in this synthetic setup 5 percent of its confident fixes are wrong. These rates are inputs, not measurements of any model. Over an 8-hour shift the four designs look like this.
| Design | Agent calls | Applied without review | Wrong and unreviewed | Backlog at end | Hours to clear |
|---|---|---|---|---|---|
| People handle every exception | 0 | 0 | 0 | 400 | 14 |
| Agent proposes, people approve | 640 | 0 | 0 | 0 | 0 |
| Agent applies confident fixes | 640 | 384 | 16 | 0 | 0 |
| Every record goes to the agent | 16,000 | 9,600 | 480 | 5,680 | 64 |
Without help, three reviewers can clear 30 cases an hour against 80 arriving, so the backlog grows by 50 an hour and ends the shift at 400. With the agent proposing fixes, review drops to 2 minutes, capacity rises to 90 an hour, and the queue never forms. The agent is called 640 times, once per exception. Letting the agent apply its confident fixes removes another 48 reviews an hour but writes 16 wrong changes into the ledger with nobody looking. The toy model rounds down errors separately in each hour: floor(48 times 0.05) is 2, giving 16 over eight hours. Without that rounding, the expected count would be 19.2. These discrete illustrative counts are not a measured error forecast.
The last row is the "agent understands everything" design. The rules no longer gate anything, so the agent sees all 16,000 requests. Even with the same 60 percent confidence, 800 requests an hour need review, the backlog reaches 5,680, and 480 wrong changes go through unreviewed. The 15,360 requests that the rules would have passed unchanged now each cost a model call and carry a model error rate. Nothing about the clean requests needed judgement.
What stays deterministic
Three things should not move into the agent.
- The rules themselves. A rule that rejects a return outside the 30-day window is a policy decision with a known owner. If it moves into a prompt, the policy becomes a probability and loses its audit trail.
- The routing decision. Which records go to the exception queue, and which exception types allow auto-apply, belongs in configuration that a person changes on purpose. The agent can ask for a type to be added. It cannot route records to itself.
- The final write. A proposed fix is a structured change: the record id, the field, the old value, the new value and a reason. The same validator that the straight-through path uses checks it before it applies. A fix that fails validation goes back to the queue, not into the ledger.
The agent owns one step: reading the rejected record, the rule that rejected it and any related records, then producing that structured proposal.
from dataclasses import dataclass
@dataclass(frozen=True)
class Proposal:
record_id: str
field: str
old: str
new: str
reason: str
confidence: float
AUTO_APPLY = {"order_number_typo"} # exception types a person has signed off for auto-apply
def route(exception_type: str, proposal: Proposal, validate, apply, enqueue_review) -> str:
if not validate(proposal): # same validator as the straight-through path
enqueue_review(proposal, "failed validation")
return "review"
if exception_type in AUTO_APPLY and proposal.confidence >= 0.9:
apply(proposal)
return "applied"
enqueue_review(proposal, "needs approval")
return "review"Migration steps for an existing pipeline
- Instrument the exception queue before adding anything. Record arrivals per hour by exception type, time to resolution, and what the person changed. That history becomes the evaluation set.
- Run the agent in shadow on the queue. It writes proposals to a side table, and the reviewer works as before. Compare proposals with what the reviewer actually did, per exception type.
- Show proposals to reviewers, with the diff, the evidence the agent read and an approve button. Measure review time against scratch time. This is where most of the capacity gain comes from, and it needs no auto-apply at all.
- Allow auto-apply only for exception types with enough history and an agreement rate the business accepts, with a daily sample audited by a person. Keep the list of auto-apply types in configuration.
- Never remove a rule because the agent "would catch it anyway". If a rule is wrong, fix the rule. If an exception type keeps recurring, ask whether a new deterministic rule could handle it before the queue.
Failure modes to design for
Reject-rate spikes. A supplier changes its order-number format and the rules reject 12 percent of requests instead of 4. In the model, even with proposals, three reviewers fall behind by 150 an hour and finish the shift 1,200 cases behind. The answer is an alert on the exception rate per type, which is often a rule that needs updating, not a reason to widen auto-apply.
Auto-apply creep. Raising the confident share to 100 percent clears the queue and doubles the unreviewed wrong changes, to 32 a shift. A clear queue is not evidence of correct changes. Watch the audited error rate, not the backlog.
Proposals that drift from the validator. If the agent can write fields the validator does not check, auto-apply bypasses the controls the straight-through path enforces. Validate proposals with the same code, and reject proposals that touch fields outside the exception type's allowed set.
Feedback loops. If reviewers approve proposals without reading them, approval rates rise and look like a better agent. Sample approved proposals for a second review and track how often the sample disagrees.
When an agent is unnecessary
If the exceptions are few, a person handles them faster than any integration you would build. If one exception type dominates and the fix is mechanical, such as reformatting a field, write a rule. An agent earns its place when exceptions are varied, each needs some reading across related records, and reviewers spend most of their time working out what happened rather than typing the fix.
How to verify it
Replay a week of historical exceptions through the agent in shadow mode and report agreement per exception type, not one overall number. Check that every clean record in the same week still takes the straight-through path with no model call: the count of agent calls should equal the count of exceptions. In production, alert on three things: the exception rate per type, the review backlog, and the audited error rate of auto-applied changes. The companion lab lets you move the reject rate, confidence, error rate and reviewer capacity and watch which of the three moves first.
Interactive experiment
Agent exception queue: routing, confidence and reviewer capacity. Synthetic browser-local fixtures, adjustable inputs, decision traces and JSON export.