pub struct EventCallbacks {Show 38 fields
pub on_audio: Option<AudioCallback>,
pub on_text: Option<TextCallback>,
pub on_text_complete: Option<TextCallback>,
pub on_input_transcript: Option<TranscriptCallback>,
pub on_output_transcript: Option<TranscriptCallback>,
pub on_thought: Option<TextCallback>,
pub on_vad_start: Option<SignalCallback>,
pub on_vad_end: Option<SignalCallback>,
pub on_phase: Option<PhaseCallback>,
pub on_usage: Option<UsageCallback>,
pub on_interrupted: Option<AsyncCallback>,
pub on_tool_call: Option<ToolCallCallback>,
pub on_tool_cancelled: Option<AsyncCallbackWith<Vec<String>>>,
pub on_turn_complete: Option<AsyncCallback>,
pub on_generation_complete: Option<AsyncCallback>,
pub on_go_away: Option<AsyncCallbackWith<Duration>>,
pub on_connected: Option<AsyncCallbackWith<Arc<dyn SessionWriter>>>,
pub on_disconnected: Option<AsyncCallbackWith<Option<String>>>,
pub on_resumed: Option<AsyncCallback>,
pub on_error: Option<AsyncCallbackWith<String>>,
pub on_transfer: Option<AsyncCallbackWith2<String, String>>,
pub on_extracted: Option<AsyncCallbackWith2<String, Value>>,
pub on_extraction_error: Option<AsyncCallbackWith2<String, String>>,
pub on_turn_complete_mode: CallbackMode,
pub on_generation_complete_mode: CallbackMode,
pub on_connected_mode: CallbackMode,
pub on_disconnected_mode: CallbackMode,
pub on_error_mode: CallbackMode,
pub on_go_away_mode: CallbackMode,
pub on_extracted_mode: CallbackMode,
pub on_extraction_error_mode: CallbackMode,
pub on_tool_cancelled_mode: CallbackMode,
pub on_transfer_mode: CallbackMode,
pub on_resumed_mode: CallbackMode,
pub before_tool_response: Option<BeforeToolResponseCallback>,
pub on_turn_boundary: Option<AsyncCallbackWith2<State, Arc<dyn SessionWriter>>>,
pub instruction_template: Option<InstructionFn>,
pub instruction_amendment: Option<InstructionFn>,
}Expand description
Typed callback registry for Live session events.
Callbacks are divided into two lanes:
- Fast lane (sync): Called inline, must be < 1ms. For audio, text, transcripts, VAD.
- Control lane (async): Awaited on a dedicated task. For tool calls, lifecycle, interruptions.
Fields§
§on_audio: Option<AudioCallback>Called for each audio chunk from the model (PCM16 24kHz).
on_text: Option<TextCallback>Called for each incremental text delta from the model.
on_text_complete: Option<TextCallback>Called when the model completes a text response.
on_input_transcript: Option<TranscriptCallback>Called for input (user speech) transcription updates.
on_output_transcript: Option<TranscriptCallback>Called for output (model speech) transcription updates.
on_thought: Option<TextCallback>Called when the model emits a thought/reasoning summary (when includeThoughts is enabled).
on_vad_start: Option<SignalCallback>Called when server-side VAD detects voice activity start.
on_vad_end: Option<SignalCallback>Called when server-side VAD detects voice activity end.
on_phase: Option<PhaseCallback>Called on session phase transitions.
on_usage: Option<UsageCallback>Called when server sends token usage metadata.
on_interrupted: Option<AsyncCallback>Called when the model is interrupted by barge-in.
on_tool_call: Option<ToolCallCallback>Called when model requests tool execution.
Return None to use auto-dispatch (ToolDispatcher), Some to override.
Receives State for natural state promotion from tool results.
on_tool_cancelled: Option<AsyncCallbackWith<Vec<String>>>Called when server cancels pending tool calls.
on_turn_complete: Option<AsyncCallback>Called when the model completes its turn.
on_generation_complete: Option<AsyncCallback>Called when the model finishes generating its full intended response,
before any interruption truncation (the wire GenerationComplete).
on_go_away: Option<AsyncCallbackWith<Duration>>Called when server sends GoAway (session ending soon).
on_connected: Option<AsyncCallbackWith<Arc<dyn SessionWriter>>>Called when session setup completes (connected).
Receives a SessionWriter for sending messages on connect (e.g. greeting prompts).
on_disconnected: Option<AsyncCallbackWith<Option<String>>>Called when session disconnects.
on_resumed: Option<AsyncCallback>Called after session resumes from GoAway.
on_error: Option<AsyncCallbackWith<String>>Called on non-fatal errors.
on_transfer: Option<AsyncCallbackWith2<String, String>>Called when agent transfer occurs (from, to).
on_extracted: Option<AsyncCallbackWith2<String, Value>>Called when a TurnExtractor produces a result (extractor_name, value).
on_extraction_error: Option<AsyncCallbackWith2<String, String>>Called when a TurnExtractor fails (extractor_name, error_message).
By default, extraction failures are logged via tracing::warn!.
Register this callback to implement custom error handling (retry, alert, etc.).
on_turn_complete_mode: CallbackModeExecution mode for on_turn_complete.
on_generation_complete_mode: CallbackModeExecution mode for on_generation_complete.
on_connected_mode: CallbackModeExecution mode for on_connected.
on_disconnected_mode: CallbackModeExecution mode for on_disconnected.
on_error_mode: CallbackModeExecution mode for on_error.
on_go_away_mode: CallbackModeExecution mode for on_go_away.
on_extracted_mode: CallbackModeExecution mode for on_extracted.
on_extraction_error_mode: CallbackModeExecution mode for on_extraction_error.
on_tool_cancelled_mode: CallbackModeExecution mode for on_tool_cancelled.
on_transfer_mode: CallbackModeExecution mode for on_transfer.
on_resumed_mode: CallbackModeExecution mode for on_resumed.
before_tool_response: Option<BeforeToolResponseCallback>Intercept tool responses before sending to Gemini.
Receives the tool responses and shared State. Returns (potentially modified) responses. Use this to rewrite, augment, or filter tool results based on conversation state.
on_turn_boundary: Option<AsyncCallbackWith2<State, Arc<dyn SessionWriter>>>Called at turn boundaries (after extractors, before on_turn_complete).
Receives shared State and a SessionWriter for injecting content into the conversation. Use this for context stuffing, K/V injection, condensed state summaries, or any outbound content interleaving.
instruction_template: Option<InstructionFn>State-reactive system instruction template (full replacement).
Called after extractors run on each TurnComplete. If it returns
Some(instruction), the system instruction is updated mid-session.
Returns None to leave the instruction unchanged.
This is sync (no async) because instruction generation should be fast.
instruction_amendment: Option<InstructionFn>State-reactive instruction amendment (additive, not replacement).
Called after extractors and phase transitions on each TurnComplete.
If it returns Some(text), the text is appended to the current phase
instruction (separated by \n\n). Returns None to skip amendment.
Unlike instruction_template (which replaces the entire instruction),
this only adds to the phase instruction — the developer never needs to
know or repeat the base instruction.