How to Switch Between Different Models
Switch models and supported providers within one agent session while preserving message and tool-call history.
Reuse one Agent and assign a new model to agent.model between turns. Agno reformats stored messages and tool-call IDs for supported providers before sending the history to the next model.
Provider Support
| Switch | Guidance |
|---|---|
| Different model from the same provider | Supported |
| OpenAI Chat, OpenAI Responses, Anthropic Claude, Google Gemini, and AWS Claude | Supported, including stored tool calls and results |
| Other provider combinations | Test provider-specific content such as reasoning blocks, server tools, and multimodal messages before production |
Install dependencies:
uv pip install agno google-genai openai sqlalchemySet the API keys required by each provider before running the example. See Environment variables.
Switch Models
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.google import Gemini
from agno.models.openai import OpenAIChat
agent = Agent(
model=OpenAIChat(id="gpt-5.4"),
instructions="You are a helpful assistant for technical discussions.",
db=SqliteDb(db_file="tmp/model_switching.db"),
add_history_to_context=True,
num_history_runs=10,
)
agent.print_response("Explain quantum computing basics")
# Switch models within the same provider
agent.model = OpenAIChat(id="gpt-5.4-mini")
agent.print_response("What are the main applications?")
# Switch providers and keep the same session history
agent.model = Gemini(id="gemini-3.5-flash")
agent.print_response("Summarize our discussion so far.")