bodhi-realtime-agent / VoiceSession
Class: VoiceSession
Defined in: core/voice-session.ts:137
Top-level integration hub that wires all framework components together.
Manages the full lifecycle of a real-time voice session:
- Audio fast-path: Client audio → LLM (and back) without touching the EventBus.
- Tool routing: Inline tools execute synchronously; background tools hand off to subagents.
- Agent transfers: Intercepts
transfer_to_agenttool calls and delegates to AgentRouter. - Reconnection: Handles GoAway signals and unexpected disconnects via session resumption.
- Conversation tracking: Transcriptions populate ConversationContext automatically.
Example
const session = new VoiceSession({
sessionId: 'session_1',
userId: 'user_1',
apiKey: process.env.GOOGLE_API_KEY,
agents: [mainAgent, expertAgent],
initialAgent: 'main',
port: 9900,
model: google('gemini-2.5-flash'),
});
await session.start();Constructors
Constructor
new VoiceSession(
config):VoiceSession
Defined in: core/voice-session.ts:184
Parameters
config
Returns
VoiceSession
Properties
conversationContext
readonlyconversationContext:ConversationContext
Defined in: core/voice-session.ts:140
eventBus
readonlyeventBus:EventBus
Defined in: core/voice-session.ts:138
hooks
readonlyhooks:HooksManager
Defined in: core/voice-session.ts:141
sessionManager
readonlysessionManager:SessionManager
Defined in: core/voice-session.ts:139
Accessors
workspace
Get Signature
get workspace():
object
Defined in: core/voice-session.ts:605
Workspace API for persisting artifacts (images, videos, docs, etc.) produced by agents/tools. When no artifactStore is configured, saveArtifact returns null without persisting.
Returns
object
saveArtifact()
saveArtifact(
params):Promise<ArtifactRef|null>
Parameters
params
Returns
Promise<ArtifactRef | null>
Methods
close()
close(
_reason?):Promise<void>
Defined in: core/voice-session.ts:625
Gracefully shut down: disconnect Gemini, stop the WebSocket server, transition to CLOSED.
Parameters
_reason?
string = 'normal'
Returns
Promise<void>
feedAudioFromClient()
feedAudioFromClient(
data):void
Defined in: core/voice-session.ts:1236
Feed client audio into the session (LLM + STT). Used when the server owns the socket (multi-user).
Parameters
data
Buffer
Returns
void
feedJsonFromClient()
feedJsonFromClient(
message):void
Defined in: core/voice-session.ts:1241
Feed client JSON (text_input, file_upload, etc.) into the session. Used when the server owns the socket.
Parameters
message
Record<string, unknown>
Returns
void
getSessionId()
getSessionId():
string
Defined in: core/voice-session.ts:1256
Session ID for logging and multi-user association.
Returns
string
notifyBackground()
notifyBackground(
text,options?):void
Defined in: core/voice-session.ts:534
Queue a short spoken update for the user. Delivered immediately when possible, otherwise after the current turn.
Parameters
text
string
options?
label?
"SUBAGENT UPDATE" | "SUBAGENT QUESTION"
priority?
"normal" | "high"
Returns
void
notifyClientConnected()
notifyClientConnected():
void
Defined in: core/voice-session.ts:1246
Notify the session that the client connected. Used when the server owns the socket (multi-user).
Returns
void
notifyClientDisconnected()
notifyClientDisconnected():
void
Defined in: core/voice-session.ts:1251
Notify the session that the client disconnected. Used when the server owns the socket (multi-user).
Returns
void
start()
start():
Promise<void>
Defined in: core/voice-session.ts:547
Start the client WebSocket server and connect to the LLM transport.
Returns
Promise<void>
transfer()
transfer(
toAgent):Promise<void>
Defined in: core/voice-session.ts:666
Transfer the active session to a different agent (reconnects with new config).
Parameters
toAgent
string
Returns
Promise<void>