Skip to main content

Module effort_routing

Module effort_routing 

Source
Expand description

Per-turn effort routing (#1148, opt-in dynamic thinking budget).

Unlike the static effort.rs which applies a constant reasoning level across all turns (for cache stability), this module classifies each turn and adjusts thinking effort dynamically.

Opt-in only (proxy.effort_routing = true). When disabled, the static effort.rs path remains the sole controller. When enabled, this module overrides the static level with a per-turn classification.

§Cache stability tradeoff

Provider prompt caches (Anthropic cache_control, OpenAI prefix caching) break when reasoning parameters change. This module accepts that tradeoff because:

  1. Output tokens on Opus-class models cost 5x input tokens — savings from reduced thinking often exceed the cache-miss penalty.
  2. Routine turns (file reads, passing tests) generate disproportionate thinking waste for trivial tool-result acknowledgements.
  3. The module uses a two-level strategy (not N levels) to minimize cache key diversity: routine or full — only two cache prefixes to warm.

§Classification

A turn is classified as routine when the last assistant message was a tool call and the tool result indicates success on a non-complex operation:

  • File read (tool_use with ctx_read, read_file, Read)
  • Successful shell command (exit_code == 0, no error indicators)
  • Search results (grep/glob/find)
  • Status checks (git status, test passing)

A turn is classified as full (keep maximum thinking) when:

  • The user sent a new message (requires understanding intent)
  • The tool result contains errors/failures
  • Multiple tool results arrived (complex multi-step)
  • The content is architecturally complex (refactoring, debugging)

Structs§

RoutingStats
Statistics for monitoring effort routing effectiveness.

Enums§

TurnClass
Turn classification result.

Functions§

classify_turn
Classify the current turn based on the message array. Returns Routine if the latest context is a simple tool-result acknowledgement, Full otherwise.
classify_turn_anthropic
Classify based on Anthropic messages structure.
classify_turn_responses
Classify based on OpenAI Responses API input array (different structure).
effort_for_turn
Map a turn classification to the effort level to apply. base is the operator’s configured static effort level.
intent_aware_effort
Adjust effort from a classifier intent while preserving the configured effort for intents that are not clearly simple reads or coding work.
stats
Snapshot routing statistics.