`src/engine/bare/llm_turn.rs` — one model call
Request construction and the two turn paths.
Key items
build_turn_request(transient)— extras first, thenmachine.full_history(); system prompt; tool schemas (Nonewhen the registry is empty).turn_request_options()— yourrequest_options+ the fallbackrouted_model()override (which wins over your model field when routing is active).do_turn— the cancel guard, thendo_create_message(biased select vs cancel + turn timeout) ordo_stream(through theStreamHandler;AttemptResetwipes the accumulator;Fallbackadopted wholesale).routed_model()/routed_or_client_model()— which model serves this turn.record_turn_success/record_turn_failure— the fallback-breaker glue (rate-limit escalations count as RateLimit; trips fireon_fallback; chain advance on failed fallbacks).
Behavior notes
- The user’s input reaches the model only via the scratchpad —
turn_inputis for memory retrieval and observers, never the request. - Overhead (system + schemas) is measured once with the configured counter;
response_formatturns suppress tools so their estimate over-reserves — conservative by design. - Detection feeds only on terminal replies (no tool calls).
Deep dive: The LLM turn.