Agent API
A robust, production-ready application for serving Agents as an API.
Welcome to the Simple Agent API: a robust, production-ready application for serving Agents as an API. It includes:
- A FastAPI server for handling API requests.
- A PostgreSQL database for storing Agent sessions, knowledge, and memories.
- A set of pre-built Agents to use as a starting point.
Quickstart
Follow these steps to get your Agent API up and running:
Prerequisites: Docker Desktop should be installed and running.
Clone the repo
Export your OpenAI key
Start the application
Test the application
This command starts:
- The FastAPI server, running on
localhost:8000
. - The PostgreSQL database, accessible on
localhost:5432
.
Once started, you can:
- Test the API at localhost:8000/docs.
- Connect to Agno Playground or Agent UI:
- Open the Agno Playground app.agno.com/playground/agents.
- Add
http://localhost:8000
as a new endpoint. You can name itAgent API
(or any name you prefer). - Select your newly added endpoint and start chatting with your Agents.
Stop the application
Folder structure
The agent-api
folder contains the following structure:
Prebuilt Agents
The /agents
folder contains pre-built agents that you can use as a starting point.
- Web Search Agent: A simple agent that can search the web.
- Agno Assist: An Agent that can help answer questions about Agno.
- Important: Make sure to load the
agno_assist
knowledge base before using this agent.
- Important: Make sure to load the
- Finance Agent: An agent that uses the Yahoo Finance API to get stock prices and financial data.
Managing Python Dependencies
Modify pyproject.toml
Add or update your desired Python package dependencies in the [tool.poetry.dependencies]
section of the pyproject.toml
file.
Generate requirements.txt
The requirements.txt
file is used to build the application image. After modifying pyproject.toml
, regenerate requirements.txt
using:
To upgrade all existing dependencies to their latest compatible versions, run:
Rebuild Docker Images
Rebuild your Docker images to include the updated dependencies:
Running in Production
This repository includes a Dockerfile
for building a production-ready container image of the application.
The general process to run in production is:
- Update the
scripts/build_image.sh
file and set yourIMAGE_NAME
andIMAGE_TAG
variables. - Build and push the image to your container registry:
- Run in your cloud provider of choice.
Detailed Steps
1. Configure for Production
- Ensure your production environment variables (e.g.,
OPENAI_API_KEY
, database connection strings) are securely managed. Most cloud providers offer a way to set these as environment variables for your deployed service. - Review the agent configurations in the
/agents
directory and ensure they are set up for your production needs (e.g., correct model versions, any production-specific settings).
2. Build Your Production Docker Image
Update the scripts/build_image.sh
script to set your desired IMAGE_NAME
and IMAGE_TAG
(e.g., your-repo/agent-api:v1.0.0
).
Run the script to build and push the image:
3. Deploy to a Cloud Service
With your image in a registry, you can deploy it to various cloud services that support containerized applications. Some common options include:
Serverless Container Platforms:
- Google Cloud Run: A fully managed platform that automatically scales your stateless containers.
- AWS App Runner: Makes it easy to deploy containerized web applications and APIs at scale.
- Azure Container Apps: Build and deploy modern apps and microservices using serverless containers.
Container Orchestration Services:
- Amazon Elastic Container Service (ECS): Often used with AWS Fargate for serverless compute or EC2 instances.
- Google Kubernetes Engine (GKE): Managed Kubernetes service.
- Azure Kubernetes Service (AKS): Managed Kubernetes service.
Platform as a Service (PaaS) with Docker Support:
- Railway.app: Simple deployment from a Dockerfile.
- Render: Simplifies deploying Docker containers, databases, and static sites.
- Heroku: Supports deploying Docker containers.
Specialized Platforms:
- Modal: Platform for running Python code in the cloud, can serve web endpoints.
The specific deployment steps will vary depending on the chosen provider. Generally, you'll point the service to your container image in the registry and configure port mapping (application runs on port 8000
by default), environment variables, scaling, and database connections.
4. Database Configuration
The default docker-compose.yml
sets up a PostgreSQL database for local development. In production, use a managed database service (e.g., AWS RDS, Google Cloud SQL, Azure Database for PostgreSQL).
Ensure your deployed application is configured with the correct database connection URL for your production database, usually via environment variables.
Additional Information
Congratulations on running your Agent API.
- Read how to use workspaces with your Agent API