LLMSession

Struct LLMSession 

Source
pub struct LLMSession { /* private fields */ }
Expand description

A session that manages communication with an LLM

Implementations§

Source§

impl LLMSession

Source

pub fn new( config: LLMSessionConfig, from_llm: Sender<FromLLMPayload>, cancel_token: CancellationToken, ) -> Result<Self, LlmError>

Creates a new LLM session

§Arguments
  • config - Session configuration
  • from_llm - Sender for outgoing responses
  • cancel_token - Token for session cancellation
§Errors

Returns an error if the LLM client fails to initialize (e.g., TLS setup failure)

Source

pub fn id(&self) -> i64

Returns the session ID

Source

pub fn created_at(&self) -> Instant

Returns when the session was created

Source

pub fn model(&self) -> &str

Returns the model for this session

Source

pub fn set_max_tokens(&self, max_tokens: i64)

Sets the default maximum tokens for the session

Source

pub fn max_tokens(&self) -> i64

Returns the current max tokens setting

Source

pub fn context_limit(&self) -> i32

Returns the context limit for this session’s model

Source

pub async fn set_system_prompt(&self, prompt: String)

Sets the default system prompt for the session

Source

pub async fn clear_system_prompt(&self)

Clears the default system prompt

Source

pub async fn system_prompt(&self) -> Option<String>

Returns the current system prompt

Source

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.

Source

pub async fn clear_tools(&self)

Clears all tool definitions for this session.

Source

pub async fn tools(&self) -> Vec<LLMTool>

Returns a copy of the current tool definitions.

Source

pub async fn clear_conversation(&self)

Clears the conversation history and compact summaries.

Source

pub async fn force_compact(&self) -> CompactResult

Forces compaction to run immediately, regardless of threshold. Returns a CompactResult with details about what happened.

Source

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.

Source

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.

Source

pub fn shutdown(&self)

Gracefully shuts down the session. After calling this, the session will not accept new messages.

Source

pub fn is_shutdown(&self) -> bool

Returns true if the session has been shutdown

Source

pub async fn start(&self)

Starts the session’s main processing loop. This method processes requests from the ToLLM channel until shutdown. Should be spawned as a tokio task.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more