Overview
LLMManager owns everything an Agent does with a language model: building the LiteLLM instance from configuration, rotating through fallback models when one fails, checking model capabilities, invoking the model across all streaming modes, and re-running a failed task down the fallback chain.
Every Agent builds one automatically as agent.llm_manager. You rarely construct it yourself — but it is where the behavior lives, and the agent’s LLM methods are thin wrappers over it.
Import
Design
Unlike the agent’s other collaborators,LLMManager holds a reference back to its owning agent and reads configuration live rather than snapshotting it.
That is deliberate. Agents mutate their own LLM configuration at run time: system_prompt grows when skills load, tools_list_dictionary changes when tools are registered, streaming_on is toggled per call by run_stream. A snapshot taken at construction would silently go stale.
Anything the manager writes — model_name, current_model_index, llm — is written back to the agent, so agent.llm, serialization, and save() / load() all behave exactly as before.
Any
required
The owning
Agent. Read for configuration; written to for model_name, current_model_index, and llm.Model selection and fallback
Configure fallbacks on the agent, and the manager handles rotation.get_available_models
fallback_models when set, otherwise from model_name plus fallback_model_name (de-duplicated).
get_current_model
gpt-5.4, if the index runs out of range.
switch_to_next_model
agent.model_name, and rebuild agent.llm against it. Returns False when the list is exhausted. Model switches are always logged.
reset_model_index
is_fallback_available
True when more than one model is configured.
Construction
build
LiteLLM instance from every configuration source: the agent’s core settings, llm_args, tools_list_dictionary, MCP tool schemas, and anything passed here.
Any
A single dict is merged directly into the configuration; anything else is stored under
additional_args.Any
Merged into the LiteLLM configuration, taking precedence over defaults.
None if initialization raised AgentLLMInitializationError. parallel_tool_calls is enabled automatically when the agent has two or more tools or any MCP server configured.
get_parameters
check_model_supports_utilities
randomize_temperature
[0.0, 1.0]. Used between loops when dynamic_temperature_enabled is set; falls back to 0.5 when the LLM exposes no temperature.
Invocation
call
- Non-streaming
- Panel streaming
- Detailed streaming
Direct
llm.run() returning the complete string. Used when neither stream nor streaming_on is set.str
required
The prompt to send.
str
Image input for multimodal models — file path, URL, data URI, or raw base64.
int
default:"0"
Loop iteration, used in streaming panel titles.
Callable[[str], None]
Receives
token_info dicts in detailed streaming, token strings in panel streaming.is_last is stripped from kwargs before dispatch.
Stream plumbing
stream_with_tool_collection forwards every chunk unchanged while assembling fragmented delta.tool_calls deltas into a complete tool-call list. extract_thinking_from_stream swallows reasoning chunks from models that emit them, flushes them to a thinking panel, and yields only content chunks onward.
Fallback execution
handle_fallback_execution
None is returned.
Agent-level wrappers
Each of these delegates straight to the manager and remains the supported public API:Related
Agent
The class that owns the manager
Model Providers
Supported models and provider configuration