0212. Model tool calls and usage categories through the runner
- Status: Proposed (pending owner confirmation)
- Date: 2026-11-09
- Plan: M14.1
- Amends: 0108, 0112, and the Step 24 addendum of 0121
Context
ModelReply carried text, a terminal and folded
token counts; calls lived on AnthropicResponse, so
AnthropicReplay.call_model failed closed on calls.
ToolResult lacked provider IDs, and usage lacked
categories and reasoning. ADR-0121's Step 24 addendum avoided
breaking reply fields; M14.1 needs them.
Decision
- Complete, validated tool calls with provider IDs travel on
ModelReply.calls(ToolCall.id,name,arguments). The runner queues oneEvent.ModelToolCalls(task, calls)per reply, after its deltas and beforeModelDone, so an agent sees a parallel batch at once. OnlyCompletedreplies keep calls; every other terminal drops them. - The runner re-validates calls whatever port produced them: an
empty ID or name, arguments that are not a valid JSON object, or a
duplicate ID in one reply turns the reply into
Failed(Provider(..))with no calls. A captured secret in any call field fails the whole reply rather than redacting JSON. Event.ToolResult(task, id, outcome)echoes the dispatchedToolCall.id, including registry rejections; agent-made calls use"".ModelReply.usage: TokenUsagereports five categories: uncached input, cached input (cache read), cache write, reasoning and output. Reasoning is a subset of output and is reported only. Cache read and write are disjoint from input. An absent category isnone, never zero. Run-level totals travel as the last field ofRunEnd(Finished/Idle/Unsupported), summing every attempt of that invocation, folded fromDriverState.attemptseven without a workspace host; no inline accumulator lives onRunStateorDriverState. A no-attempt run constructszero_usage()once at the return seam.TokenTotals.usagestill sums an owner's settled attempts. Zero-usage tool attempts need history only for workspace settlement; without a host they are omitted, preserving bounded tool-only loops and model totals.run_tools_loopmust remain a single-root (var state = initial)DriverEndloop for transition-arena reclamation.- Budgets keep folding cache into input through
token_budget_usage, so reservations, hard limits, unknown-usage counting (ADR-0110) andBudgetSettledjournal bytes are unchanged. AnthropicReplayand the curl path returnModelReplywith calls;AnthropicResponseandreplay_responseare removed. Anthropic reports reasoning as unknown because it does not split thinking out of output.
Amends 0108: incomplete arguments remain
unobservable at any runner port. Amends 0112:
calls are fixture-tested through run()
(anth-replay-e2e). Amends 0121 (Step
24): ModelPort stays immutable/reply-only;
fields change.
Alternatives considered
- A
Delta.ToolUseper call — splits a parallel batch across events and changes every single-armDeltamatch. - Keep the
AnthropicResponsecompanion API — two sources of truth and a fail-closed trap for text-only consumers. - Agents map ActionId to call ID themselves — agents never see action IDs.
- Keep folded
input_tokensbeside the categories — the two could drift. - Charge reasoning to the output budget — it is already part of output, so it would be counted twice.
- Store
TokenUsageinline onRunState— an 80-byte field is copied on every intermediatewith, including idle spawns that never call a model; that regressed density smoke to 29,403 B/agent over the 28,672 ceiling. An option or resident vector onRunStatestill burdens those copies. - Raise the density ceiling — would mask the regression; the 28,672 proxy remains the gate (ADR-0122).
Consequences
- An ABI break for every agent in this repo and the external
coding-harnessapp (in-repo agents update together; the app needs a follow-up). BudgetExceeded(ActionId, _)for a refused parallel call still cannot be paired with its call ID; recorded as an open question, unchanged here.- Anthropic runs report reasoning as unknown until a provider exposes it.
- With reclamation restored, the 100,000-step arena golden is refreshed to allocated=182989068, copied=29388998, peak=4576; the 32M limit is unchanged.
- The earlier 23,222 B/agent density result disabled transition
arenas and is not comparable to main's 28,349. Restoring
reclamation measured 29,141; exact singleton queues avoid spare
Event-union slots and reduce it to 27,893 against the unchanged
28,672 ceiling.
coding-harnessmust also match the newRunEndarity.