pub struct AgentSession {
pub state: SessionState,
pub context_providers: Vec<Arc<dyn ContextProvider>>,
/* private fields */
}Expand description
A conversation session: a lightweight identity + state container.
Message history is not stored here any more — see
crate::history::HistoryProvider and
crate::history::ensure_history_provider.
Fields§
§state: SessionStateFree-form session state (for context providers to persist per-session
data across runs). Shared by reference across clones of this session —
see SessionState.
context_providers: Vec<Arc<dyn ContextProvider>>Context providers associated with this session (memory/RAG/history
injection). Combined with an agent’s own providers at request time —
see Agent::combined_providers.
Implementations§
Source§impl AgentSession
impl AgentSession
Sourcepub fn new() -> AgentSession
pub fn new() -> AgentSession
A fresh, local (non-service-managed) session with a newly generated
session_id.
Sourcepub fn child(&self) -> AgentSession
pub fn child(&self) -> AgentSession
A child session for delegating part of this conversation to a
sub-agent (the as_tool(propagate_session) path).
The child keeps this session’s session_id and shares its state
bag by reference, but gets an isolated (cleared)
service_session_id and no context providers. Isolating the
server-side conversation pointer matters: after the parent’s first
model call, a service-managed session carries the parent conversation
id (e.g. an OpenAI Responses previous_response_id); a child that
inherited it would submit a follow-up onto a conversation whose
tool call is still pending, which the server rejects. Mirrors
upstream’s _agent_wrapper child-session construction
(_agents.py, microsoft/agent-framework#5875).
Sourcepub fn service(id: impl Into<String>) -> AgentSession
pub fn service(id: impl Into<String>) -> AgentSession
A service-managed session identified by a conversation id.
Sourcepub fn with_context_providers(
self,
providers: Vec<Arc<dyn ContextProvider>>,
) -> AgentSession
pub fn with_context_providers( self, providers: Vec<Arc<dyn ContextProvider>>, ) -> AgentSession
Attach context providers to this session, replacing any previously set.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
This session’s local identifier.
Sourcepub fn service_session_id(&self) -> Option<&str>
pub fn service_session_id(&self) -> Option<&str>
The service-side conversation id, if any.
Sourcepub fn set_service_session_id(&mut self, id: impl Into<String>)
pub fn set_service_session_id(&mut self, id: impl Into<String>)
Set the service-side conversation id explicitly.
Sourcepub fn try_adopt_service_session_id(&mut self, id: &str) -> bool
pub fn try_adopt_service_session_id(&mut self, id: &str) -> bool
Adopt a service-managed conversation id returned by the chat service
(e.g. an OpenAI Responses previous_response_id or an Azure AI thread
id), so follow-up runs continue the same service conversation.
Returns true when the id was newly adopted (it differed from what
the session already carried), false when it was already current.
Sourcepub fn to_dict(&self) -> Value
pub fn to_dict(&self) -> Value
Serialize this session’s {session_id, service_session_id, state} to
JSON. Conversation history is deliberately not included — it lives
in whichever HistoryProvider, if
any, is attached to context_providers; serialize that separately
(e.g. InMemoryHistoryProvider::to_dict).
Sourcepub fn from_dict(state: &Value) -> Result<AgentSession, Error>
pub fn from_dict(state: &Value) -> Result<AgentSession, Error>
Reconstruct a session from state produced by AgentSession::to_dict.
context_providers are not restored by this call — callers
reattach their own (including any HistoryProvider, whose own state
is serialized/restored independently).
Trait Implementations§
Source§impl Clone for AgentSession
impl Clone for AgentSession
Source§fn clone(&self) -> AgentSession
fn clone(&self) -> AgentSession
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more