pub struct Context {
pub id: String,
pub history: VecDeque<ContextMessage>,
pub user: UserContext,
pub variables: HashMap<String, Value>,
pub metadata: ContextMetadata,
pub token_count: usize,
}Expand description
Conversation context containing state and history
Fields§
§id: StringUnique context ID
history: VecDeque<ContextMessage>Conversation history
user: UserContextUser information
variables: HashMap<String, Value>Session variables
metadata: ContextMetadataContext metadata
token_count: usizeToken count for the context
Implementations§
Source§impl Context
impl Context
Sourcepub fn add_message(&mut self, message: &Message)
pub fn add_message(&mut self, message: &Message)
Add a message to the history
Sourcepub fn add_response(&mut self, response: &Response)
pub fn add_response(&mut self, response: &Response)
Add a response to the history
Sourcepub fn trim_to_token_limit(&mut self, max_tokens: usize)
pub fn trim_to_token_limit(&mut self, max_tokens: usize)
Trim history to fit within token limit
Sourcepub fn get_variable(&self, key: &str) -> Option<&Value>
pub fn get_variable(&self, key: &str) -> Option<&Value>
Get a variable value
Sourcepub fn set_variable(&mut self, key: impl Into<String>, value: Value)
pub fn set_variable(&mut self, key: impl Into<String>, value: Value)
Set a variable value
Sourcepub fn clear_history(&mut self)
pub fn clear_history(&mut self)
Clear all history
Sourcepub fn is_expired(&self, ttl: Duration) -> bool
pub fn is_expired(&self, ttl: Duration) -> bool
Check if the context is expired
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Context
impl<'de> Deserialize<'de> for Context
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnwindSafe for Context
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