VoiceAgentClient manages a full-duplex WebSocket for real-time conversations. It handles microphone capture, audio playback, STT, LLM, TTS, and interruptions.
Basic usage
- JavaScript (browser)
- Python
Running a dashboard agent
PassagentId to run an agent you built in the dashboard, with its prompt, voice, language, tools, knowledge base and integrations. prompt, voice and language are then optional, and the SDK sends them only if you set them, as overrides for this session.
agentId that is not on your account the server refuses the handshake with 404 agent.not_found; a browser sees only a failed connection (ws.close).
Options
Events
Methods
connected and generation read-only properties, and onAudio(cb) / onVisemes(cb) as shorthand for on('audio', cb) / on('visemes', cb). Full signatures are in the JavaScript API Reference.
Status flow
Reconnection
The client reconnects only when the connection drops or the server goes away (WebSocket close codes 1001, 1006, 1011–1014): exponential backoff 2s → 4s → 8s → cap at 10s, max 5 attempts, statusreconnecting meanwhile. Each reconnection is a new server session — the conversation starts over — and reuses the running microphone.
When the server closes the session on purpose — 1000 when the agent ends the call, 1008 when a limit is reached, 4xxx for other application reasons — the client does not reconnect. It fires error with a LokutorError of code session.ended whose message is the server’s reason, then status disconnected and the ended event. (Before 1.5.0 it reconnected into a fresh session instead.)
Starting a call on a phone
Ask for the microphone inside the tap that starts the call, withrequestMicrophone(), and pass the result to BrowserAudioManager as microphone (see the JavaScript reference). Asked for later — after the connection opens — iOS Safari can refuse it without showing its prompt, and in the audio session’s 'playback' mode it always does. If the microphone cannot start, connect() rejects with code audio.microphone_unavailable and the session is closed rather than left talking to nobody.
Keeping the screen on
In the browser,BrowserAudioManager keeps the screen awake while the microphone is live (Screen Wake Lock), the way a video player does: a phone that dims and locks mid-call suspends the page’s microphone and audio. The lock is taken again when the page returns to the foreground and released when the call ends. Pass keepAwake: false to manage this yourself.