pub struct Session { /* private fields */ }Expand description
A stateful conversation session.
Manages conversation history, session ID, and context automatically.
Users only need to call chat() with their input.
Implementations§
Source§impl Session
impl Session
Sourcepub async fn chat(
&self,
input: impl Into<String>,
) -> Result<AgentResponse, AgentError>
pub async fn chat( &self, input: impl Into<String>, ) -> Result<AgentResponse, AgentError>
Send a message and get a response.
This is the primary API for conversation. The session automatically manages context, history, and tool execution.
§Errors
Returns an error if the LLM call fails or internal state is inconsistent.
Sourcepub async fn chat_with_context(
&self,
input: impl Into<String>,
context: RequestContext,
) -> Result<AgentResponse, AgentError>
pub async fn chat_with_context( &self, input: impl Into<String>, context: RequestContext, ) -> Result<AgentResponse, AgentError>
Send a message with an explicit request context.
Use this when you need to customize tool policies, add skills context, or provide other per-request overrides.
§Errors
Returns an error if the LLM call fails or internal state is inconsistent.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
Get the session ID.
Sourcepub async fn reset(&self) -> Result<(), AgentError>
pub async fn reset(&self) -> Result<(), AgentError>
Reset the session (clear history but keep the same session ID).
This clears the conversation history in the session store while preserving cumulative token usage.
Sourcepub fn new_session(&self) -> Self
pub fn new_session(&self) -> Self
Start a new session with the same agent configuration.