DuckDB Tools

Query a remote IMDB movie CSV with SQL using DuckDbTools to compute average ratings.

duckdb_tools.py
"""
Duckdb Tools
=============================

Demonstrates duckdb tools.
"""

from agno.agent import Agent
from agno.tools.duckdb import DuckDbTools

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


agent = Agent(
    tools=[DuckDbTools()],
    instructions="Use this file for Movies data: https://agno-public.s3.amazonaws.com/demo_data/IMDB-Movie-Data.csv",
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    agent.print_response(
        "What is the average rating of movies?", markdown=True, stream=False
    )

The toolkit creates an in-memory DuckDB connection by default. Querying this HTTPS CSV requires network access from DuckDB and may load its HTTP extension on first use. For an offline dataset, download the CSV beforehand and replace the URL in instructions with its local path.

Run the Example

Set up your virtual environment

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

Install dependencies

uv pip install -U agno duckdb openai

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"

Run the example

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

python duckdb_tools.py

Full source: cookbook/91_tools/duckdb_tools.py