Skip to main content

Getting Started with the RAG Agents SDK

This tutorial will guide you through setting up your environment, installing the SDK, and creating your first agent. By the end of this tutorial, you will have a basic understanding of how to build and run agents using the SDK.

Prerequisites

Before you begin, make sure you have the following installed:

  • Python 3.8 or higher
  • pip (Python package installer)

Step 1: Setting Up Your Environment

First, let's set up a virtual environment to manage our dependencies. If you have a preferred method for managing virtual environments, feel free to use that instead.

Open your terminal and run the following commands:

# Create a new virtual environment
python -m venv agents-sdk-env

# Activate the virtual environment
# On Windows
agents-sdk-env\Scripts\activate

# On macOS/Linux
source agents-sdk-env/bin/activate

Step 2: Installing the Agents SDK

Next, let's install the RAG Agents SDK. Run the following command in your terminal:

pip install zetaalpha.rag-agents

Congratulations! You now have the SDK installed on your system. To verify the installation, you can run the following command:

rag_agents --help

Step 3: Creating Your First Agent

Now that we have the SDK installed, let's create our first agent. Run the following command to set up a new agents project:

rag_agents init

The wizard will ask you for the location to create the project and the name of the first agent. The folder structure will be created as follows:

<agents project>/
├── .gitignore
├── __init__.py
├── <agent name>.py
├── agent_setups.json
└── env/
└── agent_setups.json

Step 4: Test Your Agent Locally

The SDK includes a UI for interacting with your agent and evaluating its performance. To start the UI, run the following command:

rag_agents dev <agents project>

The command will open a new browser window where you can chat with the agent and change its configuration. For more details on the evaluation interface, check the How to Evaluate Agent Quality Using RAGElo guide.

Step 4: Running Your Agent Locally

The SDK serves a chat REST API for calling the agents you create. There is a streaming and a non-streaming endpoint. To serve the API locally you can run the following command:

rag_agents serve <agents project>

You can see the API documentation at http://localhost:8000/docs. To test your agent you can use the Swagger UI or send a POST request to the /chats/responses endpoint. Here's an example using curl:

curl -X POST "http://localhost:8000/chats/responses?tenant=zetaalpha" \
-H "Content-Type: application/json" \
-d '{
"agent_identifier": "<agent name>",
"messages": [
{
"sender": "user",
"content": "Hello, how are you?"
}
]
}'

This API is designed to be compatible with the Zeta Alpha platform and you can either deploy the agents in the SaaS platform (managed) or deploy them on your own infrastructure (self-hosted). If you need to customize the REST server, you can read the How to Extend the API Server guide.

info

When deploying the server in self-hosted mode, you are responsible for handling the configuration of the agents. In managed mode, the configuration is taken from your tenant configuration.

warning

When deploying the server in self-hosted mode, you are responsible for handling the authentication and authorization of the users calling the API. The chat API takes headers Authorization for temporary tokens (JWT) or X-Auth for API keys. In managed mode, the authentication and authorization are handled by the platform.

Conclusion

Congratulations! You've successfully set up your environment, installed the Agents SDK, and created your first agent. You can now start building more complex agents and explore the other features of the SDK.

Next Steps

If you have any questions or run into issues, feel free to reach out to our support team.