EventCallbacks

Struct EventCallbacks 

Source
pub struct EventCallbacks {
Show 42 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_session_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() -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>, pub on_tool_call: Option<Arc<dyn Fn(Vec<FunctionCall>, State) -> Pin<Box<dyn Future<Output = Option<Vec<FunctionResponse>>> + Send>> + Send + Sync>>, pub on_tool_cancelled: Option<Arc<dyn Fn(Vec<String>) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>, pub on_turn_complete: Option<Arc<dyn Fn() -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>, pub on_generation_complete: Option<Arc<dyn Fn() -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>, pub on_go_away: Option<Arc<dyn Fn(Duration) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>, pub on_connected: Option<Arc<dyn Fn(Arc<dyn SessionWriter>) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>, pub on_disconnected: Option<Arc<dyn Fn(Option<String>) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>, pub on_teardown: Vec<Arc<dyn Fn() -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>, pub on_teardown_concurrent: Vec<Arc<dyn Fn() -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>, pub on_resumed: Option<Arc<dyn Fn() -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>, pub on_error: Option<Arc<dyn Fn(String) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>, pub on_transfer: Option<Arc<dyn Fn(String, String) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>, pub on_extracted: Option<Arc<dyn Fn(String, Value) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>, pub on_extraction_error: Option<Arc<dyn Fn(String, String) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>, pub on_interrupted_mode: ExecutionMode, pub on_turn_boundary_mode: ExecutionMode, pub on_turn_complete_mode: ExecutionMode, pub on_generation_complete_mode: ExecutionMode, pub on_connected_mode: ExecutionMode, pub on_disconnected_mode: ExecutionMode, pub on_error_mode: ExecutionMode, pub on_go_away_mode: ExecutionMode, pub on_extracted_mode: ExecutionMode, pub on_extraction_error_mode: ExecutionMode, pub on_tool_cancelled_mode: ExecutionMode, pub on_transfer_mode: ExecutionMode, pub on_resumed_mode: ExecutionMode, pub before_tool_response: Option<Arc<dyn Fn(Vec<FunctionResponse>, State) -> Pin<Box<dyn Future<Output = Vec<FunctionResponse>> + Send>> + Send + Sync>>, pub on_turn_boundary: Option<Arc<dyn Fn(State, Arc<dyn SessionWriter>) -> Pin<Box<dyn Future<Output = ()> + Send>> + 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_session_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() -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>

Called when the model is interrupted by barge-in.

§on_tool_call: Option<Arc<dyn Fn(Vec<FunctionCall>, State) -> Pin<Box<dyn Future<Output = Option<Vec<FunctionResponse>>> + Send>> + 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>) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>

Called when server cancels pending tool calls.

§on_turn_complete: Option<Arc<dyn Fn() -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>

Called when the model completes its turn.

§on_generation_complete: Option<Arc<dyn Fn() -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>

Called when the model finishes generating its full intended response, before any interruption truncation (the wire GenerationComplete).

§on_go_away: Option<Arc<dyn Fn(Duration) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>

Called when server sends GoAway (session ending soon).

§on_connected: Option<Arc<dyn Fn(Arc<dyn SessionWriter>) -> Pin<Box<dyn Future<Output = ()> + Send>> + 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>) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>

Called when session disconnects.

§on_teardown: Vec<Arc<dyn Fn() -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>

Teardown hooks run on disconnect, before on_disconnected.

Additive, unlike every other callback here. Each of those is a single Option that the last registration silently replaces, which is fine for an application — it has one place to write its handler — and unusable for an extension: .with_memory(s).on_disconnected(f) would drop the extension’s hook, and the reverse order would drop the application’s, with nothing reporting either.

Extensions that must flush durable state at end of session register here (gemini-memory-rs reconciles its session ledger this way). Hooks run in registration order and are awaited before on_disconnected fires, so the application’s own handler observes a settled world. A hook that panics or hangs delays disconnect — keep them bounded.

§on_teardown_concurrent: Vec<Arc<dyn Fn() -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>

Teardown hooks that are spawned detached on disconnect rather than awaited — for bookkeeping that must not delay the disconnect (metrics, a final log line). Anything that flushes durable state belongs in on_teardown.

§on_resumed: Option<Arc<dyn Fn() -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>

Called after session resumes from GoAway.

§on_error: Option<Arc<dyn Fn(String) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>

Called on non-fatal errors.

§on_transfer: Option<Arc<dyn Fn(String, String) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>

Called when agent transfer occurs (from, to).

§on_extracted: Option<Arc<dyn Fn(String, Value) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>

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

§on_extraction_error: Option<Arc<dyn Fn(String, String) -> Pin<Box<dyn Future<Output = ()> + Send>> + 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_interrupted_mode: ExecutionMode

Execution mode for on_interrupted. Blocking by default: audio forwarding resumes only after the callback returns, which is what a playback flush needs. Concurrent is for bookkeeping only.

§on_turn_boundary_mode: ExecutionMode

Execution mode for on_turn_boundary. Blocking by default so injected context lands before the next turn; concurrent is for observation only.

§on_turn_complete_mode: ExecutionMode

Execution mode for on_turn_complete.

§on_generation_complete_mode: ExecutionMode

Execution mode for on_generation_complete.

§on_connected_mode: ExecutionMode

Execution mode for on_connected.

§on_disconnected_mode: ExecutionMode

Execution mode for on_disconnected.

§on_error_mode: ExecutionMode

Execution mode for on_error.

§on_go_away_mode: ExecutionMode

Execution mode for on_go_away.

§on_extracted_mode: ExecutionMode

Execution mode for on_extracted.

§on_extraction_error_mode: ExecutionMode

Execution mode for on_extraction_error.

§on_tool_cancelled_mode: ExecutionMode

Execution mode for on_tool_cancelled.

§on_transfer_mode: ExecutionMode

Execution mode for on_transfer.

§on_resumed_mode: ExecutionMode

Execution mode for on_resumed.

§before_tool_response: Option<Arc<dyn Fn(Vec<FunctionResponse>, State) -> Pin<Box<dyn Future<Output = Vec<FunctionResponse>> + Send>> + 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>) -> Pin<Box<dyn Future<Output = ()> + Send>> + 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<(), Error>

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

impl Default for EventCallbacks

Source§

fn default() -> EventCallbacks

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<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

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<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

§

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