#[non_exhaustive]pub struct ContextUpdate {
pub system_instruction: Option<Content>,
pub tools: Option<Vec<Tool>>,
}Expand description
A mid-session replacement of the model preamble: the system instruction,
the declared tools, or both. Sent as a contextUpdate message.
Only the fields that are set change. tools: None keeps the current
tools; Some(vec![]) clears them. A new system instruction replaces the
one given at setup. Updates are processed in order with the rest of the
client’s input, so an update sent before a tool response is in effect
when the model reads that response.
Both fields are part of the model preamble, so every update invalidates the server’s prefix cache. Send one only when something changed.
Gemini 3.8 Live accepts it on Google AI and Vertex AI; Gemini 2.5 Live
does not (see SessionConfig::supports_context_update).
let update = ContextUpdate::new()
.system_instruction("The caller is verified. Never read balances aloud.")
.tools(vec![Tool::functions(vec![FunctionDeclaration {
name: "get_balance".into(),
description: "Fetch the verified caller's balance.".into(),
parameters: None,
behavior: None,
}])]);
assert!(!update.is_empty());
assert!(ContextUpdate::new().is_empty());Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.system_instruction: Option<Content>Replacement system instruction. None keeps the current one.
tools: Option<Vec<Tool>>Replacement tool list. None keeps the current tools; an empty list
clears them.
Implementations§
Source§impl ContextUpdate
impl ContextUpdate
Sourcepub fn system_instruction(self, instruction: impl Into<String>) -> Self
pub fn system_instruction(self, instruction: impl Into<String>) -> Self
Replace the system instruction with instruction.
Sourcepub fn clear_tools(self) -> Self
pub fn clear_tools(self) -> Self
Remove every declared tool.
Trait Implementations§
Source§impl Clone for ContextUpdate
impl Clone for ContextUpdate
Source§fn clone(&self) -> ContextUpdate
fn clone(&self) -> ContextUpdate
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ContextUpdate
impl Debug for ContextUpdate
Source§impl Default for ContextUpdate
impl Default for ContextUpdate
Source§fn default() -> ContextUpdate
fn default() -> ContextUpdate
Source§impl PartialEq for ContextUpdate
impl PartialEq for ContextUpdate
impl StructuralPartialEq for ContextUpdate
Auto Trait Implementations§
impl Freeze for ContextUpdate
impl RefUnwindSafe for ContextUpdate
impl Send for ContextUpdate
impl Sync for ContextUpdate
impl Unpin for ContextUpdate
impl UnsafeUnpin for ContextUpdate
impl UnwindSafe for ContextUpdate
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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> ⓘ
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].