CsvTools 使 Agent 能够读写 CSV 文件。
下面的 Agent 将下载 IMDB CSV 文件,并允许用户通过 CLI 应用程序对其进行查询。
cookbook/tools/csv_tools.py
import httpx
from pathlib import Path
from agno.agent import Agent
from agno.tools.csv_toolkit 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)
参数 | 类型 | 默认值 | 描述 |
---|
csvs | List[Union[str, Path]] | - | 要处理或读取的 CSV 文件或路径列表。 |
row_limit | int | - | 要从每个 CSV 文件处理的最大行数。 |
read_csvs | bool | True | 启用从指定 CSV 文件读取数据的功能。 |
list_csvs | bool | True | 启用列出所有可用 CSV 文件功能。 |
query_csvs | bool | True | 启用执行 CSV 文件内数据查询的功能。 |
read_column_names | bool | True | 启用从 CSV 文件读取列名的功能。 |
duckdb_connection | Any | - | 指定用于 DuckDB 数据库操作的连接实例。 |
duckdb_kwargs | Dict[str, Any] | - | 用于配置 DuckDB 操作的关键字参数字典。 |
函数 | 描述 |
---|
list_csv_files | 列出所有可用的 CSV 文件。 |
read_csv_file | 此函数读取 CSV 文件的内容。 |
get_columns | 此函数返回 CSV 文件的列。 |
query_csv_file | 此函数查询 CSV 文件内容。 |
开发者资源
Responses are generated using AI and may contain mistakes.