Skip to content

bodhi-realtime-agent / VoiceSession

Class: VoiceSession

Defined in: core/voice-session.ts:103

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_agent tool calls and delegates to AgentRouter.
  • Reconnection: Handles GoAway signals and unexpected disconnects via session resumption.
  • Conversation tracking: Transcriptions populate ConversationContext automatically.

Example

ts
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:132

Parameters

config

VoiceSessionConfig

Returns

VoiceSession

Properties

conversationContext

readonly conversationContext: ConversationContext

Defined in: core/voice-session.ts:106


eventBus

readonly eventBus: EventBus

Defined in: core/voice-session.ts:104


hooks

readonly hooks: HooksManager

Defined in: core/voice-session.ts:107


sessionManager

readonly sessionManager: SessionManager

Defined in: core/voice-session.ts:105

Methods

close()

close(_reason): Promise<void>

Defined in: core/voice-session.ts:465

Gracefully shut down: disconnect Gemini, stop the WebSocket server, transition to CLOSED.

Parameters

_reason

string = 'normal'

Returns

Promise<void>


notifyBackground()

notifyBackground(text, options?): void

Defined in: core/voice-session.ts:412

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


start()

start(): Promise<void>

Defined in: core/voice-session.ts:425

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:503

Transfer the active session to a different agent (reconnects with new config).

Parameters

toAgent

string

Returns

Promise<void>

Built with VitePress