A FastAPI-based platform for managing and orchestrating AI agents. This project provides a robust foundation for building AI agent systems with async database support, comprehensive API endpoints, and Docker containerization.
- FastAPI Framework: Modern, fast web framework for building APIs
- Async SQLAlchemy: Asynchronous database operations with SQLite
- Pydantic Models: Data validation and serialization
- Docker Support: Containerized deployment with Python 3.10
- RESTful API: Complete CRUD operations for agents and chat sessions
- OpenAI Integration: AI-powered chat responses using GPT models
- Voice Processing: Speech-to-text and text-to-speech capabilities
- Health Checks: Built-in health monitoring
- CORS Support: Cross-origin resource sharing enabled
- Comprehensive Testing: Full test suite with pytest and mocking
- API Documentation: Interactive Swagger UI and Postman collection
- Environment Configuration: .env file support for easy configuration
ai_agent_platform/
├── app/
│ ├── __init__.py
│ ├── database/
│ │ ├── __init__.py
│ │ ├── engine.py
│ │ ├── base.py
│ │ └── database.py
│ ├── models/
│ │ ├── __init__.py
│ │ ├── base.py
│ │ ├── agent.py
│ │ ├── session.py
│ │ └── audio.py
│ ├── schemas/
│ │ ├── __init__.py
│ │ ├── agent.py
│ │ ├── session.py
│ │ ├── message.py
│ │ └── voice.py
│ ├── services/
│ │ ├── __init__.py
│ │ ├── agent_service.py
│ │ ├── session_service.py
│ │ └── voice.py
│ └── routes/
│ ├── __init__.py
│ ├── agent_routes.py
│ ├── sessions.py
│ └── voice.py
├── tests/
│ ├── __init__.py
│ ├── conftest.py
│ ├── test_agents.py
│ ├── test_sessions.py
│ ├── test_voice.py
│ └── test_health.py
├── alembic/ # Database migrations (included in git)
│ ├── env.py
│ ├── versions/
│ └── ...
├── frontend/ # React frontend (source included, build/deps excluded)
│ ├── src/
│ ├── public/
│ └── ...
├── audio_files/
├── main.py
├── requirements.txt
├── pytest.ini
├── Dockerfile
├── docker-compose.yml
├── env.example
├── README.md
└── ...
- The root
.gitignore
covers all backend and frontend exclusions. There is no need for a separatefrontend/.gitignore
. - The
alembic/
directory (including all migration scripts) must be included in git for database versioning. - The entire frontend source code is included, but
node_modules/
,build/
, and environment files are excluded.
- Python 3.10+ (for local development)
- Node.js 16+ and npm (for frontend development)
- Docker (for containerized deployment)
- OpenAI API key (for AI chat and voice functionality)
- Clone the repository:
git clone <repository-url>
cd ai_agent_platform
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install backend dependencies:
pip install -r requirements.txt
- Set up backend environment variables:
# Copy the example environment file
cp env.example .env
# Edit .env file with your configuration
# At minimum, set your OpenAI API key:
# OPENAI_API_KEY=your-openai-api-key-here
- Run the backend application:
python main.py
The API will be available at http://localhost:8000
- Set up and run the frontend (in a new terminal):
# Navigate to frontend directory
cd frontend
# Install frontend dependencies
npm install
# Set up frontend environment
cp env.example .env
# Start the frontend development server
npm start
The frontend will be available at http://localhost:3000
Note: Make sure both the backend (port 8000) and frontend (port 3000) servers are running for full functionality.
- Set up environment variables:
# Copy the example environment file
cp env.example .env
# Edit .env file with your configuration
# At minimum, set your OpenAI API key:
# OPENAI_API_KEY=your-openai-api-key-here
- Build and run with Docker Compose:
docker-compose up --build
- Build the Docker image:
docker build -t ai-agent-platform .
- Run the container:
docker run -p 8000:8000 \
--env-file .env \
-v $(pwd)/audio_files:/app/audio_files \
ai-agent-platform
docker run -p 8000:8000 \
-e OPENAI_API_KEY="your-openai-api-key" \
-e DEBUG=False \
-e LOG_LEVEL=info \
ai-agent-platform
The application supports configuration through environment variables or a .env
file:
OPENAI_API_KEY
: Your OpenAI API key for AI functionality
DATABASE_URL
: Database connection string (default: SQLite)DEBUG
: Enable debug mode (default: False)LOG_LEVEL
: Logging level (default: info)HOST
: Server host (default: 0.0.0.0)PORT
: Server port (default: 8000)
# Copy env.example to .env and configure
OPENAI_API_KEY=your-openai-api-key-here
DATABASE_URL=sqlite+aiosqlite:///./ai_agent_platform.db
DEBUG=False
LOG_LEVEL=info
HOST=0.0.0.0
PORT=8000
Once the application is running, you can access:
- Interactive API Docs (Swagger UI):
http://localhost:8000/docs
- ReDoc Documentation:
http://localhost:8000/redoc
- OpenAPI Schema:
http://localhost:8000/openapi.json
A complete Postman collection is included for API testing:
- File:
AI Agent Platform.postman_collection.json
- Description: Pre-configured requests for all API endpoints
- Environment Variables: Uses
{{baseUrl}}
variable (set tohttp://localhost:8000
for local development)
- Open Postman
- Click "Import" button
- Select the
AI Agent Platform.postman_collection.json
file - The collection will be imported with all endpoints organized by category
- Create a new environment in Postman
- Add variable
baseUrl
with valuehttp://localhost:8000
- Select the environment before running requests
- Agents: Create, read, update, delete agents
- Sessions: Create and list chat sessions
- Messages: Send messages and get AI responses
- Voice: Process voice messages with speech-to-text and text-to-speech
- Audio: Download generated audio files
- Health: Health check endpoint
GET /api/v1/agents/
- List all agentsPOST /api/v1/agents/
- Create a new agentGET /api/v1/agents/{agent_id}
- Get agent by IDPUT /api/v1/agents/{agent_id}
- Update agentDELETE /api/v1/agents/{agent_id}
- Delete agent
POST /api/v1/agents/{agent_id}/sessions
- Start new chat sessionGET /api/v1/agents/{agent_id}/sessions
- List sessions for an agentPOST /api/v1/sessions/{session_id}/messages
- Send message and get AI response
POST /api/v1/sessions/{session_id}/voice
- Process voice message (speech-to-text → AI response → text-to-speech)GET /api/v1/audio/{audio_filename}
- Download generated audio file
GET /health
- Health check endpoint
curl -X POST "http://localhost:8000/api/v1/agents/" \
-H "Content-Type: application/json" \
-d '{
"name": "ChatBot Agent",
"description": "A conversational AI agent",
"agent_type": "chatbot",
"is_active": true,
"configuration": {
"model": "gpt-3.5-turbo",
"system_prompt": "You are a helpful assistant.",
"temperature": 0.7,
"max_tokens": 1000
},
"capabilities": ["text_generation", "conversation"]
}'
curl -X POST "http://localhost:8000/api/v1/agents/1/sessions"
curl -X POST "http://localhost:8000/api/v1/sessions/1/messages" \
-H "Content-Type: application/json" \
-d '{
"content": "Hello, how are you today?"
}'
curl -X POST "http://localhost:8000/api/v1/sessions/1/voice" \
-F "audio_file=@your_audio_file.wav"
curl -X GET "http://localhost:8000/api/v1/audio/response_1_abc123.mp3" \
--output response.mp3
curl -X GET "http://localhost:8000/api/v1/agents/1/sessions"
- Input:
.wav
,.mp3
,.m4a
,.webm
- Output:
.mp3
(using OpenAI TTS)
- Speech-to-Text: Uses OpenAI Whisper API to convert audio to text
- AI Processing: Sends transcribed text to GPT model for response
- Text-to-Speech: Converts AI response to audio using OpenAI TTS
- Storage: Saves audio files and metadata to database
The system stores comprehensive metadata for each voice interaction:
- Input audio file information
- Output audio file path
- Transcription text
- TTS voice settings
- File formats and durations
The project includes a comprehensive test suite with pytest:
# Run all tests
pytest
# Run tests with verbose output
pytest -v
# Run specific test file
pytest tests/test_agents.py
# Run tests with coverage
pytest --cov=app
# Run only unit tests
pytest -m unit
# Run only integration tests
pytest -m integration
# Skip slow tests
pytest -m "not slow"
tests/conftest.py
: Test fixtures and configurationtests/test_agents.py
: Agent endpoint teststests/test_sessions.py
: Session and message teststests/test_voice.py
: Voice processing teststests/test_health.py
: Health endpoint tests
- Async Database Testing: Isolated test database with automatic cleanup
- OpenAI API Mocking: Mocked responses for reliable testing
- Fixture System: Reusable test data and setup
- Comprehensive Coverage: Tests for success cases, validation, and error handling
# Install formatting tools
pip install black isort
# Format code
black .
isort .
# Install linting tools
pip install flake8 mypy
# Run linting
flake8 .
mypy app/
The application uses the following environment variables:
OPENAI_API_KEY
: Your OpenAI API key (required for AI chat and voice functionality)DATABASE_URL
: Database connection string (defaults to SQLite)DEBUG
: Enable debug mode (default: False)LOG_LEVEL
: Logging level (default: info)HOST
: Server host (default: 0.0.0.0)PORT
: Server port (default: 8000)
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
- Write tests for all new features
- Follow the existing code style
- Update documentation as needed
- Ensure all tests pass before submitting PR