Run Local Agent API
This guide will walk you through:
- Creating a minimal FastAPI app with an Agno agent
- Containerizing it with Docker
- Running it locally along with a PostgreSQL database for knowledge and memory
Setup
Create a new directory for your project
Create a new directory for your project and navigate to it. After following this guide, your project structure will should look like this:
After following this guide, your project structure will should look like this:
Create a `requirements.txt` file and add the required dependencies:
Step 1: Create a FastAPI App with an Agno Agent
Create a new Python file, e.g., `main.py`, and add the following code to create a minimal FastAPI app with an Agno agent:
Create and activate a virtual environment:
Install the required dependencies by running:
Set your OPENAI_API_KEY environment variable:
Run the FastAPI app with `uvicorn main:app --reload`.
Step 2: Create a Dockerfile
In the same directory, create a new file named `Dockerfile` with the following content:
Build the Docker image by running:
Run the Docker container with:
Access your app
You can now access the FastAPI app at http://localhost:8000
.
Step 3: Add Knowledge and Memory with PostgreSQL
Update your `main.py` file to include knowledge and memory storage using PostgreSQL:
Create a `docker-compose.yml` file in the same directory with the following content:
Run the Docker Compose setup with:
This will start the FastAPI app and the PostgreSQL database, allowing your agent to use knowledge and memory storage.
You can now access the FastAPI app at http://localhost:8000
and interact with your agent that has knowledge and memory capabilities.
You can test the agent by running curl http://localhost:8000/ask?query="What is the recipe for pad thai?"
.