/p/2026-07-10 · explainer
Paper explainer · 2607.08010 · Kujanpää et al.

Solve the routine once,
then call a tool — stop rewriting the code.

Production agents burn latency and reliability re-solving the same routine on every request, regenerating query code for steps that never change. This system compiles each repeated step into a validated, versioned tool the agent calls directly — falling back to writing code only for genuinely new steps. In a live fulfilment-centre alarm-triage system that cut median latency 42% and end-to-end errors up to 53%, and a simpler direct-call design cut latency a further 62%.

01 · The problem

The agent re-solves the same step on every single request

A production triage agent follows a fixed standard-operating-procedure: a decision tree of 44 decision nodes and 19 action nodes. Decision nodes come in three kinds — observations (test a metric against a threshold), root causes (name the failure), and constraints (gate an expensive action, e.g. “is the collector belt empty enough to justify a staffing change?”). Most of these steps are identical from one alarm to the next.

The common pattern still handles them with a code-writing sub-agent: for every alarm it generates fresh query code, executes it against the tool/data environment, reads the result, and reasons to a verdict — again for the next alarm, and the next. That costs latency, and because the code is regenerated each time it also varies run-to-run: a datatype it silently coerces today it might mishandle tomorrow. The waste shows up plainly in the token bill.

Interactive · output tokens per alarmQwen3 32B · 1,500 historical alarms
total output tokens
14,998
every step re-planned and re-coded in the output stream
sub-agent code-gen tokens
7,452
query code written from scratch each time

Flip to tools and the sub-agent stops writing query code for steps that already have one: total output tokens fall 58% (14,998 → 6,225) and its code-generation tokens fall 80% (7,452 → 1,466). Same alarms, same answers — just no re-solving.

02 · The mechanism

An offline pipeline compiles each SOP step into one validated tool

The fix moves the coding loop out of the request path and into a build step. Before deployment, a three-stage tool-maker turns each SOP node into a single tool with a fixed signature — (warehouse, timestamp, context) in, a structured verdict out: (verdict, observed value, threshold, explanation). Step through it on one node — the belt-empty constraint that gates a costly staffing change.

Interactive · the tool-maker pipelinecollect → generate → test-repair · one SOP node

At runtime the production agent simply calls the deployed tool. If a tool is missing or throws, it falls back to the original code-writing sub-agent — the same one used to collect data in stage 1 — so nothing is ever worse than the baseline.

03 · The payoff

Compact tool verdicts let you delete a whole agent layer

Slotting the tools into the existing sub-agent already cuts latency. But because a tool returns a compact structured verdict instead of a wall of code and raw data, the sub-agent layer stops earning its keep — the main agent can call tools directly. Each step down simplifies the architecture. Pick an architecture and watch p50/p99 latency and the error rate move together.

Interactive · architecture comparisonlatency index (baseline=100) · error on 1,500 alarms, GLM-4.5-Air
p50 latency index — all three, for comparison
writes code
100
calls tools
58
direct calls
26
p99 latency index — baseline
p99
100
100p50 index
100p99 index
1.7%error rate

Latency indices are model-agnostic (baseline = 100). Error rates are end-to-end on 1,500 historical alarms with GLM-4.5-Air; Qwen3 32B shows the same direction (2.8% → 1.8% for the first two arms).

04 · Quality & auditability

Both build stages earn their place — and the tools surface broken specs

A tool is only worth calling if it is correct. Two stages carry that: giving the tool-maker the data-collector’s execution trace, and running the test-repair loop. Ablate each and watch per-node Pass@1 (best model, GLM-4.7). Neither alone reaches the deployed number.

Interactive · trace + repair ablationtool-generation Pass@1 per SOP node
deployed
94.5%

Where the last errors live: the spec itself

With trace + repair, most residual failures traced to just 4 of the 44 nodes — where the human-written SOP text was ambiguous (unclear averaging windows, unstated edge cases). The tool-maker cannot invent the author’s intent, but it localised the ambiguity. Clarifying only those four nodes’ wording closed almost all the gap.

Interactive · clarify the 4 ambiguous nodesPass@1 across all 44 nodes
Pass@1
94.5%

Deployed tools reach 94.5%. The residual isn’t a model limit — it’s spec ambiguity the tool-maker pinned to four nodes.

Versioned tools expose problems fresh code hides

Regenerated code silently adapts to whatever it sees — which means real environment changes disappear into run-to-run variance. A tool has stable, reproducible inputs and outputs, so the same drift becomes a visible, pinpointed signal. Three real production issues surfaced this way:

Interactive · issues caught in productionbyproduct of stable, versioned tools
The numbers

What it bought, in the deployed system

−42%
p50 latency, sub-agent calls tools
Tools slotted into the existing sub-agent: p50 index 100 → 58, p99 100 → 59. Same architecture, fewer regenerated tokens.
a further −62%
main-agent direct calls
Compact tool verdicts let the sub-agent layer be removed; the main agent calls tools directly. p50 index falls to 26 — about a quarter of baseline.
up to −53%
end-to-end error rate
GLM-4.5-Air on 1,500 historical alarms: 1.7% → 0.8% error (98.3% → 99.2% accuracy). Qwen3 32B: 2.8% → 1.8%.
94.5%
tool Pass@1 per SOP node
Best model (GLM-4.7) with trace + repair. Clarifying four ambiguous nodes lifts it to 99.9%.
−58%
output tokens per alarm
Qwen3 32B: 14,998 → 6,225 total; the sub-agent’s code-generation share falls 80% (7,452 → 1,466).
5,000+
production alarms served
Since deployment on the outbound-dock triage system — a live system, not a lab study.
05 · Why you care

Any repeated step in your agent is a tool waiting to be compiled

If your agent re-runs the same procedural step across requests — “check inventory before confirming an order”, “look up the account tier”, “validate the shipping address” — you are paying to re-solve it every time, and inheriting whatever the model improvises that run. Flip the same step between regenerating code and calling a compiled tool. Illustrative walkthrough — the code is simulated; the paper’s measured effects are the direction, not these exact numbers.

Interactive · one repeated step, two waysstep: check inventory before confirming an order

How to try it on your own agent

Where it stops — stated honestly

This is validated on one application (outbound-dock alarm triage); generalisation to free-form runbooks or other domains isn’t established. The loop still retains human oversight — it doesn’t yet guarantee every failure is caught without review of newly generated or repaired tools, and clarifying an underspecified SOP is inherently a human task, since the spec encodes the author’s intent. Tool creation still benefits from labelled cases: a label-free variant trails the labelled ceiling by ~3 points (91.6% vs 94.5%). What is real: the tools have run across 5,000+ production alarms since deployment.

In practice

Cache the routine, not the reasoning

When you catch the agent re-deriving the same multi-step routine on every request, compile that routine into a validated, versioned tool it calls directly — and fall back to generating code only for genuinely new steps. In the paper's alarm-triage system that cut p50 latency 42% and errors up to 53%.