Agent
A voice agent: instructions plus tools, optional sub-agents, and call-control behavior. Subclass it and decorate methods as tools, give it a Pipeline, then register it withserve and start calls against it with invoke - the
serving worker runs each call in an AgentSession. Within a live call,
this.session resolves to the current AgentSession.
Constructor
The system prompt / instructions for the agent.
Tools the agent exposes to its model. Defaults to none.
Display name. Defaults to the agent’s id.
Stable agent id. Defaults to the class name.
The Pipeline this agent runs on. Defaults to
null.Maximum call duration in seconds, or
null for no limit. Defaults to null.MCP servers to attach. Defaults to none.
Whether the agent inherits conversation context on handoff. Defaults to
false.Suffix appended to instructions to steer voice/style, or
null. Defaults to null.Whether AgentOptions.voiceSuffix is appended. Defaults to
true.Sub-agents available for handoff via
agentSwitch. Defaults to none.Context-window policy for trimming conversation history. Defaults to
null.addServer
captureFrames
numOfFrames
Number of most-recent frames to return. Defaults to
1.cleanup
closeEmitter
emit
hangup
initializeMcp
interrupt
ctx.session.interrupt(...).
listenerCount
off
on
once
onEnter
onExit
playBackgroundAudio
volume
Playback volume 0.0-1.0. Defaults to
1.0.looping
Whether to loop the clip. Defaults to
false.overrideThinking
Whether this clip overrides any thinking audio. Defaults to
true.preloadBackgroundAudio
volume
Playback volume 0.0-1.0. Defaults to
1.0.registerA2a
registerTools
removeAllListeners
reply
instructions, then speak it.
No-op when no session is active. Also reachable as ctx.session.reply(...).
say
message through the pipeline’s text-to-speech (no model call).
No-op when no session is active. Also reachable as ctx.session.say(...).
setThinkingAudio
file to clear it.
volume
Playback volume 0.0-1.0. Defaults to
0.3.stopBackgroundAudio
unregisterA2a
updateTools
tools.
AgentSession
Create an AgentSession foragent running on pipeline.
Low-level constructor used internally by serve for each dispatched session.
Prefer serve + invoke; call this directly only when building a
custom worker that manages sessions itself.
Constructor
Inactivity timeout in seconds after which the agent proactively wakes the user
(requires an
onWakeUp handler), or null to disable. Defaults to null.Maximum number of wake-up attempts before ending the call, or
null for unlimited. Defaults to null.Background audio to play during the call (config object, URL, or path). Defaults to
null.Handler for incoming DTMF (touch-tone) digits. Defaults to the pipeline’s, else
null.Voicemail detector. Defaults to the pipeline’s, else
null.Recording configuration applied to the session. Defaults to
null.activeAgent
addShutdownCallback
callTransfer
Auth token for the transfer.
Destination to transfer to; ignored if empty.
cancelGeneration
changePipeline
New pipeline mode (e.g. ‘cascade’, ‘hybrid_stt’).
Array of [component, provider, params] triples to reconfigure.
clearContext
keepSystemPrompt (default true),
the agent’s instructions are kept and only the turns are cleared.
Whether the clear was applied.
close
onExit, fire shutdown callbacks, disconnect, and clean up.
closeEmitter
contextToAnthropic
contextToDict
contextToGoogle
contextToOpenai
emit
fetchChatContext
fetchContextHistory
generate
text (spoken via the pipeline).
getContextHistory
await it to
fetch the latest from the live session.
handoffs
hangup
reason
injectContext
true only if all succeeded.
injectMessage
message
| ChatMessage | { role: ChatRole | string; content: string; messageId?: string; images?: ImageContent[] }
required
true if the live session accepted the message.interceptToolResult
interrupt
lastHandoffReason
'' if none.
leave
'sdk_leave').
listenerCount
off
on
once
playBackgroundAudio
config may be a URL/path string or a config object
with file_url/volume/looping. Set enabled: false to skip.
preloadBackgroundAudio
config as playBackgroundAudio.
publishMessage
topic to other participants/agents.
config
{ topic: string; message?: unknown; options?: Record<string, unknown> | null; payload?: unknown; }
required
pushAudioFrame
sampleRate
Sample rate of the PCM data in Hz. Defaults to
48000.registerHandoffAgent
removeAllListeners
removeMessage
true if the message was removed, false otherwise.reply
instructions, optionally grounded on image frames.
opts
{ waitForPlayback?: boolean; // eslint-disable-next-line @typescript-eslint/no-explicit-any frames?: any[]; latestFrames?: number; interruptible?: boolean; }
A handle to await or interrupt the utterance.
say
message verbatim via TTS.
opts
{ interruptible?: boolean; voice?: string; // eslint-disable-next-line @typescript-eslint/no-explicit-any audioData?: any; addToChatContext?: boolean; // eslint-disable-next-line @typescript-eslint/no-explicit-any [k: string]: any; }
A handle to await or interrupt the utterance.
sendA2A
targetAgentId.
A2A is delivered over pub/sub (topic a2a/<targetAgentId>): the message is published
as a JSON envelope { source_agent_id, message_json, correlation_id }.
The receiving agent must have called subscribeA2A to receive it (surfaced as an
a2a_message event).
correlationId
sendImage
mimeType
MIME type for raw bytes. Defaults to
'image/jpeg'.sendMessageWithFrames
Frames as
[bytes, mime] tuples, captured vision frames, or raw bytes.setUserInputEnabled
start
startRecording
Recording config; falls back to the session-level
recording= if omitted.startThinkingAudio
agent.setThinkingAudio).
stopBackgroundAudio
stopRecording
stopThinkingAudio
subscribeA2A
a2a_message events.
subscribePubSub
topic. The optional callback fires for matching messages.
callback
(msg: { topic: string; message: string; sender_id: string; sender_name: string; timestamp: string; payload: unknown; }) => void
The registered handler (or
null) so it can later be removed via
session.off('pubsub_message', handler).summarizeContext
updateAgentState
agent_state_changed.
updateContextWindow
updateInstructions
updateInterruptConfig
opts
{ mode?: string; interruptMinDuration?: number; interruptMinWords?: number; cooldownMs?: number; falseInterruptPauseDurationMs?: number; resumeOnFalseInterrupt?: boolean; }
updateProvider
Component to update (e.g.
'stt', 'llm', 'tts').New provider identifier.
Optional provider parameters. Defaults to
null.updateRecordingState
recording_status_changed.
updateTools
updateUserState
user_state_changed (and speech_in when speaking).
waitForParticipantArrived
waitForSynthesisDone
Optional timeout in seconds.
true if synthesis completed, false if the timeout elapsed first.warmTransfer
agentSwitch(...) for multi-agent handoff. Always throws.
serve
options.agentId (or the agent’s own id) and runs until the
process receives a shutdown signal, starting a new AgentSession for
each dispatched session. Pair with invoke to start sessions against the
registered agent.
One of: a configured Agent instance; a zero-arg
Agent subclass (the class itself, e.g.
serve(MyAgent)); or an
AgentFactory returning an Agent. A class or factory yields a fresh
Agent + Pipeline per call - required for correct per-call state and pipeline
hooks under concurrent calls. A shared instance is still accepted for simple,
stateless agents. In every case the agent must carry a pipeline and an id.Registration, capacity, and debug settings. See ServeOptions.
invoke
agentId (the id you passed to
serve), gives it a room (auto-created when none is supplied) plus any
SIP and per-call config, and returns the new session’s ids.
The id the target agent registered with via serve.
Room, SIP, routing, and timeout settings. See InvokeOptions.
The started session’s ids and an optional playground URL.
Room
Create a Room config for invoke.Constructor
Existing room to join. When omitted, a room is auto-created.
ZRT auth token. Falls back to
ZRT_AUTH_TOKEN / ZRT_API_KEY + ZRT_SECRET_KEY.Display name for the agent participant. Defaults to the
agentId.Whether to return a playground URL in the result. Defaults to
true.Enable video/vision input. Defaults to
false.Enable session recording. Defaults to
false.Enable background audio. Defaults to
false.Enable the audio listener. Defaults to
false.End the session automatically on completion. Defaults to
true.Maximum session length in seconds; truncated to an integer. Defaults to
15; pass null to omit.Seconds to wait with no participant before ending; truncated to an integer. Defaults to
90; pass null to omit.Fixed participant id for the agent. Defaults to assigned automatically.
Base URL of the signaling service. Defaults to the standard endpoint.
Forward session logs to the dashboard. Defaults to
true.Minimum dashboard log level (
DEBUG/INFO/WARNING/ERROR/CRITICAL). Defaults to 'INFO'.Sip
Create a Sip config for invoke.Constructor
Destination phone number / SIP URI.
Caller phone number / SIP URI.
Call direction, e.g.
'inbound' or 'outbound'.Caller-supplied unique call identifier.
Webhook URL to notify about call events.
Extra key/value metadata merged into the call’s dispatch metadata.