Data Analyst

Load an IMDB movie CSV into DuckDB and query it with a LangDB agent.

data_analyst.py
"""Run `uv pip install duckdb` to install dependencies."""

from textwrap import dedent

from agno.agent import Agent
from agno.models.langdb import LangDB
from agno.tools.duckdb import DuckDbTools

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

duckdb_tools = DuckDbTools()
duckdb_tools.create_table_from_path(
    path="https://agno-public.s3.amazonaws.com/demo_data/IMDB-Movie-Data.csv",
    table="movies",
)

agent = Agent(
    model=LangDB(id="llama3-1-70b-instruct-v1.0"),
    tools=[duckdb_tools],
    markdown=True,
    additional_context=dedent("""\
    You have access to the following tables:
    - movies: contains information about movies from IMDB.
    """),
)
agent.print_response("What is the average rating of movies?", stream=False)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    pass

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

Configure LangDB access

Create a LangDB project and API key, and enable the provider access required by your selected model. Set the current API host; Agno appends the project ID and /v1.

export LANGDB_API_BASE_URL="https://api.langdb.ai"
export LANGDB_API_KEY="your_langdb_api_key"
export LANGDB_PROJECT_ID="your_langdb_project_id"

Check your project's model catalog for the exact ID and required capabilities, such as vision, tool calling or structured output. Gateway aliases and access can vary by project.

Run the example

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

python data_analyst.py

Full source: cookbook/90_models/langdb/data_analyst.py