config=, or permanently swap it with switch_model(), all while keeping your conversation history intact.
config= or switch_model() changes the LLM without losing history.
Override vs Switch
Quick Start
Override model for a single call
gpt-4o-mini by default. Passing config={"model": "gpt-4o"} upgrades just that one call. The next call reverts to gpt-4o-mini.How It Works
Per-call config overrides are isolated to that single invocation and never mutate the agent’s defaults. This makes them safe for concurrent use — multiple threads can call the same agent with different models simultaneously.switch_model() updates agent.llm and recreates the internal LLM instance. Conversation history stored in agent._chat_history is untouched.
Configuration Options
chat() config keys:
| Key | Type | Description |
|---|---|---|
model | str | Override model name for this call (e.g. "gpt-4o", "claude-3-5-sonnet") |
temperature | float | Override temperature for this call |
provider | str | Override provider (e.g. "openai", "anthropic") |
switch_model() signature:
llm= constructor argument).
Agent Config TypeScript Reference
TypeScript agent configuration
Agent Rust Reference
Rust agent configuration
Common Patterns
Route by task complexity:Best Practices
Use per-call config for cost optimization
Use per-call config for cost optimization
Default to a fast, cheap model and escalate to a powerful model only for complex requests. This gives you the best cost-to-quality ratio without managing multiple agents.
Use switch_model for long-running sessions
Use switch_model for long-running sessions
When a user explicitly asks to use a different model, call
switch_model() so all subsequent turns in that session use the new model automatically. Per-call config is better for one-off overrides.Per-call config is thread-safe
Per-call config is thread-safe
Config overrides are applied within the scope of a single
chat() call and never persist to agent state. Multiple concurrent callers can override different models on the same agent instance safely.Conversation history survives model switches
Conversation history survives model switches
switch_model() only changes the model — it does not clear agent._chat_history. The new model receives the full conversation context from previous turns.Related
Model Failover
Automatic fallback when a model call fails
Model Router
Dynamic model selection based on task type

