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
Install dependencies:
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Switch models and supported providers within one agent session while preserving message and tool-call history.
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.
| 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 |
uv pip install agno google-genai openai sqlalchemy
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.")
Was this page helpful?