Interchange Model: All 5 Providers

Cycles through OpenAI Chat, OpenAI Responses, Claude, Gemini, and AWS Claude.

Cycles through OpenAI Chat, OpenAI Responses, Claude, Gemini, and AWS Claude. The agent can call a tool and summarize the resulting conversation after switching providers.

The local get_weather function returns simulated weather, not live conditions. Tool choice remains model-selected; a summary turn may reuse history without calling the tool again. This example demonstrates tool-message and history interchange.

all_providers.py
"""
Interchange Model: All 5 Providers

Cycles through OpenAI Chat, OpenAI Responses, Claude, Gemini, and AWS Claude.
Tool calls happen on every turn, then the history is summarized from a different provider.
"""

import os
from random import randint

from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.models.anthropic import Claude
from agno.models.aws import Claude as AWSClaude
from agno.models.google import Gemini
from agno.models.openai import OpenAIChat, OpenAIResponses


def get_weather(city: str) -> str:
    """Get the current weather for a city."""
    return f"The weather in {city} is sunny and {randint(-10, 35)}C."


def main() -> None:
    db_url = os.getenv(
        "AGNO_POSTGRES_URL",
        "postgresql+psycopg://ai:ai@localhost:5532/ai",
    )
    db = PostgresDb(db_url)

    agent = Agent(
        model=OpenAIChat(id="gpt-5.6-luna"),
        db=db,
        add_history_to_context=True,
        num_history_runs=10,
        tools=[get_weather],
        introduction="You are a weather agent that can check the weather in different cities.",
    )

    # Turn 1 — OpenAI Chat (call_* IDs)
    agent.print_response("What is the weather in Paris?")

    # Turn 2 — OpenAI Responses (fc_* IDs)
    agent.model = OpenAIResponses()
    agent.print_response("What is the weather in London?")

    # Turn 3 — Claude (toolu_* IDs)
    agent.model = Claude()
    agent.print_response("What is the weather in Tokyo?")

    # Turn 4 — Gemini (UUID-style IDs)
    agent.model = Gemini()
    agent.print_response("What is the weather in New York?")

    # Turn 5 — Back to OpenAI Chat to summarize all history
    agent.model = OpenAIChat(id="gpt-5.6-luna")
    agent.print_response("Summarize all the weather we checked.")

    # Turn 6 — Claude summarizes (sees history from all providers)
    agent.model = Claude()
    agent.print_response("Which city had the best weather?")

    # Turn 7 — AWS Claude
    agent.model = AWSClaude()
    agent.print_response("What is the weather in Beijing?")

    # Turn 8 — OpenAI Responses (fc_* IDs)
    agent.model = OpenAIResponses()
    agent.print_response("What is the weather in London?")


if __name__ == "__main__":
    main()

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno "anthropic[bedrock]" "psycopg[binary]" aioboto3 boto3 google-genai openai sqlalchemy

Export environment variables

The AWS model defaults to a global Claude Sonnet 4.5 inference profile. Configure a supported source region, Bedrock model access, and permissions for the profile and its destination models. When using temporary AWS credentials, also export the corresponding AWS_SESSION_TOKEN ($Env:AWS_SESSION_TOKEN in PowerShell).

export ANTHROPIC_API_KEY="your_anthropic_api_key_here"
export AWS_ACCESS_KEY_ID="your_aws_access_key_id_here"
export AWS_REGION="your_aws_region_here"
export AWS_SECRET_ACCESS_KEY="your_aws_secret_access_key_here"
export GOOGLE_API_KEY="your_google_api_key_here"
export OPENAI_API_KEY="your_openai_api_key_here"

Run PgVector

docker run -d \
  -e POSTGRES_DB=ai \
  -e POSTGRES_USER=ai \
  -e POSTGRES_PASSWORD=ai \
  -e PGDATA=/var/lib/postgresql \
  -v pgvolume:/var/lib/postgresql \
  -p 5532:5432 \
  --name pgvector \
  agnohq/pgvector:18

Run the example

Save the code above as all_providers.py, then run:

python all_providers.py

Full source: cookbook/02_agents/14_advanced/interchange_model/all_providers.py