Expand description
Typed callback registry for Live session events.
Fast lane callbacks (sync, < 1ms): audio, text, transcripts, VAD. Control lane callbacks (async, can block): tool calls, lifecycle, interruptions. Outbound interceptors: transform tool responses, inject context at turn boundaries.
§Callback Modes
Each control-lane callback has an associated ExecutionMode:
Blocking— awaited inline. The event loop waits for completion before processing the next event. Guarantees ordering and state consistency.Concurrent— spawned as a detached tokio task. The event loop continues immediately. Use for fire-and-forget work (logging, background agent dispatch, analytics).
Fast-lane callbacks (audio, text, VAD) are always sync and inline.
Interceptors (before_tool_response, on_turn_boundary) are always blocking.
on_interrupted, on_turn_boundary, and the on_teardown hooks default to
blocking for a reason — audio forwarding resumes only after on_interrupted
returns, the next turn proceeds only after on_turn_boundary, and disconnect
completes only after teardown — but each can be made concurrent when the
body is pure bookkeeping (see the _mode fields and on_teardown_concurrent).
on_tool_call and before_tool_response are always blocking: their return
value is the tool response.
Structs§
- Event
Callbacks - Typed callback registry for Live session events.
Type Aliases§
- Async
Callback - Control-lane async callback with no payload.
- Async
Callback With - Control-lane async callback over one payload value.
- Async
Callback With2 - Control-lane async callback over two payload values.
- Audio
Callback - Fast-lane sync callback over a raw audio chunk.
- Before
Tool Response Callback - Middleware over outgoing tool responses (inspect/rewrite before send).
- Instruction
Fn - Sync state-reactive instruction generator (
None= leave unchanged). - Session
Phase Callback - Fast-lane sync callback over a wire-level
SessionPhasechange (connecting → active → disconnecting …). Not thePhaseMachine. - Signal
Callback - Fast-lane sync callback with no payload (VAD start/end).
- Text
Callback - Fast-lane sync callback over a text payload (delta, accumulated text, thought).
- Tool
Call Callback - Tool-call override: return
Some(responses)to reply,Noneto defer to auto-dispatch via the registeredToolDispatcher. - Transcript
Callback - Fast-lane sync callback over a transcript chunk with its
is_finalflag. - Usage
Callback - Fast-lane sync callback over usage metadata.