Cheap Router, Strong Writer
Most coding-agent turns are tool choices, not prose. A decision model picks the next step, one chat call writes the arguments, and classic ReAct takes over when either fails.
Why a ReAct loop pays frontier prices for yes/no decisions
In a ReAct loop, every model call is a bet. You pay for the strongest model available even when the next action is a boolean, an enum, or a decision to stop. A skill-building turn can run a dozen rounds — catalog reads, workspace diffs, test runs, edits — and only a few call for strong writing.
Swapping in a cheaper model everywhere is the obvious move. It breaks the moment an argument is a sentence or a note to the owner. That’s where output quality still matters.
The routing layer is middleware, not another orchestrator
We wrapped the agent’s wrapModelCall with buildDecisionWrapModelCall(policy, deps). We ask the cheap model a single next_action choice: which bound tool should run, or should we defer_to_agent_llm / end_agent_run? Those two built-in labels are constants (DEFER_ACTION, END_RUN_ACTION), and the question id is next_action.
graph LR
A["Turn starts"] --> B{"DecisionModel<br/>next_action choice"}
B -->|"bound tool"| C["classifyToolArguments()"]
B -->|"end_agent_run"| D["Command({ goto: END })<br/>no model call"]
B -->|"defer / failure"| E["Original handler (agent LLM)"]
C -->|"deterministic"| F["Zod-validated args"]
C -->|"enum / boolean"| G["DecisionModelArguments<br/>one batched call"]
C -->|"free text"| H["DecisionArgumentsExtraction<br/>structured chat call"]
F --> I["Tool executes"]
G --> I
H --> I
E --> I
I --> B
That question triggers three traced calls. First, we send only the tool names and their descriptions, plus the two built-in criteria — argument schemas stay withheld until a tool has been chosen. Step two answers the chosen tool’s arg_<name> boolean/enum questions in a single DecisionModelArguments call. Free text goes to a DecisionArgumentsExtraction call on a chat model.
We use the same engine for the root agent and the delegated skill editors, each with its own policy: different instructions, a different end criterion, and — for editors — no workspace finish guard. No separate orchestration server; it’s one middleware in the existing LangChain agent.
One turn, step by step
- 01
Intercept the model call
wrapModelCall receives the request before the strong model sees it. The policy is attached to the agent at build time, not hard-coded in any tool.
- 02
Ask one action question
chooseAction() sends one 'next_action' choice whose criteria map tool names to descriptions, plus defer and end. Full argument schemas are saved for step two.
- 03
Apply guards
If end_agent_run is chosen and the workspace is dirty, omitDecisionAction deletes that label, a one-line reason is appended, and the decision is re-asked.
- 04
Resolve arguments, then execute or fall back
Arguments come from context, a batched decision call, or structured extraction. Any unusable result returns the original handler — the loop keeps running inside the same traced turn.
Three argument shapes, three execution paths
classifyToolArguments looks at the chosen tool’s schema — after action selection, before any argument model call. A tool with no properties resolves in pure code; so does an argument that can be derived from context. If every property is a boolean or a non-empty enum, the decision model answers. Anything with free text goes to the chat model.
// decision-orchestrator.ts — resolveContextArguments()
function resolveContextArguments(
toolName: string,
context: DecisionArgumentContext,
): Record<string, unknown> | null {
if (
toolName === SkillBuilderToolName.READ_SALES_ASSISTANT_REVIEWED_CONVERSATION_CONTEXT &&
context.reviewedConversationId !== undefined
) {
return { conversationId: context.reviewedConversationId };
}
return null;
}
// No model call — but the result is still checked with tool.schema.safeParse().// decision-orchestrator.ts — buildArgumentQuestions()
const criteria = property.type === 'boolean'
? { true: 'Yes, enable this option', false: 'No, leave this option off' }
: Object.fromEntries((property.enum ?? []).map((value) => [String(value), String(value)]));
questions['arg_' + name] = {
type: 'choice',
instructions: 'Choose the value of ' + name + ' for tool ' + tool.name,
criteria,
};
// One argumentRun.invoke({ model, state, questions }) answers every arg_* question.// decision-orchestrator.ts — the only place free text is authored
const argumentsModel = await getArgumentsChatModel();
const structured = argumentsModel.withStructuredOutput(tool.schema, { name: tool.name });
const extracted = await structured.invoke(messages, {
signal: request.runtime.signal,
runName: DECISION_ARGS_LLM_RUN_NAME,
tags: [DECISION_MODEL_RUN_TAG, 'arguments', 'structured-output', INTERNAL_MODEL_CALL_TAG],
});
if (isJsonObject(extracted) && (!hasSafeParse(tool.schema) || tool.schema.safeParse(extracted).success)) {
return toolCall(tool.name, extracted);
}
return handler(request); // unusable arguments → classic ReAct fallbackThe Decisions client checks the provider response against a Zod schema and requires the primary answer to be a choice; probabilities come back sorted from highest to lowest. A refusal, a missing answer, or an unexpected type throws, and the middleware hands the turn back to the agent LLM. resolveArgumentAnswers returns null the same way when a value is unavailable or outside the enum.
- Every tool choice is a chat-model call
- Full context and tool schemas loaded for yes/no decisions
- Stopping the run is just another completion
- A bad answer is a single model failure
- DecisionModel picks one action from tool names + two built-ins
- arg_* enum/boolean questions batched into one Decisions call
- Free text uses one structured extraction, hidden from the timeline
- A dirty workspace removes end_agent_run from the choice set
Try the router
Change the step type, the strategy, and the workspace state. The trace shows what the orchestrator actually calls. The right pane is illustrative — token, cost, and latency numbers come from fixed constants, not measured billing data.
The design in four layers
The agent LLM handles everything
The classic ReAct handler is still the fallback and the defer path. It consumes the full context and tool schemas for every call it answers.
Cheap action classification
One Decisions API choice determines the next tool, defer, or end. Argument schemas are withheld at this stage, so the router's input stays small.
Argument routing
Three shapes: context-derived code, batched boolean/enum decisions, and a single structured chat extraction tagged so its raw JSON never reaches the chat timeline.
Fail-closed guards and live events
The finish guard, the tool-loop guard, and a live-only decision event stream address the two failure modes: dropped work and silent loops.
Trade-offs and failure modes
- One more credential to configure. The orchestrator’s decision model uses only a tenant BYOK OpenRouter credential; an unusable credential disables the middleware entirely rather than silently switching providers. The managed DECISION harness model (TRY_FOR_FREE,
inception/mercury-decide:free) belongs to a different feature — sales-assistant pre-run extraction. - Classification can be wrong, so it fails open. An unusable choice, an unknown tool, a missing definition, or an invalid argument set returns
handler(request). The finish guard is the deliberate exception: it fails closed, and a guard that throws is treated as “dirty work exists”. - The decision call is not retried. It emits a
decision_finishedwitherrorMessageand degrades to ReAct. The surrounding editor runs have their own retries — 3 model retries and 2 whole-run attempts with|retry-Ncheckpoint namespaces. - Debug events are live-only.
decision_started/decision_finishedshare a correlation id and never enter the persisted replay log; the finished event carries the choice, probability, confidence, sorted options, and served model.
Takeaways
Next, we look at why the event stream from this orchestrator needed its own protocol — LangGraph streamEvents Isn’t Your API: v3 Projection + Replay.
Share this article
Common questions
Does the decision model replace the chat model?
What happens when the decision call itself fails?
Is the router just a cheap general-purpose LLM?
How do you stop an agent from ending with uncommitted edits?
Related articles
Keep reading
A Guardrail That Edits the Action Space
Re-ask with end_agent_run removed and the reason stated. No louder prompt.
Read#02 · Decision models & orchestrationNot Every Tool Argument Needs the Same Model
Deterministic code, one decision call, or a chat model — chosen by argument shape.
Read#08 · The custom agent protocolLangGraph streamEvents Isn't Your API: v3 Projection + Replay
LangGraph v3 streamEvents is experimental and engine-shaped. We turn it into a typed protocol with Socket.IO rooms, replay, and retraction.
Read