Build a Uniswap Docs Retrieval Agent with SwarmZero.ai
This Uniswap Documentation Retrieval Agent allows users to build a specialized Q&A Retrieval-Augmented Generation (RAG) agent that sources information directly from Uniswap’s official documentation. The agent is designed to provide accurate, timely, and user-friendly responses to questions about Uniswap.
This tutorial will guide you through setting up, configuring, and extending a Dune Analytics agent using the uniswap-retrieval-agent
repository from SwarmZero.ai.
Prerequisites
Before starting, ensure you have the following:
Python 3.8 or higher installed.
Git installed.
An IDE or text editor (VS Code, PyCharm, etc.).
A basic understanding of Python programming.
Uniswap Documentation to use as a reference for answering user queries.
API keys from OpenAI, Anthropic, and Mistral if you plan to use these services.
Step-by-Step Tutorial for Building a Uniswap Agent with SwarmZero.ai
Here is a detailed guide to building the Uniswap Docs Retrieval Agent:
Cloning the Repository
To begin, clone the uniswap-retrieval-agent
repository to your local machine. This will give you access to the code and resources needed to run and customize the Uniswap Agent.
Step 1: Open your terminal or command prompt. Ensure Git is installed on your system.
Step 2: Run the following commands:
These commands will download the repository and navigate into its directory, setting up the base environment to start working on the agent.
Setting Up the Environment
Now that you have the repository cloned, the next step is to set up the environment to run the agent. This involves creating a virtual environment, installing dependencies, and configuring environment variables.
Step 1: Create a virtual environment:
Step 2: Activate the virtual environment
Command Prompt:
PowerShell:
On Unix/Mac:
Installing Dependencies
With the virtual environment activated, install the required dependencies:
Run the command below to install the optional dependencies:
Setting Up Environment Variables
Step 1: Create a new file called .env in the root directory:
Step 2: Copy the contents of .env.example into your new .env file.
Step 3: Add your API keys to the .env file:
These steps will ensure your environment is properly configured to run the Uniswap Docs Retreival Agent.
Understanding the Code Structure
Before running and customizing the agent, it's essential to understand the structure of the uniswap_agent
repository. This will help you navigate through the code and make necessary modifications efficiently.
Overview of Key Files and Directories:
.env.example
: This file provides an example of the environment variables required for the project. Copy this to create your.env
file and add the necessary keys.hive_config.toml
: Contains configuration settings for the agent, such as API keys and other adjustable settings.uniswap-retrieval-agent.py
: This is the main script that runs the agent. It contains the core logic for fetching Uniswap documentation, processing it, and answering user queries.requirements.txt
: Lists all the dependencies required to run the agent.
Building the Uniswap Agent (uniswap-retrieval-agent.py)
In this section, you will now understand the logic and the process of building a Uniswap Docs AI agent with SwarmZero.ai.
Step 1: Import Necessary Libraries
Start by importing the required libraries. These include libraries for handling environment variables, logging, and interacting with the HiveAgent.
Step 2: Configure Logging
Set up logging to help you monitor the execution of your program.
Step 3: Define the Utility Function to Get the Configuration Path
Define a utility function to get the absolute path to your configuration file.
Step 4: Set Up Instruction for the Uniswap Agent
Create an instruction string that defines the role of the agent. The agent's purpose is to provide answers based on Uniswap documentation.
Step 5: Create and Run the HiveAgent
Finally, create an instance of the HiveAgent, passing in the functions, instructions, and configuration path. Then, run the agent.
Running the Agent
With the environment set-up and a basic understanding of the code structure, you are now ready to run the agent.
Ensure your virtual environment is activated. You can test your agent by calling its Chat API endpoint to see the result.
Here’s an example using curl:
Step 1: Run the API server:
Step 2: Open the Swagger Docs
Step 3: Choose the POST /api/vi/chat and test it:
This will send a request to the API and provide you with a response, allowing you to verify the agent’s functionality.
Output
As the next steps, you can proceed with testing if required.
Wrap Up
Congratulations! You've successfully set up, configured, and customized your Uniswap Docs Retrieval Agent using SwarmZero.ai.
Last updated