A production-grade, object-oriented framework for orchestrating stateful, multi-modal AI agents using Google Gemini 2.5 Flash Native Audio. This system is designed to demonstrate advanced software engineering patterns including hexagonal architecture, asynchronous concurrency, and strict type safety.
Kura-Next provides a robust engine for building voice-first applications. It decouples the core agent logic from the input/output transport, allowing the same agent definitions to operate over CLI, WebSockets, or Telephony (Twilio) interfaces.
- Native Audio Integration: Utilizes Gemini 2.5 Flash's native audio modalities for sub-500ms latency interactions.
- Event-Driven Architecture: Built on Python's
asyncioevent loop for high-performance non-blocking I/O. - Hexagonal Design: Strict separation of concerns using Ports and Adapters patterns.
- Stateful Context Management: Hierarchical state tracking (Global, Session, User) with persistence.
- VUI Optimization: Implements latency masking (filler audio), warm agent handoffs, and background intervention detection.
- Type Safety: 100% type-hinted codebase verified with
mypy.
The system is composed of the following layers:
- Orchestrator: The central kernel that manages the event loop and signal routing.
- Agents: Autonomous units encapsulating business logic and tools.
- Infrastructure: Adapters for external services (LLM, Database, Twilio).
- Interfaces: Abstractions for input/output streams.
- Python 3.11 or higher
- Google Cloud Project with Gemini API access
- Twilio Account (for telephony integration)
- PostgreSQL (Production) or SQLite (Development)
-
Clone the repository
git clone https://github.com/your-repo/agent-framework.git cd AgentFramework -
Initialize the virtual environment
python -m venv venv source venv/bin/activate # Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
Configuration is managed via environment variables. Create a .env file in the project root:
# AI Configuration
GOOGLE_API_KEY=your_google_api_key
GEMINI_MODEL=gemini-2.0-flash-exp
# Database Configuration
# For SQLite (Development):
DATABASE_URL=sqlite+aiosqlite:///./data/kura.db
# For PostgreSQL (Production):
# DB_HOST=aws-0-us-east-1.pooler.supabase.com
# DB_USER=postgres
# DB_PASSWORD=your_password
# DB_PORT=5432
# DB_NAME=postgres
# Telephony Configuration (Optional)
TWILIO_ACCOUNT_SID=your_sid
TWILIO_AUTH_TOKEN=your_token
TWILIO_PHONE_NUMBER=+15550000000
# Server Settings
SERVER_HOST=0.0.0.0
SERVER_PORT=8080
ENVIRONMENT=development
LOG_LEVEL=INFOFor rapid prototyping and logic verification without telephony overhead:
python -m src.main --cliStarts the FastAPI server to handle WebSocket connections and Twilio webhooks:
python -m src.mainThe server exposes the following endpoints:
POST /twilio/voice: Webhook for incoming Twilio calls.WS /ws/audio: General-purpose WebSocket for web clients.
src/
├── framework/ # Core engine (Orchestrator, Context, Signals)
│ ├── core/
│ └── interfaces/
├── infrastructure/ # Adapters (Gemini, SQLAlchemy)
├── client/ # Reference Implementation (TaskMaster)
│ ├── agents/ # Domain-specific agents
│ └── tools/ # Tool definitions
├── server/ # FastAPI application
└── main.py # Entry point
- Code Style: Adheres to PEP 8. formatted via
ruff. - Type Checking: Strict typing enforced via
mypy. - Testing: Unit and integration tests using
pytest.
To run the test suite:
pytest tests/ -v