Async Tool Use

Run a gpt-4o agent with WebSearchTools asynchronously and stream the response through the OpenAI Responses API.

Code

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

import asyncio

from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.tools.websearch import WebSearchTools

agent = Agent(
    model=OpenAIResponses(id="gpt-4o"),
    tools=[WebSearchTools()],
    markdown=True,
)
asyncio.run(agent.aprint_response("Whats happening in France?", stream=True))

Usage

Set up your virtual environment

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

Set your API key

export OPENAI_API_KEY=xxx

Install dependencies

uv pip install -U openai ddgs agno

Run Agent

python async_tool_use.py