Skip to content

A production-grade REST API for deploying and managing AI agents in the cloud. This API provides a scalable and secure way to create, manage, and interact with AI agents.

License

Notifications You must be signed in to change notification settings

The-Swarm-Corporation/AgentAPIProduction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Swarms Agent API

Join our Discord Subscribe on YouTube Connect on LinkedIn Follow on X.com

A production-grade REST API for deploying and managing AI agents in the cloud. This API provides a scalable and secure way to create, manage, and interact with AI agents.

License: MIT Python 3.11+ Docker

Features

  • πŸš€ Create and manage multiple AI agents
  • πŸ”„ Process completions with rate limiting and error handling
  • πŸ“Š Track agent metrics and performance
  • πŸ”’ Built-in security features
  • 🎯 Horizontal scaling support
  • πŸ› οΈ Easy deployment with Docker
  • πŸ’« Graceful shutdown handling
  • πŸ” Comprehensive logging
  • ⚑ High-performance FastAPI backend

Quick Start

Prerequisites

  • Python 3.11+
  • Docker (optional)
  • OpenAI API key (or other LLM provider key)

Local Development Setup

  1. Clone the repository:
git clone https://github.com/The-Swarm-Corporation/AgentAPIProduction.git
cd agent-api
  1. Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: .\venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Create a .env file:
OPENAI_API_KEY=your_api_key_here
PORT=8080
WORKSPACE_DIR=agent_workspace
  1. Run the server:
python -m uvicorn api.api:app --host 0.0.0.0 --port 8080 --reload

Docker Deployment

  1. Build the Docker image:
docker build -t agent-api .
  1. Run the container:
docker run -d \
  -p 8080:8080 \
  -e OPENAI_API_KEY=your_api_key_here \
  -e PORT=8080 \
  --name agent-api \
  agent-api

API Documentation

Base URL

http://localhost:8080/v1

Endpoints

Create Agent

POST /v1/agent
{
  "agent_name": "string",
  "model_name": "string",
  "description": "string",
  "system_prompt": "string",
  "temperature": 0.1,
  "max_loops": 1
}

List Agents

GET /v1/agents

Process Completion

POST /v1/agent/completions
{
  "prompt": "string",
  "agent_id": "uuid",
  "max_tokens": null,
  "temperature_override": 0.5
}

Get Agent Metrics

GET /v1/agent/{agent_id}/metrics

For full API documentation, visit /v1/docs or /v1/redoc after starting the server.

Rate Limiting

The API implements rate limiting with the following defaults:

  • 2 requests per second
  • 30 requests per minute
  • 1000 requests per hour
  • 10000 requests per day

Deployment Considerations

Production Environment

For production deployment, consider:

  1. Using a reverse proxy (e.g., Nginx)
  2. Implementing SSL/TLS
  3. Setting up monitoring (e.g., Prometheus + Grafana)
  4. Using environment-specific configuration
  5. Implementing proper backup strategies

Example docker-compose.yml for production:

version: '3.8'

services:
  agent-api:
    build: .
    ports:
      - "8080:8080"
    environment:
      - OPENAI_API_KEY=${OPENAI_API_KEY}
      - PORT=8080
    volumes:
      - agent_data:/app/agent_workspace
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 30s
      timeout: 3s
      retries: 3
    restart: unless-stopped

volumes:
  agent_data:

Cloud Deployment

The API can be deployed to various cloud providers:

AWS Elastic Beanstalk

eb init -p docker agent-api
eb create production

Google Cloud Run

gcloud builds submit --tag gcr.io/PROJECT_ID/agent-api
gcloud run deploy agent-api --image gcr.io/PROJECT_ID/agent-api

Azure Container Instances

az container create \
  --resource-group myResourceGroup \
  --name agent-api \
  --image your-registry.azurecr.io/agent-api \
  --dns-name-label agent-api \
  --ports 8080

Error Handling

The API implements comprehensive error handling:

  • Rate limit exceeded: 429
  • Not found: 404
  • Internal server error: 500

Error responses follow this format:

{
  "detail": {
    "error": "string",
    "message": "string"
  }
}

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For support and questions:

Acknowledgments

  • FastAPI for the excellent web framework
  • Swarms for the agent implementation
  • The open-source community

Made with ❀️ by swarms.ai

About

A production-grade REST API for deploying and managing AI agents in the cloud. This API provides a scalable and secure way to create, manage, and interact with AI agents.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published