Skip to main content

PandasAI Agent Overview

While the pai.chat() method is meant to be used in a single session and for exploratory data analysis, an agent can be used for multi-turn conversations. To instantiate an agent, you can use the following code:
Contrary to the pai.chat() method, an agent will keep track of the state of the conversation and will be able to answer multi-turn conversations. For example:

Follow-up Questions

An agent can handle follow-up questions that continue the existing conversation without starting a new chat. This maintains the conversation context. For example:
The follow_up method works just like chat but doesn’t clear the conversation memory, allowing the agent to understand context from previous messages.

Using the Agent in a Sandbox Environment

The sandbox works offline and provides an additional layer of security for code execution. It’s particularly useful when working with untrusted data or when you need to ensure that code execution is isolated from your main system.
To enhance security and protect against malicious code through prompt injection, PandasAI provides a sandbox environment for code execution. The sandbox runs your code in an isolated Docker container, ensuring that potentially harmful operations are contained.

Installation

Before using the sandbox, you need to install Docker on your machine and ensure it is running. First, install the sandbox package:

Basic Usage

Here’s how to use the sandbox with your PandasAI agent:

Customizing the Sandbox

You can customize the sandbox environment by specifying a custom name and Dockerfile:

Training the Agent with local Vector stores

Training agents with local vector stores requires a PandasAI Enterprise license. See Enterprise Features for more details or contact us for production use.
It is possible also to use PandasAI with a few-shot learning agent, thanks to the “train with local vector store” enterprise feature (requiring an enterprise license). If you want to train the agent with a local vector store, you can use the local ChromaDB, Qdrant or Pinecone vector stores. Here’s how to do it: An enterprise license is required for using the vector stores locally. See Enterprise Features for licensing information. If you plan to use it in production, contact us.