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: 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.
Agent Skills are not part of system_prompt. Agent.call_llm adds the selected skills to each request before it delegates to call(). See SkillsManager.
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.
The core settings include:
temperaturefrom the agent. It defaults toNone, andLiteLLMleaves it out of the request when unset, so models that reject any temperature value, such as some Claude models, work without extra configuration.usage_hook, set to the agent’s own usage counter. Token totals live on the agent, so they survive a rebuild after a fallback switch. See Token usage.base_urlandapi_key, from the agent’sllm_base_urlandllm_api_key.
agent.tool_manager.defer_mcp_tools()). Otherwise they are fetched with agent.tool_manager.add_mcp_tools_to_memory() and sent with every request.
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.
List[str]
Multiple image inputs for multimodal models, same accepted forms as
img.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.
Any provider error is logged and re-raised. The agent’s standard loop (Agent._run) retries the call up to retry_attempts times. After the last failure it raises AgentLLMError, which hands the task to the fallback chain below.
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
Agent.run calls it when a run fails and more than one model is configured.
When every model is exhausted, the original error goes to the agent’s error handler, which logs it (and saves state when autosave is on) and re-raises it to the caller.
Agent-level wrappers
Each of these delegates to the manager and remains the supported public API:Related
Agent
The class that owns the manager
Model Providers
Supported models and provider configuration