A circuit breaker is one of the oldest tricks in reliability engineering: when a dependency is failing, stop calling it, fail fast, and probe until it recovers. Every agent framework I’ve looked at either ships one or tells you to put one in front of your tools.
Almost all of them define “failing” the way an HTTP client does: a 5xx, a timeout, a connection reset. That’s the right definition for a service calling a service. It’s the wrong definition for an agent, because the tool failures that hurt an agent most usually arrive with a 200 OK.
The failure a status code can’t see
Think about what a degraded dependency actually returns:
- A search tool whose index is rebuilding returns
[]. The agent concludes there are no matching incidents. - An inventory API on a stale read replica returns last week’s host list. The agent restarts a host that was decommissioned.
- A pricing service on its fallback path returns a default. The agent’s cost estimate is off by an order of magnitude.
None of these are errors at the transport layer. A human engineer would squint at an empty result and think “that’s odd”. An agent mostly takes it at face value and plans around it, which is the same mechanism behind prompt injection: the agent believes the text in front of it.
So the question for an agent’s breaker is not “did the call succeed?” but “is the result usable?”.
The simulation
I built a small, seeded simulation to put numbers on the difference. The tool and the agent are invented. The numbers describe how the two breaker designs behave, not how any real service fails. The script is at the end.
- 4,000 tool calls. Healthy for the first 2,000, with a 0.2% background 5xx rate.
- At call 2,000 the dependency degrades silently. 35% of calls now return
200with a bad payload. The 5xx rate doesn’t change. - Both breakers use the same rolling window of 50 calls, trip when 20% of the window has failed, and stay open for 200 calls before letting traffic through again.
- The status-code breaker counts only 5xx as a failure.
- The semantic breaker also counts a payload that fails validation. The validator is imperfect on purpose: it misses 10% of bad payloads and wrongly flags 1% of good ones.
Both designs see identical random draws, so the only difference is what the breaker counts.
Results
| Breaker | Trips | Calls to first trip after degradation | Bad results the agent consumed |
|---|---|---|---|
| Status-code | 0 | never | 702 |
| Semantic | 8 | 25 | 16 |
The status-code breaker never noticed. As far as it could tell, the dependency was as healthy at call 4,000 as at call 1. The agent consumed 702 bad results, and each one is a chance for a wrong plan, a wrong action, or a confident wrong answer.
The semantic breaker tripped 25 calls into the degradation and spent most of the rest of the run open: each time its 200-call cooldown ended, it let traffic through, refilled its window, and tripped again. Sixteen bad results got past it, all of them payloads its validator missed while the breaker was closed. That’s not zero, but it’s a 44× reduction from a check that costs a few lines of code.
The validator is now part of your availability
The catch is that the validator’s mistakes are now breaker inputs. A validator that flags good payloads will open the breaker on a healthy dependency, and an open breaker is an outage for every agent that needs that tool.
I reran the healthy half of the simulation across 20 seeds while turning up the validator’s false-positive rate:
| Validator false-positive rate | False trips while healthy (20 runs) |
|---|---|
| 1% | 0 |
| 5% | 0 |
| 10% | 43 |
| 15% | 128 |
The cliff is sharp. With a 20% trip threshold over 50 calls, a validator that’s wrong 5% of the time almost never fills a window. At 10%, ordinary binomial noise fills windows often enough to trip dozens of times. The rule that falls out of it: measure the validator’s false-positive rate on known-good traffic, and keep it at a quarter of the trip threshold or less. If you can’t get it that low, raise the threshold or widen the window, and accept slower detection.
What to validate
You don’t need an LLM judge for this. The checks that catch most silent degradation are boring:
- Schema. Required fields present, types right. Structured outputs guarantee the shape of what the model emits; you need the same guarantee for what your tools return to it.
- Emptiness where emptiness is suspicious. A host inventory with zero hosts, or a search with zero hits for a query that returned hundreds yesterday.
- Freshness. A
generated_atoras_oftimestamp older than the tool’s contract allows. - Range and invariants. Negative counts, percentages above 100, a total that doesn’t match its parts.
- Fallback markers. If the dependency tells you it served a default or a cached response, treat that as degraded for decisions that act on the world, even if it’s fine for decisions that only read.
Keep the checks deterministic and fast. The validator runs on every call; it has to be cheaper than the tool.
Where it goes
Put the semantic breaker at the tool gateway, not inside the agent’s prompt. “If the result looks wrong, don’t use it” is an instruction the model may or may not follow on a given turn. A breaker is a mechanism that runs whether the model remembers it or not, which is the same argument as for hooks over instructions.
When the breaker is open, return a structured error the agent can reason about (tool_unavailable: inventory, reason: validation_failure_rate, retry_after: 120s) instead of the bad payload. An agent that knows a tool is down can escalate or wait. An agent that got a plausible wrong answer can’t.
The script
Standard library only. Seeded, so you get exactly the numbers above. Save as semantic_breaker.py and run it with python3.
"""Status-code breaker vs semantic breaker on an agent tool that degrades silently.
Synthetic, seeded, stdlib only. The tool and the agent are invented; the point is
how the two breaker designs behave, not how any real service fails.
"""
import random
SEED = 7
CALLS = 4000 # tool calls over the run
DEGRADE_AT = 2000 # dependency starts degrading here
BAD_RATE = 0.35 # after DEGRADE_AT: share of calls returning 200 + bad payload
HARD_ERR_RATE = 0.002 # background 5xx rate, healthy or not
VALIDATOR_FP = 0.01 # validator wrongly flags a good payload
VALIDATOR_FN = 0.10 # validator misses a bad payload
WINDOW = 50 # rolling window of calls the breaker looks at
TRIP_AT = 0.20 # trip when failure share in window >= this
COOLDOWN = 200 # calls skipped while open, then one probe
def simulate(semantic: bool, seed: int = SEED):
rng = random.Random(seed)
window, open_until = [], -1
consumed_bad = trips = false_trips = skipped = 0
first_trip = None
for i in range(CALLS):
degraded = i >= DEGRADE_AT
# Draw the outcome the same way for both designs, so only the breaker differs.
r_hard, r_bad, r_val = rng.random(), rng.random(), rng.random()
if i < open_until:
skipped += 1
continue
hard = r_hard < HARD_ERR_RATE
bad = (not hard) and degraded and r_bad < BAD_RATE
if semantic:
flagged = (bad and r_val >= VALIDATOR_FN) or (not bad and not hard and r_val < VALIDATOR_FP)
failure = hard or flagged
if bad and not flagged:
consumed_bad += 1 # slipped past the validator
else:
failure = hard
if bad:
consumed_bad += 1 # 200 OK, so the agent uses it
window.append(failure)
if len(window) > WINDOW:
window.pop(0)
if len(window) == WINDOW and sum(window) / WINDOW >= TRIP_AT:
trips += 1
if not degraded:
false_trips += 1
if first_trip is None and degraded:
first_trip = i - DEGRADE_AT
open_until = i + COOLDOWN
window = []
return dict(consumed_bad=consumed_bad, trips=trips, false_trips=false_trips,
calls_to_first_trip=first_trip, skipped=skipped)
if __name__ == "__main__":
for name, sem in (("status-code breaker", False), ("semantic breaker", True)):
print(f"{name:20s}", simulate(sem))
# Sensitivity: validator false-positive rate vs false trips while healthy
print("\nvalidator FP rate -> false trips in the healthy half (20 seeds)")
for fp in (0.01, 0.05, 0.10, 0.15):
VALIDATOR_FP = fp
ft = sum(simulate(True, s)["false_trips"] for s in range(20))
print(f" FP {fp:.2f}: {ft} false trips across 20 runs")
Full output:
status-code breaker {'consumed_bad': 702, 'trips': 0, 'false_trips': 0, 'calls_to_first_trip': None, 'skipped': 0}
semantic breaker {'consumed_bad': 16, 'trips': 8, 'false_trips': 0, 'calls_to_first_trip': 25, 'skipped': 1592}
validator FP rate -> false trips in the healthy half (20 seeds)
FP 0.01: 0 false trips across 20 runs
FP 0.05: 0 false trips across 20 runs
FP 0.10: 43 false trips across 20 runs
FP 0.15: 128 false trips across 20 runs
Limits
- Synthetic dependency. Real degradation is rarely a clean step from 0% to 35%. A slow ramp is harder to catch, and the window and threshold you choose decide how early you see it.
- The validator is modeled, not built. Its 10% miss rate and 1% false-positive rate are assumptions. Your real rates depend on your checks and your data, and you have to measure them.
- Some bad payloads can’t be validated. A plausible, well-formed, wrong answer passes every structural check. A breaker shrinks the problem; it doesn’t remove the need for outcome checks on what the agent did with the result.
- Open breakers have a cost. Sixteen hundred calls were skipped while the semantic breaker was open. That’s correct behavior for a broken dependency, but it means the agent needs a defined fallback, not just an error.
For an agent, a tool that answers wrongly is down. Make your breaker agree.
Comments