Skip to main content

Voice Agents

In plain terms

A voice agent is an agent you talk to out loud — it listens, thinks, and speaks back in real time, like a phone call with a helpful human. Same brain, memory, and tools as a text agent; the only difference is the input and output are speech instead of typing. Picture a hotel front-desk line, a bank’s phone support, or a kiosk at a store — the customer just speaks, and the agent looks things up, takes action, and replies in a natural voice. And because it shares the same memory as your text agents, it remembers the caller from their last visit.
The analogy: if a text agent is live chat, a voice agent is the phone line — same employee, different channel.
Agentium supports real-time voice conversations through the VoiceAgent class. Voice agents connect to speech-to-speech APIs (OpenAI Realtime, Google Gemini Live) over WebSocket, handle audio streaming, tool calling, and persistent user memory — all with the same patterns as regular text agents.
Voice agents use a separate RealtimeProvider interface (not the regular ModelProvider). The realtime API manages its own conversation context within the WebSocket connection.

Quick Start


Architecture

Voice agents have a layered architecture:

VoiceAgent

Orchestrator. Manages the realtime connection, tools, user memory, and session lifecycle.

RealtimeProvider

WebSocket adapter for a specific speech-to-speech API. Translates between Agentium events and the provider’s protocol.

Voice Gateway

Thin Socket.IO relay. Bridges browser audio to VoiceAgent. No business logic.

VoiceAgent Config

string
required
Name of the voice agent.
RealtimeProvider
required
The realtime provider to use. Use the shorthand helpers openaiRealtime() or googleLive(), or instantiate OpenAIRealtimeProvider / GoogleLiveProvider directly.
string
System instructions for the voice agent. User memory facts are automatically appended on connect.
ToolDef[]
Tools the agent can call during a voice conversation. Same defineTool() API as regular agents.
string
Voice to use for speech synthesis (e.g., "alloy", "shimmer", "echo"). Provider-specific.
UserMemory
Cross-session user memory. Facts are loaded into instructions on connect and auto-extracted from transcripts on disconnect.
ModelProvider
LLM model used by UserMemory for auto-extracting facts from conversation transcripts. Required when userMemory is set.
string
Default user ID. Can be overridden per connect() call.
number
Temperature for response generation.
TurnDetectionConfig | null
Server-side voice activity detection config. Set to null to disable.
CostTracker
Shared cost tracker for monitoring token usage and enforcing budgets across voice sessions. Tracks audio input/output tokens automatically from the Realtime API.
string
default:"silent"
Logging level: "debug", "info", "warn", "error", "silent".

connect()

Call connect() to start a voice session:
On connect, the agent:
  1. Loads user facts from UserMemory (if configured) and appends them to instructions
  2. Opens a WebSocket to the realtime provider
  3. Sends session config (instructions, tools, voice, etc.)
  4. Returns a VoiceSession handle

VoiceSession

The session handle returned by connect():

Events


Realtime Providers

OpenAI Realtime

Requires: npm install ws

Google Gemini Live

Requires: npm install @google/genai
Both openaiRealtime() and googleLive() are shorthand helpers that return a RealtimeProvider. They mirror the openai() / google() pattern used for text models. The class exports (OpenAIRealtimeProvider, GoogleLiveProvider) are still available for advanced use.

User Memory in Voice

Voice agents support the same UserMemory as regular agents. The flow:
1

User connects

connect({ userId: "akash" }) loads stored facts and appends them to the agent’s instructions.
2

Conversation happens

The agent knows the user’s name, preferences, etc. from the injected facts.
3

User disconnects

On close() or disconnect, all transcripts are consolidated (small deltas merged into full messages) and sent to the LLM for fact extraction.
4

Facts are stored

New facts are deduplicated and saved. Next time the user connects, they’re automatically loaded.
Voice agents do not use the Memory class (long-term summarization) or SessionManager. The realtime API manages its own conversation context within the WebSocket connection. Only UserMemory persists across sessions.

Tool Calling

Tools work the same as regular agents. When the realtime API detects a tool call intent:
  1. The provider emits a tool_call event
  2. VoiceAgent executes the tool via ToolExecutor
  3. The result is sent back to the provider
  4. The agent speaks the result

Voice Gateway (Socket.IO)

For browser-based voice apps, use the createVoiceGateway from @agentium/transport:
The gateway is a thin relay — it forwards Socket.IO events to the VoiceAgent and streams audio/events back. All memory, session, and tool logic lives in the agent.

Client-Side Events


Cost Tracking

Voice agents support CostTracker for monitoring realtime API token usage:
Each realtime API usage event is automatically tracked — including audio input/output tokens when available. The same tracker can be shared with text and browser agents for unified cost monitoring.

Examples