`src/reflection/llm.rs` — the model-powered reflector
Asks the model to analyze its own tool failures — the first in-tree consumer of structured output. Opt-in; one model round-trip per analyzed failure.
Key items
LlmReflector::new(client)+with_system_prompt(...)— the built-in analyst prompt specifies the exactFailureAnalysisJSON shape and instructs the model to preferis_recoverable: falseover inventing corrections.analyze— builds one user message (Tool / Input / Schema / Error / Task / Attempt lines; schema omitted when unavailable; attempt rendered 1-indexed), callsrequest_structured::<FailureAnalysis>, validates.validate_modified_input[feature: schema_validation] — rejects anInputFixwhosemodified_inputfails the tool’s real schema before the retry; without the feature, corrections are trusted as-is.
Behavior notes
- Any reflector-side failure (
ReflectionError::Internal) becomes a conservativeFailin the engine. - The client is held as
Arc<dyn ApiClient>so the boxed future can reach it without borrowing. - Cost model: one model call per failure analysis — the reason it isn’t the default.
Deep dive: Reflection.