VideoSDK AI Agents Documentation
repository·main·Indexed 20 days ago
https://github.com/videosdk-live/agentsAn 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.
What's inside VideoSDK AI Agents
- 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.
Use LangChain and LangGraph in VideoSDK voice pipelines
mainThe VideoSDK LangChain Plugin allows you to integrate the LangChain ecosystem into your AI Agent's voice pipeline. You can use any LangChain-compatible LLM or a compiled LangGraph graph as the core LLM component in your pipeline.Implement Agent-to-Agent (A2A) Coordination
mainThe 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
- Create an orchestrator using
asyncio.create_taskto run multiple agent sessions (e.g., aCustomerServiceAgentand aLoanAgent) in the same room. - Use A2A registration so agents can delegate tasks to one another (e.g., the general agent delegates a loan query to the specialist agent).
How Pipeline Modes work in VideoSDK AI Agents
mainAll agents are constructed using a single
Pipelineclass. Depending on which components (STT, LLM, TTS, VAD, etc.) you provide to thePipelineconstructor, the framework automatically selects one of three execution modes:- 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). - 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).
- 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)- Cascade Mode: A traditional chain of
Use common patterns in videosdk-agents
mainFollow these patterns for consistent development:
- Tool Definition: Use the
@function_tooldecorator on standalone functions or agent methods to make them available to the LLM. - Event-Driven Architecture: All components extend
EventEmitter. Always listen for the"error"event to handle failures gracefully. - Async Lifecycle: Always implement
async aclose()in your components to ensure proper resource cleanup. - Realtime Models: If using speech-to-speech models (like OpenAI Realtime or Gemini Live), inherit from
RealtimeBaseModel. ThePipelinewill automatically wrap these in aRealtimeLLMAdapter.
@function_tool def my_agent_tool(param: str): """Docstring for the tool""" return f"Processed {param}"- Tool Definition: Use the
Key Framework Conventions
mainWhen 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, andRealtimeBaseModelare located invideosdk.agents. - Tool Definition: Use the
@function_tooldecorator 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.
Understand VideoSDK AI Agent Pipeline Modes
mainThe
Pipelineclass 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:- 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). - Realtime Mode: Uses a single, unified speech-to-speech model (such as OpenAI Realtime, Gemini Live, or Nova Sonic) to minimize latency.
- 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.
- Cascade Mode: A traditional sequential pipeline following the flow:
Important considerations for OpenAILLM and OpenAIRealtime
mainWhen 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
developerrole instead of the standardsystemrole. - Uses
max_completion_tokensinstead ofmax_tokens. - Gates
temperatureandtop_pparameters (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.
- Uses the
How the VideoSDK Plugin System works
mainThe 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
Pipelineconfiguration; no other code changes are required.Pipeline Modes
- 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).
- 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.
- 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() )Understand the Voice Blog Writer LangGraph pipeline
mainThe 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:
coordinator→planner→write_sections(consisting of 4 sequential Gemini calls) →compiler→synthesizer.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")- File Generation: The final blog is saved in the local directory with the format
How Silero VAD works in the framework
mainSilero 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).Understand N8N Workflow Nodes for VideoSDK Telephony
mainThe 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-answeredorcall-hangup) from VideoSDK to allow the workflow to react when a call concludes.