Agent you
subclass to give it instructions and tools, and the AgentSession that runs it,
speaking, listening, and managing the call lifecycle. serve and invoke register
an agent and start sessions against it.
Agent
What the agent is, what it can do, and how it behaves on a call. Subclass it to give the agent behaviour: methods decorated with@function_tool are registered by the constructor, and the on_* hooks
below are called by the session as the call progresses. An instance is inert
until zeroruntime.serve registers it and a session is started against it.
The pipeline is the other half. This class carries the prompt, the tools and
the call-shaped options; Pipeline carries the providers that hear and
speak.
Constructor
@function_tool callables defined elsewhere. Tools defined as methods on the agent are found on their own, so this is for the ones that are not.MCPServerStdio and MCPServerHTTP whose tools join the agent’s own. Connected on the first call to initialize_mcp, not here.Carry the chat history over when another agent hands off to this one. Off means it starts the conversation fresh.
Seconds of caller silence before the agent nudges. 0 disables it; negative is rejected.
Other agents this one hands off to, kept on
alternates. Nothing registers them for you. Every agent takes its id from ZERORUNTIME_AGENT_ID, so agents in one process share an id and Session.add_handoff cannot tell them apart.How long to wait for one of this agent’s tools to return before handing the model a timeout.
None keeps the default of 30 seconds. Raise it only for an agent whose tools genuinely run long. The case it exists for is a tool that awaits Session.warm_transfer — that runs for supervisor_join_timeout + briefing_timeout, minutes rather than seconds, and the default would kill the round trip while the transfer carried on underneath. The cost is symmetric: a tool that hangs holds the turn for exactly this long.This agent’s
Steps, run in order by the runtime’s workflow engine, or Workflow.from_yaml(...). Its @function_tool methods finish them with complete, and self.workflow.<step> reads the answers. name, instructions, pipeline and workflow can also be set as class attributes, so an agent you hand the call to needs no __init__.register_tools
@function_tool methods off self.
Called by the constructor. Call it again after adding one at runtime.
update_tools
on_enter
Session.set_thinking_audio. A line it
returns is an instruction for the model’s next line. It may take a
reason argument; either way self.handoff_reason is why it has the
call ("call started" for the first).
on_exit
transfer_to(...) to move the call, or None to stay.
Also called as the call is ending with this agent serving, before teardown
finishes: a line it returns is the farewell.
transfer_to
self.handoff_reason. With inherit_context=False it
starts without the earlier conversation; with a workflow, its note then lists
the answers recorded so far, so it doesn’t ask for them again.
complete
Step.result dataclass, and move on.
The answer of a step already finished is the caller correcting it: that step is
recorded again, and the call goes back to where it was. The answer of a later step,
given early, is kept for it: that step is recorded when it comes up, and never asked.
go_to_step
"<agent>.<step>" in another agent, which the caller is handed to.
Only that step is asked again; the answers after it are kept. If the new answer
differs from the old one, the agents after this one redo their finished steps.
on_participant_joined
on_participant_left
hangup
cleanup
initialize_mcp
zeroruntime.serve calls it
while building the agent, so a server that is down fails the build
rather than the first tool call.
add_server
tools.
Ignores anything that is not an MCPServerStdio or MCPServerHTTP.
on
off
emit
event.
Returns as soon as the handlers have been started, not when they
finish, and never raises: an exception inside a handler is logged
against the event name. Ignored once the emitter has been closed.
AgentContext
What is known about an incoming job, handed to the agent factory.zeroruntime.serve passes one to your factory if it takes an argument, so
the agent can be built around the call it is about to take — a caller’s
number out of metadata, a different prompt per room.
Fields
Whatever the dispatcher attached — the caller’s number, a tenant id, anything the job was started with.
CallSummary
Summarise the conversation when it ends, and POST the result.Fields
A second model for the summary alone.
None reuses the session’s. Worth pointing at something cheap: it runs once, over the whole transcript, while the process is already shutting down.Seconds the summariser gets. 0 takes the default. Summarising is an LLM round trip over the whole conversation, so it is a different order of work from the rest of teardown. The ceiling is the shutdown grace period, since this runs while the agent is shutting down — asking for more than that cuts the summary off mid-request rather than granting the time.
serve
agent and serve every call dispatched to it.
Every keyword here describes this worker — how many calls it takes,
what it logs, where it answers probes. What a session looks like
(recording, codec, timeouts and so on) is set on Room and passed as
room=.
Blocks until interrupted. The agent is registered with ZeroRuntime under
its agent id, and every call dispatched to that id builds a fresh agent
from the factory — one instance per call, never one shared across them.
A callable returning an
Agent. Your subclass is usually the callable. An instance is rejected: concurrent calls would share one conversation.The
Room every dispatched call is given. Every Room field can be set here. A dispatched call never passes through zeroruntime.invoke, so this is the only place its session is described; invoke(room=...) inherits from it and overrides only the fields it names.Called on its own thread once the agent is registered. Where
zeroruntime.invoke belongs, for a process that starts its own calls rather than waiting to be dispatched to.Concurrent sessions this worker accepts. The
ZERORUNTIME_MAX_CONCURRENT_SESSIONS environment variable wins when it is set to a number.Fraction of capacity above which the worker reports itself loaded and new calls prefer another worker.
Applied to the
zeroruntime logger, and installs colored logging if nothing else has configured the root logger.Also take calls another agent hands over with
transfer_to(RemoteAgent(<this agent id>)), in place: the same session and participant, this agent’s instructions, tools, hooks and pipeline. On by default, so one process both takes its own calls and serves transfers; False takes only its own.invoke
serve(on_ready=...), which runs on its own thread, or await
ZeroRuntimeChannel.start from async code.
The agent has to be served by this process; invoke cannot start a
call on an agent served by another one, because the pipeline, credentials
and tools all live where zeroruntime.serve was called.
The agent is the one zeroruntime.serve registered, under
ZERORUNTIME_AGENT_ID or "zeroruntime_agent".
A
Room layered over the one serve() was given — name only what differs. Without room_id a room is created.Only
enabled is applied; anything else is warned about and dropped. Prefer Room(recording=...).Start against a different ZeroRuntime address than the one
serve() is connected to. The channel is then owned by this call and closed when the session ends.Session
One live call, and everything you can do to it while it runs. You are handed one rather than constructing one:zeroruntime.invoke returns
it, and inside a @function_tool or an on_* hook it is the session the
agent is bound to. Every method here is sent to the running agent, so
they are all awaited and none of them block the call.
The object stays usable after the call ends — ended goes True and the
send methods become no-ops — so a hook can read ended_reason without
guarding first.
Constructor
log_playground
events
ended event so the last transcripts
and metrics are not cut off mid-teardown.
wait
events until the call ends, logging as it goes.
The usual last line of a script that started a session and has nothing
else to do.
Set False to drain silently. State frames are never logged either way — they arrive every few seconds and say nothing a reader wants.
aclose
async with and stop do. Call it when you drop a session
some other way, so its connection is closed.
say
Whether the caller can barge in over this line.
None leaves the pipeline’s own setting alone.Pre-rendered audio to play instead of sending
text through TTS. text is still what the transcript records. Called from inside a @function_tool, the line is spoken while the tool runs. If the tool is cancelled by an interruption, lines sent after that are not spoken, and their handles report them interrupted. Lines sent from a task the tool starts (asyncio.create_task) are not tied to the tool call.A handle for this utterance — await it to know when it finished, or read it to find out it was interrupted.
reply
instructions.
Unlike say, this is a generation: the model sees the conversation so
far plus these instructions, and what it produces is spoken.
Called from inside a @function_tool, the reply is generated and
spoken while the tool runs, in order with the tool’s say calls. As
with say, a reply sent after the tool was cancelled by an interruption
is not spoken. wait_for_playback does not apply there.
How many of the newest camera frames to show the model. The count travels, not the pixels — they are captured on the call’s side. Needs
Room(vision=True); without it there is no video track to capture from.Resolve the handle only once the audio has finished playing, rather than when generation completes.
get_context_history
get_metrics
change_pipeline
change_component.
change_component
None removes a component (denoise=None turns
noise cancellation off). Must be called while an agent is bound to the
session, e.g. from a @function_tool or an on_* hook.
play_background_audio
Room(background_audio=True).
A path, or a
BackgroundAudio carrying one along with its volume and looping. A disabled BackgroundAudio plays nothing.set_thinking_audio
on_enter.
file=None uses the built-in thinking sound. Any file libav can
decode works — wav, mp3, ogg, flac, m4a.
Needs the room’s mixing track, Room(background_audio=True), like all
audio that is not speech. Without it nothing plays, and a warning is
logged in your process.
stop_background_audio
subscribe_to_pubsub
publish_to_pubsub
add_message
Whose context to write into, when the call has more than one agent. Empty means the one running.
Replace the previous message of this role instead of appending — how a rolling system prompt is kept from growing.
append_instructions
OpenAILive) take it, as with the other appends;
for any other it is logged here as a warning and not sent.
append_thinking
append_commentary
add_handoff
zeroruntime.serve registers one
agent_id per call — and whether it inherits the history is that
agent’s inherit_context.
prepare_agent
agent_id onto the call, ready to be handed it.
transfer_to(RemoteAgent(agent_id)) calls this first, so a transfer that
can’t happen fails in the tool that asked rather than after it returned.
offer_agent
agent_id.
Sends the agent’s spec and tools, and its pipeline with the keys that
pipeline’s providers need, if it has one. The runtime runs them when
another process’s tool returns RemoteAgent(agent_id), swapping in the
pipeline components that differ from the call’s. zeroruntime.serve calls
this for every call it takes, so other agents can hand the caller to it.
process_text
get_participants
Participant records.
transfer_call
transfer_to with no introduction and the
agent drops out.
interrupt
end
stop
async with calls.
detach
end or destroy.
destroy
end
is the polite version.
on
off
emit
event.
Returns as soon as the handlers have been started, not when they
finish, and never raises: an exception inside a handler is logged
against the event name. Ignored once the emitter has been closed.
current_session
@function_tool, a lifecycle hook, a pipeline hook. Useful for code that
runs on the call without holding a reference to it — a module-level
@pipeline.on handler, say. Anything defined on the agent should reach
the call through self.session instead, and a pubsub handler subscribed
with Session.subscribe_to_pubsub already has the session in hand.
Participant
Somebody in the room with the agent.Fields
UtteranceHandle
One thing the agent is saying, and how it went. Returned bySession.say and Session.reply. Await it to block until the
line finishes — awaiting resolves whether it played out or was cut off, so
check interrupted rather than assuming it was heard.
Constructor
done
Room
Which room the agent joins.room_id=None asks for a new one.
Fields
ZeroRuntime auth token for the room. Falls back to the
ZERORUNTIME_AUTH_TOKEN environment variable. Kept out of repr.Codec the room negotiates —
"opus" (the default when None), "pcmu", "pcma", "g722". This is what tells a meeting from a phone call: opus is 48 kHz, pcmu/pcma are 8 kHz and g722 is 16 kHz, and that rate reaches the VAD and STT. Leave it None for meetings; set "pcmu" or "pcma" for SIP so the pipeline sizes itself to the narrowband audio instead of resampling it up to 48 kHz and back down again.Record the session. Off unless asked for — recording a call is a decision about the person on the other end, so the default has to be the safe one. Audio is always captured when this is on; the two below add tracks to it.
Also record the screen share. Needs
recording and vision — there is no screen-share track on a session that is not receiving video.Publish the agent under a fixed participant id.
None lets the room mint one, which is what a single-agent session wants.Open the room’s mixing audio track. Nothing plays by itself — this is the track, not the sound. Start audio on it with
session.play_background_audio(file=..., volume=..., looping=...) and stop it with session.stop_background_audio(). Required before either call: without the track the call is refused, and the caller hears nothing.Whether the agent waits for someone to join before speaking.
None keeps the default (True).Hard cap on session length, in seconds. The session is ended when it is reached.
None inherits the default ceiling. Must be >= 0.Seconds with no participant in the room before the session is ended.
None keeps the default. Must be >= 0.Seconds without conversation — no turn started or finished by either the caller or the agent — before the session is ended, even though people are still connected. Guards against a call that has stalled and would otherwise run until
session_timeout_seconds. None or 0 leaves it off. Choose it against how long a caller may legitimately go quiet (a hold, a long think), because it ends the call on them. Checked every few seconds, so the session may run slightly past it; your deployment may also enforce a tighter limit. Must be >= 0.A pubsub topic to chat on. Messages typed there go to the agent as text, and its answers are published back on it.
Sip
The telephony leg of a session — who is being called, and from what.Fields
to_metadata
UNSET
serve(recording=False) and leaving recording out have to mean
different things once a Room template exists — the first overrides the
template, the second defers to it — and no ordinary default can express
that, because the value a caller most often means to override with is the
default itself.
ZeroRuntimeChannel
A connection to a ZeroRuntime server, and the sessions started over it.zeroruntime.serve and zeroruntime.invoke own one for you. Hold one
directly to start sessions from async code, to reach a ZeroRuntime address
other than the configured one, or to ask what capacity it has.
Connect explicitly with await channel.connect(), or use it as an async
context manager — every method connects on first use anyway.
TLS is decided by the target unless secure says otherwise: local hosts
are plaintext, port 443 is TLS. ZERORUNTIME_INSECURE=1 forces plaintext.
Constructor
use_tls
secure wins if it was set, then ZERORUNTIME_INSECURE, then the
target itself: a local host is plaintext and port 443 is TLS.
connect
Seconds to wait for the channel to become ready. 0 returns without waiting, and the first request finds out instead.
aclose
status
session_info
destroy
attach
start
zeroruntime.invoke, and what to reach for
inside async code, where invoke cannot be called.
Seconds without a participant before the session is ended. Defaults to the room’s setting.