Skip to main content

LLMController

Struct LLMController 

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

The main LLM controller that manages sessions and coordinates communication

Implementations§

Source§

impl LLMController

Source

pub fn new( permission_registry: Arc<PermissionRegistry>, ui_tx: Option<Sender<UiMessage>>, channel_size: Option<usize>, ) -> LLMController

Creates a new LLM controller

§Arguments
  • permission_registry - Permission registry for batch permission requests
  • ui_tx - Optional UI channel sender for forwarding events
  • channel_size - Optional channel buffer size (defaults to DEFAULT_CHANNEL_SIZE)
Source

pub async fn start(&self)

Starts the controller’s event loop. This is idempotent - calling it multiple times has no effect. Should be spawned as a tokio task.

Source

pub async fn shutdown(&self)

Gracefully shuts down the controller and all sessions. This is idempotent - calling it multiple times has no effect.

Source

pub fn is_shutdown(&self) -> bool

Returns true if the controller has been shutdown

Source

pub fn is_started(&self) -> bool

Returns true if the controller has been started

Source

pub async fn create_session( &self, config: LLMSessionConfig, ) -> Result<i64, LlmError>

Creates a new LLM session.

§Arguments
  • config - Session configuration (includes model, API key, etc.)
§Returns

The session ID of the newly created session

§Errors

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

Source

pub async fn get_session(&self, session_id: i64) -> Option<Arc<LLMSession>>

Retrieves a session by its ID.

§Returns

The session if found, None otherwise

Source

pub async fn session_count(&self) -> usize

Returns the number of active sessions

Source

pub async fn remove_session(&self, session_id: i64) -> bool

Removes a session from the controller.

This only removes the session from the session manager. For full cleanup including permission and interaction registries, use AgentCore::remove_session.

§Arguments
  • session_id - The ID of the session to remove
§Returns

true if the session was found and removed, false otherwise

Source

pub async fn send_input( &self, input: ControllerInputPayload, ) -> Result<(), ControllerError>

Sends input to the controller for processing.

§Arguments
  • input - The input payload to send
§Returns

Ok(()) if the input was sent successfully, Err otherwise.

Source

pub async fn get_session_token_usage( &self, session_id: i64, ) -> Option<TokenMeter>

Get token usage for a specific session.

Source

pub async fn get_model_token_usage(&self, model: &str) -> Option<TokenMeter>

Get token usage for a specific model.

Source

pub async fn get_total_token_usage(&self) -> TokenMeter

Get total token usage across all sessions.

Source

pub fn token_usage(&self) -> &TokenUsageTracker

Get a reference to the token usage tracker for advanced queries.

Source

pub fn tool_registry(&self) -> &Arc<ToolRegistry>

Returns a reference to the tool registry.

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