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,
) -> Result<Self, LlmError>
pub fn new( config: LLMSessionConfig, from_llm: Sender<FromLLMPayload>, cancel_token: CancellationToken, ) -> Result<Self, LlmError>
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
Auto Trait Implementations§
impl !Freeze for LLMSession
impl !RefUnwindSafe for LLMSession
impl Send for LLMSession
impl Sync for LLMSession
impl Unpin for LLMSession
impl !UnwindSafe for LLMSession
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more