CsvTools enable an Agent to read and write CSV files.

Example

The following agent will download the IMDB csv file and allow the user to query it using a CLI app.

cookbook/agent_concepts/tools/csv_tools.py
import httpx
from pathlib import Path
from agno.agent import Agent
from agno.tools.csv import CsvTools

url = "https://agno-public.s3.amazonaws.com/demo_data/IMDB-Movie-Data.csv"
response = httpx.get(url)

imdb_csv = Path(__file__).parent.joinpath("wip").joinpath("imdb.csv")
imdb_csv.parent.mkdir(parents=True, exist_ok=True)
imdb_csv.write_bytes(response.content)

agent = Agent(
    tools=[CsvTools(csvs=[imdb_csv])],
    markdown=True,
    show_tool_calls=True,
    instructions=[
        "First always get the list of files",
        "Then check the columns in the file",
        "Then run the query to answer the question",
        "Always wrap column names with double quotes if they contain spaces or special characters",
        "Remember to escape the quotes in the JSON string (use \")",
        "Use single quotes for string values"
    ],
)

agent.cli_app(stream=False)

Toolkit Params

ParameterTypeDefaultDescription
csvsList[Union[str, Path]]-A list of CSV files or paths to be processed or read.
row_limitint-The maximum number of rows to process from each CSV file.
read_csvsboolTrueEnables the functionality to read data from specified CSV files.
list_csvsboolTrueEnables the functionality to list all available CSV files.
query_csvsboolTrueEnables the functionality to execute queries on data within CSV files.
read_column_namesboolTrueEnables the functionality to read the column names from the CSV files.
duckdb_connectionAny-Specifies a connection instance for DuckDB database operations.
duckdb_kwargsDict[str, Any]-A dictionary of keyword arguments for configuring DuckDB operations.

Toolkit Functions

FunctionDescription
list_csv_filesLists all available CSV files.
read_csv_fileThis function reads the contents of a csv file
get_columnsThis function returns the columns of a csv file
query_csv_fileThis function queries the contents of a csv file

Developer Resources