EventCallbacks

Struct EventCallbacks 

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

Execution mode for on_turn_complete.

§on_generation_complete_mode: CallbackMode

Execution mode for on_generation_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<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.

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.

§

impl<T> Instrument for T

§

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

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

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.

§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,