pub struct Session {
pub metadata: SessionMetadata,
pub entries: Vec<SessionEntry>,
pub context: HashMap<String, Value>,
}Expand description
Complete session data.
Fields§
§metadata: SessionMetadataSession metadata.
entries: Vec<SessionEntry>Session entries (conversation history, tool calls, etc.).
context: HashMap<String, Value>Session context data (key-value store).
Implementations§
Source§impl Session
impl Session
Sourcepub fn new(name: impl Into<String>, session_type: SessionType) -> Self
pub fn new(name: impl Into<String>, session_type: SessionType) -> Self
Create a new session.
Sourcepub fn status(&self) -> SessionStatus
pub fn status(&self) -> SessionStatus
Get the session status.
Sourcepub fn add_entry(&mut self, entry: SessionEntry)
pub fn add_entry(&mut self, entry: SessionEntry)
Add an entry to the session.
Sourcepub fn add_user_message(&mut self, content: impl Into<String>)
pub fn add_user_message(&mut self, content: impl Into<String>)
Add a user message.
Sourcepub fn add_assistant_message(&mut self, content: impl Into<String>)
pub fn add_assistant_message(&mut self, content: impl Into<String>)
Add an assistant message.
Sourcepub fn set_context(&mut self, key: impl Into<String>, value: Value)
pub fn set_context(&mut self, key: impl Into<String>, value: Value)
Set context value.
Sourcepub fn get_context(&self, key: &str) -> Option<&Value>
pub fn get_context(&self, key: &str) -> Option<&Value>
Get context value.
Sourcepub fn set_status(&mut self, status: SessionStatus)
pub fn set_status(&mut self, status: SessionStatus)
Update session status.
Sourcepub fn turn_count(&self) -> u32
pub fn turn_count(&self) -> u32
Count the number of turns in the session.
A turn is defined as a user message followed by an assistant message. This counts the number of complete turns.
Sourcepub fn user_message_count(&self) -> usize
pub fn user_message_count(&self) -> usize
Count user messages in the session.
Sourcepub fn assistant_message_count(&self) -> usize
pub fn assistant_message_count(&self) -> usize
Count assistant messages in the session.
Source§impl Session
impl Session
Sourcepub fn check_limits(&self, config: &SessionConfig) -> LimitCheck
pub fn check_limits(&self, config: &SessionConfig) -> LimitCheck
Check if the session is within limits.
Sourcepub fn is_at_turn_limit(&self, config: &SessionConfig) -> bool
pub fn is_at_turn_limit(&self, config: &SessionConfig) -> bool
Check if the session is at its turn limit.
Sourcepub fn remaining_turns(&self, config: &SessionConfig) -> Option<u32>
pub fn remaining_turns(&self, config: &SessionConfig) -> Option<u32>
Get remaining turns before limit.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Session
impl<'de> Deserialize<'de> for Session
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 Session
impl RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnwindSafe for Session
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