Skip to main content

EventCallbacks

Struct EventCallbacks 

Source
pub struct EventCallbacks {
Show 36 fields pub on_audio: Option<Box<dyn Fn(&Bytes) + Send + Sync>>, pub on_text: Option<Box<dyn Fn(&str) + Send + Sync>>, pub on_text_complete: Option<Box<dyn Fn(&str) + Send + Sync>>, pub on_input_transcript: Option<Box<dyn Fn(&str, bool) + Send + Sync>>, pub on_output_transcript: Option<Box<dyn Fn(&str, bool) + Send + Sync>>, pub on_thought: Option<Box<dyn Fn(&str) + Send + Sync>>, pub on_vad_start: Option<Box<dyn Fn() + Send + Sync>>, pub on_vad_end: Option<Box<dyn Fn() + Send + Sync>>, pub on_phase: Option<Box<dyn Fn(SessionPhase) + Send + Sync>>, pub on_usage: Option<Box<dyn Fn(&UsageMetadata) + Send + Sync>>, pub on_interrupted: Option<Arc<dyn Fn() -> BoxFuture<()> + Send + Sync>>, pub on_tool_call: Option<Arc<dyn Fn(Vec<FunctionCall>, State) -> BoxFuture<Option<Vec<FunctionResponse>>> + Send + Sync>>, pub on_tool_cancelled: Option<Arc<dyn Fn(Vec<String>) -> BoxFuture<()> + Send + Sync>>, pub on_turn_complete: Option<Arc<dyn Fn() -> BoxFuture<()> + Send + Sync>>, pub on_go_away: Option<Arc<dyn Fn(Duration) -> BoxFuture<()> + Send + Sync>>, pub on_connected: Option<Arc<dyn Fn(Arc<dyn SessionWriter>) -> BoxFuture<()> + Send + Sync>>, pub on_disconnected: Option<Arc<dyn Fn(Option<String>) -> BoxFuture<()> + Send + Sync>>, pub on_resumed: Option<Arc<dyn Fn() -> BoxFuture<()> + Send + Sync>>, pub on_error: Option<Arc<dyn Fn(String) -> BoxFuture<()> + Send + Sync>>, pub on_transfer: Option<Arc<dyn Fn(String, String) -> BoxFuture<()> + Send + Sync>>, pub on_extracted: Option<Arc<dyn Fn(String, Value) -> BoxFuture<()> + Send + Sync>>, pub on_extraction_error: Option<Arc<dyn Fn(String, String) -> BoxFuture<()> + Send + Sync>>, pub on_turn_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<Arc<dyn Fn(Vec<FunctionResponse>, State) -> BoxFuture<Vec<FunctionResponse>> + Send + Sync>>, pub on_turn_boundary: Option<Arc<dyn Fn(State, Arc<dyn SessionWriter>) -> BoxFuture<()> + Send + Sync>>, pub instruction_template: Option<Arc<dyn Fn(&State) -> Option<String> + Send + Sync>>, pub instruction_amendment: Option<Arc<dyn Fn(&State) -> Option<String> + Send + Sync>>,
}
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<Box<dyn Fn(&Bytes) + Send + Sync>>

Called for each audio chunk from the model (PCM16 24kHz).

§on_text: Option<Box<dyn Fn(&str) + Send + Sync>>

Called for each incremental text delta from the model.

§on_text_complete: Option<Box<dyn Fn(&str) + Send + Sync>>

Called when the model completes a text response.

§on_input_transcript: Option<Box<dyn Fn(&str, bool) + Send + Sync>>

Called for input (user speech) transcription updates.

§on_output_transcript: Option<Box<dyn Fn(&str, bool) + Send + Sync>>

Called for output (model speech) transcription updates.

§on_thought: Option<Box<dyn Fn(&str) + Send + Sync>>

Called when the model emits a thought/reasoning summary (when includeThoughts is enabled).

§on_vad_start: Option<Box<dyn Fn() + Send + Sync>>

Called when server-side VAD detects voice activity start.

§on_vad_end: Option<Box<dyn Fn() + Send + Sync>>

Called when server-side VAD detects voice activity end.

§on_phase: Option<Box<dyn Fn(SessionPhase) + Send + Sync>>

Called on session phase transitions.

§on_usage: Option<Box<dyn Fn(&UsageMetadata) + Send + Sync>>

Called when server sends token usage metadata.

§on_interrupted: Option<Arc<dyn Fn() -> BoxFuture<()> + Send + Sync>>

Called when the model is interrupted by barge-in.

§on_tool_call: Option<Arc<dyn Fn(Vec<FunctionCall>, State) -> BoxFuture<Option<Vec<FunctionResponse>>> + Send + Sync>>

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<Arc<dyn Fn(Vec<String>) -> BoxFuture<()> + Send + Sync>>

Called when server cancels pending tool calls.

§on_turn_complete: Option<Arc<dyn Fn() -> BoxFuture<()> + Send + Sync>>

Called when the model completes its turn.

§on_go_away: Option<Arc<dyn Fn(Duration) -> BoxFuture<()> + Send + Sync>>

Called when server sends GoAway (session ending soon).

§on_connected: Option<Arc<dyn Fn(Arc<dyn SessionWriter>) -> BoxFuture<()> + Send + Sync>>

Called when session setup completes (connected).

Receives a SessionWriter for sending messages on connect (e.g. greeting prompts).

§on_disconnected: Option<Arc<dyn Fn(Option<String>) -> BoxFuture<()> + Send + Sync>>

Called when session disconnects.

§on_resumed: Option<Arc<dyn Fn() -> BoxFuture<()> + Send + Sync>>

Called after session resumes from GoAway.

§on_error: Option<Arc<dyn Fn(String) -> BoxFuture<()> + Send + Sync>>

Called on non-fatal errors.

§on_transfer: Option<Arc<dyn Fn(String, String) -> BoxFuture<()> + Send + Sync>>

Called when agent transfer occurs (from, to).

§on_extracted: Option<Arc<dyn Fn(String, Value) -> BoxFuture<()> + Send + Sync>>

Called when a TurnExtractor produces a result (extractor_name, value).

§on_extraction_error: Option<Arc<dyn Fn(String, String) -> BoxFuture<()> + Send + Sync>>

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: CallbackMode

Execution mode for on_turn_complete.

§on_connected_mode: CallbackMode

Execution mode for on_connected.

§on_disconnected_mode: CallbackMode

Execution mode for on_disconnected.

§on_error_mode: CallbackMode

Execution mode for on_error.

§on_go_away_mode: CallbackMode

Execution mode for on_go_away.

§on_extracted_mode: CallbackMode

Execution mode for on_extracted.

§on_extraction_error_mode: CallbackMode

Execution mode for on_extraction_error.

§on_tool_cancelled_mode: CallbackMode

Execution mode for on_tool_cancelled.

§on_transfer_mode: CallbackMode

Execution mode for on_transfer.

§on_resumed_mode: CallbackMode

Execution mode for on_resumed.

§before_tool_response: Option<Arc<dyn Fn(Vec<FunctionResponse>, State) -> BoxFuture<Vec<FunctionResponse>> + Send + Sync>>

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<Arc<dyn Fn(State, Arc<dyn SessionWriter>) -> BoxFuture<()> + Send + Sync>>

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<Arc<dyn Fn(&State) -> Option<String> + Send + Sync>>

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<Arc<dyn Fn(&State) -> Option<String> + Send + Sync>>

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.

Trait Implementations§

Source§

impl Debug for EventCallbacks

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EventCallbacks

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more