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: ExecutionModeExecution 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: ExecutionModeExecution 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: ExecutionModeExecution mode for on_turn_complete.
on_generation_complete_mode: ExecutionModeExecution mode for on_generation_complete.
on_connected_mode: ExecutionModeExecution mode for on_connected.
on_disconnected_mode: ExecutionModeExecution mode for on_disconnected.
on_error_mode: ExecutionModeExecution mode for on_error.
on_go_away_mode: ExecutionModeExecution mode for on_go_away.
on_extracted_mode: ExecutionModeExecution mode for on_extracted.
on_extraction_error_mode: ExecutionModeExecution mode for on_extraction_error.
on_tool_cancelled_mode: ExecutionModeExecution mode for on_tool_cancelled.
on_transfer_mode: ExecutionModeExecution mode for on_transfer.
on_resumed_mode: ExecutionModeExecution 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
impl Debug for EventCallbacks
Source§impl Default for EventCallbacks
impl Default for EventCallbacks
Source§fn default() -> EventCallbacks
fn default() -> EventCallbacks
Auto Trait Implementations§
impl Freeze for EventCallbacks
impl !RefUnwindSafe for EventCallbacks
impl Send for EventCallbacks
impl Sync for EventCallbacks
impl Unpin for EventCallbacks
impl !UnwindSafe for EventCallbacks
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].