Overview
LLMManager owns the language-model plumbing of an Agent: building the LiteLLM instance from configuration, checking model capabilities, invoking the model across all streaming modes, and turning the raw stream into reasoning, content and tool-call parts. Fallback between models is not here: Agent.run walks fallback_models itself (see Model fallback).
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.
The llm the agent builds from the manager is stored on the agent, so agent.llm, serialization, and save() / load() all work against it.
The owning
Agent. Read for configuration. build() sets agent.model_name to gpt-5.4 when it is None.Model fallback
Fallback runs in one flat loop inAgent.run, not in the manager. Configure it on the agent:
- Retries belong to the client.
retry_attemptsis passed toLiteLLMasretriesand sent with every request as litellm’snum_retries, so one model gets at mostretry_attempts + 1calls. - The first entry of
fallback_modelsis the primary, andagent.model_nameis set to it.fallback_model_nameis folded intofallback_models(as[model_name, fallback_model_name]) at construction. - Only an
AgentLLMErrormoves to the next model.Agent.call_llmwraps any error fromcall()inAgentLLMError, chained to the provider’s error as__cause__. Any other exception, such as a bug in a tool, raises at once. After the last model fails, theAgentLLMErrorreaches the caller. - Every run starts from the primary model again, rebuilding
agent.llmwithllm_handling()whenever the model changes.
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.retries, from the agent’sretry_attempts.stop, set to[agent.stopping_token]when the agent has astopping_token, so the provider stops generating there.llm_argscan override it.
agent.tool_manager.defer_mcp_tools()). Otherwise they are fetched with agent.tool_manager.add_mcp_tools_to_memory() and sent with every request.
A single dict is merged directly into the configuration; anything else is stored under
additional_args.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
stream_parts, so reasoning and tool calls stream along with the content.
- Non-streaming
- Panel streaming
- Detailed streaming
Direct
llm.run() returning the complete string. Used when stream and streaming_on are off and no streaming_callback is given.Agent.llm_call telemetry span that records the request, the response and the tokens used.
Receives
token_info dicts in detailed streaming, and the text of every streamed part in panel streaming.is_last is stripped from kwargs before dispatch.
Any provider error propagates. litellm has already retried it retry_attempts times; Agent.call_llm then wraps it in AgentLLMError, which moves Agent.run to the next model in fallback_models. See Model fallback.
run_side_call
call() would when the agent streams. streaming_callback defaults to the callback of the run in progress, then to the agent’s streaming_callback. Returns the model’s reply.
Stream plumbing
stream_parts
(kind, text, chunk) tuples where kind is "reasoning", "content" or "tool_call".
- Content passes through unchanged and is appended to
content_out; joined, it is the reply text. - Reasoning starts with a
[thinking]header. - Each tool call starts with a
[tool call] <name>header, followed by a space and its argument fragments.
tool_calls_out is filled with the assembled tool calls once the stream ends. In max_loops="auto" almost every turn is a tool call, so a callback sees the whole autonomous run:
token_info["type"].
stream_with_tool_collection
delta.tool_calls deltas into a complete tool-call list, which fills tool_calls_out once the stream is consumed. stream_parts reads through it.
extract_thinking_from_stream
print_on is set, and yield only content chunks onward. The streaming modes of call() no longer use it; they stream reasoning through stream_parts instead. It remains available through Agent._extract_thinking_from_stream.
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