openai_claude.py
import os
from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.models.anthropic import Claude
from agno.models.openai import OpenAIChat
def get_weather(city: str) -> str:
"""Get the current weather for a city."""
return f"The weather in {city} is sunny and 22C."
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-4o"),
db=db,
add_history_to_context=True,
num_history_runs=10,
tools=[get_weather],
debug_mode=True,
)
# Turn 1 — OpenAI with tool call (works fine)
agent.print_response("What is the weather in Paris?")
# Turn 2 — Claude with tool call (works fine)
agent.model = Claude()
agent.print_response("What is the weather in London?")
# Turn 3 — OpenAI with tool call (works fine on its own)
agent.model = OpenAIChat(id="gpt-4o")
agent.print_response("What is the weather in Tokyo?")
# Turn 4 — Claude summary
agent.model = Claude()
agent.print_response("Summarize all the weather we checked.")
if __name__ == "__main__":
main()
Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
Export your API keys
export ANTHROPIC_API_KEY="your_anthropic_api_key_here"
export OPENAI_API_KEY="your_openai_api_key_here"
$Env:ANTHROPIC_API_KEY="your_anthropic_api_key_here"
$Env: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/data/pgdata \
-v pgvolume:/var/lib/postgresql/data \
-p 5532:5432 \
--name pgvector \
agnohq/pgvector:18