Skip to main content

Session

Defined in the session module.
Rust AI Agent SDK Session manager - main API for session persistence

Fields

NameTypeDescription
session_idString-
dataSessionData-
storeArc<dyn SessionStore>-

Methods

new

fn new(session_id: impl Into<String>) -> Self
Create a new session with default file store Parameters:
NameType
session_idimpl Into&lt;String&gt;

with_store

fn with_store(session_id: impl Into<String>, store: Arc<dyn SessionStore>) -> Self
Create with custom store Parameters:
NameType
session_idimpl Into&lt;String&gt;
storeArc&lt;dyn SessionStore&gt;

load

fn load(session_id: impl Into<String>) -> Result<Self>
Load an existing session Parameters:
NameType
session_idimpl Into&lt;String&gt;

id

fn id(&self) -> &str
Get session ID

add_user_message

fn add_user_message(&mut self, content: impl Into<String>) -> Result<()>
Add a user message Parameters:
NameType
contentimpl Into&lt;String&gt;

add_assistant_message

fn add_assistant_message(&mut self, content: impl Into<String>) -> Result<()>
Add an assistant message Parameters:
NameType
contentimpl Into&lt;String&gt;

add_message

fn add_message(&mut self, role: &str, content: impl Into<String>) -> Result<()>
Add a message with role Parameters:
NameType
role&str
contentimpl Into&lt;String&gt;

get_history

fn get_history(&self, max_messages: Option<usize>) -> Vec<Message>
Get chat history as LLM messages Parameters:
NameType
max_messagesOption&lt;usize&gt;

messages

fn messages(&self) -> &[SessionMessage]
Get all messages

message_count

fn message_count(&self) -> usize
Get message count

set_agent_name

fn set_agent_name(&mut self, name: impl Into<String>) -> Result<()>
Set agent name Parameters:
NameType
nameimpl Into&lt;String&gt;

set_user_id

fn set_user_id(&mut self, user_id: impl Into<String>) -> Result<()>
Set user ID Parameters:
NameType
user_idimpl Into&lt;String&gt;

clear

fn clear(&mut self) -> Result<()>
Clear all messages

delete

fn delete(self) -> Result<()>
Delete the session

exists

fn exists(&self) -> bool
Check if session exists on disk

save

fn save(&self) -> Result<()>
Save current state

Source

View on GitHub

praisonai/src/session/mod.rs at line 440