Migrating away from create_csv_agent in langchain-cohere
How to build a CSV Agent without using deprecated create_csv_agent - langchain-cohere
Starting from version 0.3.5 of the langchain-cohere package, the create_csv_agent abstraction has been deprecated.
In this guide, we will demonstrate how to build a custom CSV agent without it.
Define tools necessary for the agent
The below cell introduces a suite of tools that are provided to the csv agent. These tools allow the agent to fcilitate meaningful interactions with uploaded files and providing Python code execution functionality. The toolkit comprises three main components:
File Peek Tool: Offers a convenient way to inspect a CSV file by providing a quick preview of the first few rows in a Markdown format, making it easy to get a glimpse of the data.
File Read Tool: Allows for a comprehensive exploration of the CSV file by reading and presenting its full contents in a user-friendly Markdown format.
Python Interpreter Tool: Enables secure execution of Python code within a sandboxed environment, providing users with the output of the code execution.
Create helper functions
In the cell below, we will create some important helper functions that we can call to properly assemble the full prompt that the csv agent can utilize.
Build the core csv agent abstraction
The cells below outline the assembly of the various components to build an agent abstraction tailored for intelligent CSV file interactions. We use langchain to provide the agent that has access to the tools declared above, along with additional capabilities to provide additional tools if needed, and put together an agentic abstraction using the prompts defined earlier to deliver an abstraction that can easily be called for natural language querying over csv files!
Using the CSV agent
Let’s create a dummy CSV file for demo
CSV file created successfully at movies_tickets.csv.
Let’s use our CSV Agent to interact with the CSV file
The output returned is: