pub struct SessionContext {
pub session_id: Option<String>,
pub service_session_id: Option<String>,
pub session: Option<AgentSession>,
pub agent: Option<AgentInfo>,
pub input_messages: Vec<Message>,
pub instructions: Option<String>,
pub messages: Vec<Message>,
pub tools: Vec<ToolDefinition>,
}Expand description
Per-invocation context a provider contributes to a run. Providers mutate this in place in before_run. Rust equivalent of upstream SessionContext.
Fields§
§session_id: Option<String>Local session identifier (from the thread), for provider scoping.
service_session_id: Option<String>Service-managed session/conversation id, when applicable.
session: Option<AgentSession>The session the run belongs to, when the caller of before_run has
one (an Agent run always does). Clones share
the session’s state bag, so a provider can read and persist
per-session state through it. Mirrors the session argument of
upstream’s before_run.
agent: Option<AgentInfo>The agent running, when the caller of before_run is one (an
Agent run always sets it). Mirrors the
agent argument of upstream’s before_run, as the identity a
provider may scope by rather than the agent object itself.
input_messages: Vec<Message>The run’s input messages. A provider may rewrite them (for example
to strip an attachment it has analyzed); the model receives the
rewritten input, while after_run still sees the caller’s original.
instructions: Option<String>Extra system instructions to inject (providers append via add_instructions).
messages: Vec<Message>Extra context messages to inject ahead of history.
tools: Vec<ToolDefinition>Extra tools to make available for this run.
Implementations§
Source§impl SessionContext
impl SessionContext
pub fn new(input_messages: Vec<Message>) -> SessionContext
Sourcepub fn extend_messages(&mut self, source_id: &str, messages: Vec<Message>)
pub fn extend_messages(&mut self, source_id: &str, messages: Vec<Message>)
Add context messages from source_id, each tagged with its source
(see ATTRIBUTION_KEY). Mirrors upstream’s extend_messages.
Sourcepub fn extend_messages_from(
&mut self,
source_id: &str,
source_type: Option<&str>,
messages: Vec<Message>,
origin_session_ids: &[String],
)
pub fn extend_messages_from( &mut self, source_id: &str, source_type: Option<&str>, messages: Vec<Message>, origin_session_ids: &[String], )
As extend_messages, also recording the
provider’s type and the sessions the messages came from when that is
not the current one (cross-session memory), for audit and governance.
Sourcepub fn get_messages(
&self,
sources: Option<&[&str]>,
exclude_sources: Option<&[&str]>,
) -> Vec<Message>
pub fn get_messages( &self, sources: Option<&[&str]>, exclude_sources: Option<&[&str]>, ) -> Vec<Message>
The context messages, optionally only those from sources and not
from exclude_sources; unattributed messages count as from no source.
Sourcepub fn add_instructions(&mut self, s: impl Into<String>)
pub fn add_instructions(&mut self, s: impl Into<String>)
Append instructions, newline-concatenating with any already present.
Trait Implementations§
Source§impl Clone for SessionContext
impl Clone for SessionContext
Source§fn clone(&self) -> SessionContext
fn clone(&self) -> SessionContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more