Copy
Ask AI
"""
Anthropic Web Search
====================
Cookbook example for `anthropic/web_search.py`.
"""
from pprint import pprint
from agno.agent import Agent
from agno.db.in_memory import InMemoryDb
from agno.models.anthropic import Claude
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
model=Claude(
id="claude-sonnet-4-20250514",
),
db=InMemoryDb(),
tools=[
{
"type": "web_search_20250305",
"name": "web_search",
"max_uses": 5,
}
],
markdown=True,
)
agent.print_response("What's the latest with Anthropic?", stream=True)
# Show the web search metrics
print("---" * 5, "Web Search Metrics", "---" * 5)
pprint(agent.get_last_run_output().metrics)
print("---" * 20)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
pass
Run the Example
Copy
Ask AI
# Clone and setup repo
git clone https://github.com/agno-agi/agno.git
cd agno/cookbook/90_models/anthropic
# Create and activate virtual environment
./scripts/demo_setup.sh
source .venvs/demo/bin/activate
python web_search.py