USER_MESSAGE = "Sell about $1,000 of ACME from my portfolio to rebalance." INTENDED_NOTIONAL_CENTS = 100_000 # $1,000 — what user meant BAD_QUANTITY = 1000 # shares — agent mistake (190× too large) SHARE_PRICE_CENTS = 19_000 # $190.00 per share MAX_ORDER_NOTIONAL_CENTS = 500_000 # $5,000 — the gated fix
quantity=1000 (shares) → ~$190k notional.@boundary("agent", kind="llm", extract_input=agent_input) def agent_plan(state: dict) -> dict: """Simulated LLM — treats '$1,000' as 1,000 shares.""" tool_call = ToolCall( name="place_order", arguments={"quantity": BAD_QUANTITY}, # 1000 shares, not $1,000 ) return {..., "tool_calls": [tool_call], "finish_reason": "tool_calls"}
@boundary records this LLM step as an envelope. Same code is stubbed during cut-point test.@boundary("place_order", kind="tool", extract_input=_order_input) def place_order(symbol: str, quantity: int, *, side: str = "sell") -> dict: notional_cents = quantity * SHARE_PRICE_CENTS if _mode == "gated" and notional_cents > MAX_ORDER_NOTIONAL_CENTS: return {"status": "blocked", "blocked": True, ...} return {"status": "filled", ...} # ungated: $190k goes through
set_mode("gated") activates the max-amount check.ungated → incident captured. Test: gated → $190k blocked (> $5k cap).scenario.set_mode("gated") session.load_trace("fixtures/traces/trade-notional/") session.enable_replay( ReplayPlan() .stub("agent", 1) .live("place_order", 1) # run gated tool live .live("agent", 2) ) result = scenario.run_agent()
place_order runs new gated code.$ python examples/financial_incidents/run.py trade record RECORD trade-notional User request Sell about $1,000 of ACME from my portfolio to rebalance. Node Kind Mode Input Output agent@1 llm LIVE Sell about $1,000... → place_order(quantity=1000) place_order@1 tool LIVE quantity=1000 filled: $190,000.00 total agent@2 llm LIVE tool_result: filled Done. Sold 1000 ACME... Trace exported fixtures/traces/trade-notional/
$ python examples/financial_incidents/run.py trade test TEST trade-notional (cut-point) Node Kind Mode Input Output agent@1 llm STUB Sell about $1,000... → place_order(quantity=1000) place_order@1 tool LIVE quantity=1000 blocked: exceeds maximum $5,000.00 agent@2 llm LIVE blocked... Order blocked — $190,000... [PASS] order blocked [PASS] no shares sold [PASS] agent@1 stubbed [PASS] place_order ran live