pub struct LLMSession { /* private fields */ }Expand description
A session that manages communication with an LLM
Implementations§
Source§impl LLMSession
impl LLMSession
Sourcepub fn new(
config: LLMSessionConfig,
from_llm: Sender<FromLLMPayload>,
cancel_token: CancellationToken,
channel_size: usize,
) -> Result<Self, LlmError>
pub fn new( config: LLMSessionConfig, from_llm: Sender<FromLLMPayload>, cancel_token: CancellationToken, channel_size: usize, ) -> Result<Self, LlmError>
Creates a new LLM session
§Arguments
config- Session configurationfrom_llm- Sender for outgoing responsescancel_token- Token for session cancellationchannel_size- Buffer size for the session’s input channel
§Errors
Returns an error if the LLM client fails to initialize (e.g., TLS setup failure)
Sourcepub fn created_at(&self) -> Instant
pub fn created_at(&self) -> Instant
Returns when the session was created
Sourcepub fn set_max_tokens(&self, max_tokens: i64)
pub fn set_max_tokens(&self, max_tokens: i64)
Sets the default maximum tokens for the session
Sourcepub fn max_tokens(&self) -> i64
pub fn max_tokens(&self) -> i64
Returns the current max tokens setting
Sourcepub fn context_limit(&self) -> i32
pub fn context_limit(&self) -> i32
Returns the context limit for this session’s model
Sourcepub async fn set_system_prompt(&self, prompt: String)
pub async fn set_system_prompt(&self, prompt: String)
Sets the default system prompt for the session
Sourcepub async fn clear_system_prompt(&self)
pub async fn clear_system_prompt(&self)
Clears the default system prompt
Sourcepub async fn system_prompt(&self) -> Option<String>
pub async fn system_prompt(&self) -> Option<String>
Returns the current system prompt
Sourcepub async fn set_tools(&self, tools: Vec<LLMTool>)
pub async fn set_tools(&self, tools: Vec<LLMTool>)
Sets the tool definitions for this session. Tools will be included in all subsequent LLM API calls.
Sourcepub async fn clear_tools(&self)
pub async fn clear_tools(&self)
Clears all tool definitions for this session.
Sourcepub async fn clear_conversation(&self)
pub async fn clear_conversation(&self)
Clears the conversation history and compact summaries.
Sourcepub async fn force_compact(&self) -> CompactResult
pub async fn force_compact(&self) -> CompactResult
Forces compaction to run immediately, regardless of threshold.
Returns a CompactResult with details about what happened.
Sourcepub async fn send(&self, msg: ToLLMPayload) -> bool
pub async fn send(&self, msg: ToLLMPayload) -> bool
Sends a message to the LLM session for processing. Returns false if the session is shutdown or the channel is closed.
Sourcepub async fn interrupt(&self)
pub async fn interrupt(&self)
Interrupts the currently executing LLM request. This cancels any in-flight request and removes all messages from the current turn from conversation history. Does not shutdown the session.
Sourcepub fn shutdown(&self)
pub fn shutdown(&self)
Gracefully shuts down the session. After calling this, the session will not accept new messages.
Sourcepub fn is_shutdown(&self) -> bool
pub fn is_shutdown(&self) -> bool
Returns true if the session has been shutdown