pub struct StatefulAiContext { /* private fields */ }Expand description
Stateful AI context manager
Tracks state across multiple requests within a session, maintaining conversation history and enabling intelligent, context-aware responses.
Implementations§
Source§impl StatefulAiContext
impl StatefulAiContext
Sourcepub fn new(
session_id: impl Into<String>,
config: IntelligentBehaviorConfig,
) -> StatefulAiContext
pub fn new( session_id: impl Into<String>, config: IntelligentBehaviorConfig, ) -> StatefulAiContext
Create a new stateful AI context
Sourcepub fn with_memory_store(
self,
store: Arc<VectorMemoryStore>,
) -> StatefulAiContext
pub fn with_memory_store( self, store: Arc<VectorMemoryStore>, ) -> StatefulAiContext
Create with vector memory store
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
Get the session ID
Sourcepub async fn record_interaction(
&self,
method: impl Into<String>,
path: impl Into<String>,
request: Option<Value>,
response: Option<Value>,
) -> Result<(), Error>
pub async fn record_interaction( &self, method: impl Into<String>, path: impl Into<String>, request: Option<Value>, response: Option<Value>, ) -> Result<(), Error>
Record an interaction
Note: Takes &self instead of &mut self because internal state
is protected by RwLock, allowing concurrent access.
Sourcepub async fn get_state(&self) -> SessionState
pub async fn get_state(&self) -> SessionState
Get current session state
Sourcepub async fn remove_value(&self, key: &str) -> Option<Value>
pub async fn remove_value(&self, key: &str) -> Option<Value>
Remove a state value
Sourcepub async fn get_history(&self) -> Vec<InteractionRecord>
pub async fn get_history(&self) -> Vec<InteractionRecord>
Get interaction history
Sourcepub async fn get_relevant_context(
&self,
query: &str,
limit: usize,
) -> Result<Vec<InteractionRecord>, Error>
pub async fn get_relevant_context( &self, query: &str, limit: usize, ) -> Result<Vec<InteractionRecord>, Error>
Get relevant past interactions using semantic search
Sourcepub async fn build_context_summary(&self) -> String
pub async fn build_context_summary(&self) -> String
Build context summary for LLM prompt
Trait Implementations§
Source§impl Clone for StatefulAiContext
impl Clone for StatefulAiContext
Source§fn clone(&self) -> StatefulAiContext
fn clone(&self) -> StatefulAiContext
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for StatefulAiContext
impl !RefUnwindSafe for StatefulAiContext
impl Send for StatefulAiContext
impl Sync for StatefulAiContext
impl Unpin for StatefulAiContext
impl UnsafeUnpin for StatefulAiContext
impl !UnwindSafe for StatefulAiContext
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
Converts
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>
Converts
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