pub struct SessionContext { /* private fields */ }Expand description
Shared, thread-safe conversation context manager.
See the module documentation for a full usage example.
Implementations§
Source§impl SessionContext
impl SessionContext
Sourcepub fn new(config: SessionConfig) -> Self
pub fn new(config: SessionConfig) -> Self
Create a new SessionContext with the given SessionConfig.
Sourcepub async fn enrich(
&self,
request: PromptRequest,
) -> (PromptRequest, SessionAction)
pub async fn enrich( &self, request: PromptRequest, ) -> (PromptRequest, SessionAction)
Enrich a PromptRequest with conversation history for its session.
If the session has prior turns the last context_window turns are
formatted as a dialogue transcript and prepended to request.input.
The unmodified request is returned when there is no prior history.
Also runs a lazy TTL eviction pass on every call (O(sessions) but amortised across all callers).
§Returns
A tuple of (enriched_request, action). action is
SessionAction::RequestSummary when the stored turn count exceeds
SessionConfig::summarise_after_turns.
Sourcepub async fn record_response(&self, session: &SessionId, response: &str)
pub async fn record_response(&self, session: &SessionId, response: &str)
Record a model response for a session, appending it to the history.
Call this after a successful inference so the next call to enrich
can inject the assistant’s answer as context.
Sourcepub async fn summarise(&self, session: &SessionId, summary: &str)
pub async fn summarise(&self, session: &SessionId, summary: &str)
Replace the full conversation history for a session with a single summary turn.
Call this after the model produces a condensed summary in response to
a SessionAction::RequestSummary signal.
Sourcepub async fn clear_session(&self, session: &SessionId)
pub async fn clear_session(&self, session: &SessionId)
Clear all history for a session (e.g. on explicit user logout).
Sourcepub fn stats(&self) -> SessionStats
pub fn stats(&self) -> SessionStats
Return a snapshot of aggregate statistics.
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 moreAuto Trait Implementations§
impl !RefUnwindSafe for SessionContext
impl !UnwindSafe for SessionContext
impl Freeze for SessionContext
impl Send for SessionContext
impl Sync for SessionContext
impl Unpin for SessionContext
impl UnsafeUnpin for SessionContext
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>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request