VideoSDK AI Agents Documentation

repository·main·Indexed 20 days ago

https://github.com/videosdk-live/agents

An open-source Python framework for building real-time, low-latency voice and multimodal AI agents that participate in VideoSDK video meetings. The framework abstracts audio/video streaming, STT/LLM/TTS orchestration, and turn detection, supporting Cascade, Realtime, and Hybrid pipeline modes. It includes capabilities for custom Agent classes, function tools via @function_tool, and integration with tools like LangGraph and Slack.

Tokens
37.3K
Snippets
163
Records
240
Agent score
68%

What's inside VideoSDK AI Agents

  1. Overview of VideoSDK AI Agents

    main
    VideoSDK AI Agents is an open-source Python framework for building real-time voice and multimodal AI agents. These agents join VideoSDK rooms as participants, allowing them to listen, speak, and interact live in meetings. The framework automates the complex parts of the agent lifecycle, including audio streaming, turn detection, Voice Activity Detection (VAD), interruptions, and media routing.
  2. Implement Agent-to-Agent (A2A) Coordination

    main

    The Agent-to-Agent (A2A) protocol allows multiple agents to coordinate and interact within the same room. An orchestrator can manage multiple agent sessions concurrently.

    Key Functions

    • register_a2a(): Registers an agent for discovery by other agents.
    • unregister_a2a(): Removes an agent from discovery.

    Workflow

    1. Create an orchestrator using asyncio.create_task to run multiple agent sessions (e.g., a CustomerServiceAgent and a LoanAgent) in the same room.
    2. Use A2A registration so agents can delegate tasks to one another (e.g., the general agent delegates a loan query to the specialist agent).
  3. How Pipeline Modes work in VideoSDK AI Agents

    main

    All agents are constructed using a single Pipeline class. Depending on which components (STT, LLM, TTS, VAD, etc.) you provide to the Pipeline constructor, the framework automatically selects one of three execution modes:

    1. Cascade Mode: A traditional chain of STT → LLM → TTS. This is best when you need specific control over each stage (e.g., a specific STT provider or a custom TTS voice).
    2. Realtime Mode: Uses a single unified realtime model (like Gemini Live or OpenAI Realtime) for the entire pipeline. This offers the lowest latency (sub-500ms).
    3. Hybrid Mode: A mix of the two. You can use an external STT with a Realtime LLM, or a Realtime LLM with a custom external TTS.

    By passing components into the Pipeline, the framework handles the wiring and optimal execution automatically.

    # Example of Cascade Mode
    async def start_session(context: JobContext):
        pipeline = Pipeline(
            stt=DeepgramSTT(),
            llm=GoogleLLM(),
            tts=CartesiaTTS(),
            vad=SileroVAD(),
            turn_detector=TurnDetector(),
        )
        session = AgentSession(agent=MyAgent(), pipeline=pipeline)
        await session.start(wait_for_participant=True, run_until_shutdown=True)
    
    # Example of Realtime Mode
    async def start_session(context: JobContext):
        pipeline = Pipeline(
            llm=GeminiRealtime(
                model="gemini-3.1-flash-live-preview",
                config=GeminiLiveConfig(voice="Leda", response_modalities=["AUDIO"]),
            )
        )
        session = AgentSession(agent=MyAgent(), pipeline=pipeline)
        await session.start(wait_for_participant=True, run_until_shutdown=True)
  4. Use common patterns in videosdk-agents

    main

    Follow these patterns for consistent development:

    1. Tool Definition: Use the @function_tool decorator on standalone functions or agent methods to make them available to the LLM.
    2. Event-Driven Architecture: All components extend EventEmitter. Always listen for the "error" event to handle failures gracefully.
    3. Async Lifecycle: Always implement async aclose() in your components to ensure proper resource cleanup.
    4. Realtime Models: If using speech-to-speech models (like OpenAI Realtime or Gemini Live), inherit from RealtimeBaseModel. The Pipeline will automatically wrap these in a RealtimeLLMAdapter.
    @function_tool
    def my_agent_tool(param: str):
        """Docstring for the tool"""
        return f"Processed {param}"
  5. Key Framework Conventions

    main

    When building with or extending the VideoSDK AI Agents framework, adhere to these technical conventions:

    • Python Version: Requires Python $\ge$ 3.11; Python 3.12+ is recommended.
    • Plugin Namespacing: All plugins are packaged under the videosdk.plugins.* namespace.
    • Base Classes: Core abstractions for STT, LLM, TTS, VAD, EOU, and RealtimeBaseModel are located in videosdk.agents.
    • Tool Definition: Use the @function_tool decorator to define both internal and external tools for the agent.
    • Pipeline Hooks: Use the @pipeline.on("event_name") decorator pattern to intercept pipeline stages. Supported event names include "stt", "llm", "tts", and others.
  6. Understand VideoSDK AI Agent Pipeline Modes

    main

    The Pipeline class is the central orchestration component of the VideoSDK AI Agents framework. It automatically detects and operates in one of three modes based on the components you provide:

    1. Cascade Mode: A traditional sequential pipeline following the flow: VAD → STT → Turn Detector → LLM → TTS. This mode is ideal for mixing and matching different providers (e.g., using AssemblyAI for STT and Anthropic for LLM).
    2. Realtime Mode: Uses a single, unified speech-to-speech model (such as OpenAI Realtime, Gemini Live, or Nova Sonic) to minimize latency.
    3. Hybrid Mode: A combination of Cascade and Realtime modes. Common patterns include:
      • External STT + Realtime LLM: Using a specialized STT provider followed by a realtime model.
      • Realtime LLM + External TTS: Using a realtime model for intelligence followed by a specialized TTS provider for voice quality.
  7. Important considerations for OpenAILLM and OpenAIRealtime

    main

    When using the OpenAI plugin, be aware of the following technical behaviors:

    OpenAILLM (Reasoning & GPT-5 Models)

    For GPT-5 and reasoning models (o-series), the plugin applies specific logic:

    • Uses the developer role instead of the standard system role.
    • Uses max_completion_tokens instead of max_tokens.
    • Gates temperature and top_p parameters (as they may not be supported by reasoning models).

    OpenAIRealtime

    • Connects via WebSocket to wss://api.openai.com/v1/realtime.
    • Supports both text and audio modalities.

    OpenAISTT

    • Operates at 16kHz. The framework automatically handles resampling from the standard 48kHz.
  8. How the VideoSDK Plugin System works

    main

    The VideoSDK AI Agents framework uses a plug-and-play architecture where third-party AI services are integrated via interchangeable plugin packages.

    Core Concept

    Plugins implement base classes for specific roles in an AI pipeline. You can swap providers (e.g., switching from OpenAI to Anthropic) by simply changing the class you instantiate in your Pipeline configuration; no other code changes are required.

    Pipeline Modes

    1. Cascade Mode: Requires exactly 5 components: STT (Speech-to-Text) + LLM (Large Language Model) + TTS (Text-to-Speech) + VAD (Voice Activity Detection) + Turn Detector (End-of-Utterance).
    2. Realtime Mode: Uses a single unified speech-to-speech model (e.g., Gemini Realtime or OpenAI Realtime), eliminating the need for separate STT/TTS/VAD components.
    3. Hybrid Mode: Combines a Realtime LLM (for understanding) with an external TTS (for branded or high-quality custom voices).
    # Cascade Mode Example
    from videosdk.agents import Pipeline
    from videosdk.plugins.deepgram import DeepgramSTT
    from videosdk.plugins.openai import OpenAILLM
    from videosdk.plugins.elevenlabs import ElevenLabsTTS
    from videosdk.plugins.silero import SileroVAD
    from videosdk.plugins.turn_detector import TurnDetector
    
    pipeline = Pipeline(
        stt=DeepgramSTT(),
        llm=OpenAILLM(),
        tts=ElevenLabsTTS(),
        vad=SileroVAD(),
        turn_detector=TurnDetector()
    )
  9. Understand the Voice Blog Writer LangGraph pipeline

    main

    The Voice Blog Writer operates using a LangGraph pipeline that transitions through several stages once the user provides the Topic, Audience, and Tone.

    Graph Workflow

    The execution flow follows this sequence: coordinatorplannerwrite_sections (consisting of 4 sequential Gemini calls) → compilersynthesizer.

    Output and Behavior

    • File Generation: The final blog is saved in the local directory with the format {title-slug}_{datetime}.md.
    • TTS Control: By using LangGraphLLM(output_node="synthesizer_node"), the agent ensures that only the final spoken line from the synthesizer reaches the Text-to-Speech (TTS) engine, preventing intermediate graph steps from being spoken aloud.
    # Example of controlling which node's output is sent to TTS
    LangGraphLLM(output_node="synthesizer_node")
  10. How Silero VAD works in the framework

    main
    Silero VAD acts as a signal processor within the AI Agent pipeline. It utilizes ONNX Runtime for efficient model inference on audio streams. The architecture follows a pattern where audio frames are fed into the model, which then evaluates the presence of speech based on configured thresholds and durations, triggering lifecycle events (start_of_speech / end_of_speech) that drive the rest of the agent's pipeline (e.g., triggering an LLM response).
  11. Understand N8N Workflow Nodes for VideoSDK Telephony

    main

    The pre-built N8N workflow (customer_followup_agent.json) consists of three core functional nodes:

    • MCP Server Trigger: Enables the AI Agent to perform specific operations like fetching or updating data.
    • HTTP POST Request (Calling Customer Node): Initiates the outbound call to the customer via the VideoSDK telephony API.
    • Webhook Trigger (Capturing Call Events): Listens for real-time call events (such as call-answered or call-hangup) from VideoSDK to allow the workflow to react when a call concludes.