Tools

Give an OpenRouter agent WebSearchTools and stream the answer in both sync and async runs.

tool_use.py
"""Run `uv pip install ddgs` to install dependencies."""

import asyncio

from agno.agent import Agent
from agno.models.openrouter import OpenRouter
from agno.tools.websearch import WebSearchTools

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

agent = Agent(
    model=OpenRouter(id="gpt-5.6-luna"),
    tools=[WebSearchTools()],
    markdown=True,
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    # --- Sync + Streaming ---
    agent.print_response("Whats happening in France?", stream=True)

    # --- Async + Streaming ---
    asyncio.run(agent.aprint_response("Whats happening in France?", stream=True))

Run the Example

Set up your virtual environment

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

Install dependencies

uv pip install -U agno ddgs openai

Export your OpenRouter API key

export OPENROUTER_API_KEY="your_openrouter_api_key_here"

Use the full OpenRouter model ID

Replace each bare id="gpt-5.6-luna" with id="openai/gpt-5.6-luna". On the structured-output example, also replace id="gpt-4o-2024-08-06" with the same full Luna ID. Keep the JSON-mode/schema settings and other options. The OpenRouter catalog lists this model with tool and structured-output support; account and provider availability still apply.

Run the example

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

python tool_use.py

Full source: cookbook/90_models/openrouter/chat/tool_use.py