This directory contains the core API components for the Sustineo application, a FastAPI-based backend that provides voice processing, agent management, and real-time communication capabilities.
The API is built using FastAPI and provides several key functionalities:
- Real-time voice processing and Azure OpenAI Realtime API integration
- Agent management and execution system
- WebSocket connections for real-time communication
- Telemetry and observability
- Azure service integrations (Storage, Cosmos DB, AI services)
The FastAPI application entry point that:
- Configures CORS middleware for cross-origin requests
- Sets up application lifespan management
- Includes routers for voice and agent functionality
- Manages WebSocket connections for real-time communication
- Initializes telemetry and tracing
Key Features:
- Environment variable configuration for Azure services
- Application startup/shutdown lifecycle management
- Router inclusion for modular API organization
Defines the core data structures used throughout the application:
Configuration Classes:
Configuration: Agent system configuration with tools and contentDefaultConfiguration: Default settings for voice/agent configurations
Agent Classes:
Agent: Represents an AI agent with parameters and optionsFunction: Represents callable functions with typed parametersFunctionParameter: Typed parameters for function definitions
Event Classes:
Update: Base update event for WebSocket communicationAgentUpdateEvent: Specific events for agent status updatesContent: Content wrapper for various data types
Handles WebSocket connections and real-time communication:
Connection Class:
- Wraps FastAPI WebSocket for enhanced functionality
- Provides methods for JSON communication
- Manages connection state and lifecycle
ConnectionManager Class:
- Manages multiple WebSocket connections by ID
- Handles connection creation, updates, and cleanup
- Supports broadcasting updates to connected clients
Implements observability and monitoring:
GenAIOTel Class:
- Custom telemetry wrapper for AI operations
- Semantic mapping for telemetry attributes
- OpenTelemetry integration with Azure Monitor
Features:
- Span tracing for operations
- Attribute mapping and normalization
- Azure Monitor integration for production telemetry
api/
├── agent/ # Agent management and execution system
├── voice/ # Voice processing and realtime communication
├── tests/ # Test suite for API components
├── main.py # FastAPI application entry point
├── model.py # Data models and type definitions
├── connection.py # WebSocket connection management
├── telemetry.py # Observability and telemetry
├── requirements.txt # Python dependencies
└── Dockerfile # Container configuration
Key dependencies include:
- FastAPI: Modern web framework for APIs
- OpenAI: Azure OpenAI and Realtime API integration
- Azure SDK: Storage, Cosmos DB, AI Projects integration
- Prompty: AI prompt management and execution
- OpenTelemetry: Observability and tracing
- WebSockets: Real-time communication
- Pydantic: Data validation and serialization
Required environment variables:
AZURE_VOICE_ENDPOINT: Azure OpenAI voice service endpointAZURE_VOICE_KEY: Azure OpenAI API keyCOSMOSDB_CONNECTION: Cosmos DB connection stringSUSTINEO_STORAGE: Azure Storage account URLFOUNDRY_CONNECTION: Azure AI Foundry connectionLOCAL_TRACING_ENABLED: Enable local telemetry tracing
The API serves as the backend for the Sustineo application, providing:
- Voice interaction capabilities through Azure OpenAI Realtime API
- AI agent management and execution
- Real-time WebSocket communication
- Data persistence through Azure services
- Comprehensive telemetry and monitoring
- Install dependencies:
pip install -r requirements.txt - Set required environment variables
- Run the application:
uvicorn main:app --reload - Access API documentation at
http://localhost:8000/docs