Agent Studio

Architecture Overview

High-level system architecture of Agent Studio

Architecture Overview

Agent Studio follows a clean architecture pattern with clear separation between domain logic, infrastructure, and presentation layers.

System Diagram

┌─────────────────────────────────────────────────────────────────────────────┐
│                              CLIENTS                                         │
│                    Dashboard (Next.js) │ API Consumers                       │
└─────────────────────────────────────────────────────────────────────────────┘


┌─────────────────────────────────────────────────────────────────────────────┐
│                           API LAYER (FastAPI)                                │
│  ┌───────────┐ ┌───────────┐ ┌───────────┐ ┌───────────┐ ┌───────────┐    │
│  │   Auth    │ │  Agents   │ │ Workflows │ │   Tools   │ │   Calls   │    │
│  │  Router   │ │  Router   │ │  Router   │ │  Router   │ │  Router   │    │
│  └───────────┘ └───────────┘ └───────────┘ └───────────┘ └───────────┘    │
│                           │                                                  │
│                  ┌────────┴────────┐                                        │
│                  │   Middleware    │                                        │
│                  │  Rate Limit │ Auth │ Logging                             │
│                  └─────────────────┘                                        │
└─────────────────────────────────────────────────────────────────────────────┘

                    ┌───────────────┼───────────────┐
                    ▼               ▼               ▼
┌─────────────────────────┐ ┌─────────────┐ ┌─────────────────────────┐
│      CORE DOMAIN        │ │   WORKER    │ │      PROVIDERS          │
│  ┌─────────────────┐    │ │  (LiveKit)  │ │  ┌─────────────────┐    │
│  │ Workflow Runner │    │ │             │ │  │  STT: Deepgram  │    │
│  │ Tool Executor   │    │ │  Handles    │ │  │       Sarvam    │    │
│  │ Context Manager │    │ │  Voice      │ │  ├─────────────────┤    │
│  │ Handoff Logic   │    │ │  Sessions   │ │  │  TTS: Cartesia  │    │
│  └─────────────────┘    │ │             │ │  │       Sarvam    │    │
└─────────────────────────┘ └─────────────┘ │  ├─────────────────┤    │
                                            │  │  LLM: Gemini    │    │
                                            │  │       OpenAI    │    │
                                            │  └─────────────────┘    │
                                            └─────────────────────────┘


┌─────────────────────────────────────────────────────────────────────────────┐
│                         DATA LAYER                                           │
│     ┌─────────────┐          ┌─────────────┐          ┌─────────────┐       │
│     │ PostgreSQL  │          │    Redis    │          │   LiveKit   │       │
│     │ (Primary)   │          │  (Cache)    │          │  (WebRTC)   │       │
│     └─────────────┘          └─────────────┘          └─────────────┘       │
└─────────────────────────────────────────────────────────────────────────────┘

Component Responsibilities

API Layer (src/agent_studio/api/)

  • HTTP request handling
  • Authentication (JWT + API Keys)
  • Rate limiting
  • Request validation
  • OpenAPI documentation

Core Domain (src/agent_studio/core/)

  • Business logic (no framework dependencies)
  • Workflow orchestration
  • Tool execution engine
  • Context management
  • Handoff detection

Providers (src/agent_studio/providers/)

  • STT/TTS/LLM/VAD abstractions
  • Registry pattern for provider management
  • BYOK credential handling

Worker (src/agent_studio/worker/)

  • LiveKit agent process
  • Voice session management
  • Real-time audio streaming

Database (src/agent_studio/db/)

  • SQLAlchemy ORM models
  • Repository pattern
  • Alembic migrations

Request Flow

API Request

  1. Request hits FastAPI router
  2. Middleware processes (auth, rate limit, logging)
  3. Dependency injection provides services
  4. Business logic executes
  5. Response returned

Voice Call Flow

  1. Call initiated via API
  2. LiveKit room created with metadata
  3. Worker picks up job
  4. Workflow runner builds agents
  5. Agents execute with handoffs
  6. Call ends, results persisted

Deployment Topology

┌──────────────────────────────────────────────────────────────┐
│                      Load Balancer                            │
└──────────────────────────────────────────────────────────────┘

              ┌───────────────┼───────────────┐
              ▼               ▼               ▼
        ┌──────────┐    ┌──────────┐    ┌──────────┐
        │ API Pod  │    │ API Pod  │    │ API Pod  │
        │ (FastAPI)│    │ (FastAPI)│    │ (FastAPI)│
        └──────────┘    └──────────┘    └──────────┘
              │               │               │
              └───────────────┼───────────────┘

        ┌──────────────────────────────────────────┐
        │              Worker Pool                  │
        │  ┌────────┐  ┌────────┐  ┌────────┐     │
        │  │Worker 1│  │Worker 2│  │Worker N│     │
        │  └────────┘  └────────┘  └────────┘     │
        └──────────────────────────────────────────┘

              ┌───────────────┼───────────────┐
              ▼               ▼               ▼
        ┌──────────┐    ┌──────────┐    ┌──────────┐
        │PostgreSQL│    │  Redis   │    │ LiveKit  │
        │ (Primary)│    │ Cluster  │    │  Server  │
        └──────────┘    └──────────┘    └──────────┘

On this page