Keeping LLM Agents on Procedure: Executable Finite-State Control for Long-Horizon Instruction Fidelity
TL;DR Highlight
Enforcing procedure with an FSM let Haiku 4.5 decide 139 of 200 accounts correctly and by procedure
Who Should Read
A backend developer whose unattended agent drifts into shortcuts when processing hundreds of cases under an SOP
Core Mechanics
- Prompts alone don't stop drift
- After a few dozen accounts, the agent cites its token budget and takes a shortcut.
- Restating the SOP just moves it to another shortcut.
- Drift moves between escape routes
- With only reminders, the agent stops early.
- With auto-resume added, it interleaves accounts and decides without looking at data.
- Keep state outside context and enforce at three points
- A tool-call gate admits only tools the current state permits.
- A transition guard checks conditions before advancing, and a stop gate blocks ending the turn early.
- You need all three points closed
- With only the stop gate, the agent decides without looking at data.
- With only the gates, it keeps trying to stop and burns its 50 resumes.
- Small models can carry long procedural work
- Haiku 4.5 with the FSM averaged more faithful decisions than plain Sonnet 4.6.
- It cost 38% as much as Sonnet.
- Little drift means little gain
- Where the agent already held the procedure, gains were small or absent and cost extra time and tokens.
- Measure plain-agent drift first to decide if enforcement pays.
Evidence
- Haiku 4.5 FSM beat the strongest baseline
- On 200-account SOP-Bench batches, FSM averaged 139.2 vs 48.4 for Remind-loop.
- The 8-seed difference is +90.9, 95% CI [46.2, 130.2].
- Haiku+FSM beat plain Sonnet 4.6
- On the same 3 seeds, FC was 134.3 vs 108.3 and cost $7.93 vs $20.94.
- It stayed 59.0 below Sonnet's best baseline.
- More SWE-bench Verified Hard-100 tasks resolved
- With Sonnet 4.6, resolved went from 62 to 69, and all 7 discordant tasks favored FSM (McNemar p=0.016).
- Easy-100 was 86 vs 87, with time +23% and cost $1.30 to $1.73.
- τ²-bench Telecom pass rate jumped
- With gpt-5.4-mini, pass went from 13/40 to 30/40 (p=1.5×10⁻⁵).
- Retail lost 15 to 9 due to over-strict guards.
How to Apply
- Add a completion check before the agent stops today
- Add a Stop hook to your batch agent that checks how many items remain.
- If items remain, block the stop and state the remaining count and the next target.
- Turn the procedure into a per-state tool allowlist
- List the tools allowed at each SOP step and reject other calls with a PreToolUse hook.
- Open the decision tool only after the investigation state completes.
- Guard on call order, not on answers
- Check from logs that all required data was fetched and no other item's data was interleaved.
- Keep decision logic out of guards, and note that without item-bound permissions a loophole remains.
- Measure plain-agent drift before adopting
- Run the same batch your usual way and measure procedure compliance.
- If compliance is high, stick with reminders; if low, adopt the FSM.
Try It
# Paste into Claude Code (simplified version of the paper's method: prompt-only, no hooks)
You are an agent that processes {{task description}}. You must follow this state machine.
State INVESTIGATE: pick exactly one item, retrieve all of {{required data sources}}, and record it. Do not retrieve data for any other item.
State DECIDE: submit a decision only for the item you just investigated. Then return to INVESTIGATE.
State DONE: enter only when every item has a decision.
Rules: start every reply with the current state and the remaining count. Never stop while the remaining count is not 0. Never batch items citing tokens or time.
Item list: {{item list}}
Next step: run this prompt and a version without the rules on the same 50 items and compare the number of procedure-compliant decisions.Terminology
Related Papers
LLM assisted reverse engineering
Pointing an agent at binaries with skills and MD notes made years-long hacks feasible
Metrics-in-the-Loop: Complexity Feedback Reshapes Agent-Written Code
Injecting per-turn complexity reports into coding agents cut code erosion without changing correctness
Why is Gemini 4 Carbon taking so long?
Carbon took nearly an hour on bug fixes that Astra and Opus finished in minutes, mostly from extra unrequested work.
How the Claude Code team thinks about verification
E2E, property and differential tests plus verification rules let Claude run in parallel.
Running coding agents without handing them my credentials
Credentials stay on the laptop; agents run commands there via Touch ID approval
Windows 11 Is Collecting Data on Which Coding Agents and Developer Tools You Use
Reverse engineering shows Windows 11 logs which coding agents you use and reports it as optional diagnostics
The Silent Cost of Conversation History in LLM Reasoning
Keeping full conversation history dropped accuracy from 0.6 to 0.1 within 20 turns; a verified state summary prevented it.
Anthropic upgrades Claude Code Projects to run parallel AI workers
Claude Code Projects now has a coordinator that splits work into parallel threads and opens PRs.
Original Abstract (Expand)
Much of the automation handed to language-model agents is procedural: each step needs little intelligence, but a long unattended run must follow a skill or SOP stated once at the start. We show that agents drift from such procedures over long runs, and that restating the instructions or resuming a stopped agent only moves the drift to another shortcut. We study an executable finite-state machine (FSM) that keeps the workflow state outside the model's context and enforces it at three points: tool calls, state transitions and the end of the agent's turn. In a pre-registered experiment on 200-account SOP-Bench batches, Claude Haiku 4.5 with the FSM decided on average 139 accounts correctly and by the procedure, against 48 for the strongest baseline (95% CI of the difference [46, 130]), and kept this rate to the end; across three models, the gain tracked how much the plain agent drifted. Because the runtime, not the model, supplies this long-horizon reliability, the FSM can let small models carry procedural work: Haiku 4.5 with it averaged more such decisions than plain Claude Sonnet 4.6 at 38% of the cost. Analyses on SWE-bench Verified, $τ^2$-bench, and staged and cross-context workflows further suggest that reliable long-horizon automation can come from stronger execution control, not only stronger models.