Skip to main content

ThreadManager

Struct ThreadManager 

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

Manages all agent threads with event emission.

Implementations§

Source§

impl ThreadManager

Source

pub fn new() -> Self

Create a new thread manager.

Source

pub fn with_config(config: ThreadManagerConfig) -> Self

Create with custom config.

Source

pub fn subscribe(&self) -> Receiver<ThreadEvent>

Subscribe to thread events.

Source

pub fn create_chat(&mut self, label: impl Into<String>) -> ThreadId

Create a new chat thread and make it foreground.

Source

pub fn create_subagent( &mut self, label: impl Into<String>, agent_id: impl Into<String>, task: impl Into<String>, parent_id: Option<ThreadId>, ) -> ThreadId

Create a sub-agent thread.

Source

pub fn create_background( &mut self, label: impl Into<String>, purpose: impl Into<String>, parent_id: Option<ThreadId>, ) -> ThreadId

Create a background thread.

Source

pub fn create_task( &mut self, label: impl Into<String>, action: impl Into<String>, parent_id: Option<ThreadId>, ) -> ThreadId

Create a task thread.

Source

pub fn get(&self, id: ThreadId) -> Option<&AgentThread>

Get a thread by ID.

Source

pub fn get_mut(&mut self, id: ThreadId) -> Option<&mut AgentThread>

Get a mutable thread by ID.

Source

pub fn foreground(&self) -> Option<&AgentThread>

Get the foreground thread.

Source

pub fn foreground_mut(&mut self) -> Option<&mut AgentThread>

Get the foreground thread mutably.

Source

pub fn foreground_id(&self) -> Option<ThreadId>

Get foreground thread ID.

Source

pub fn list(&self) -> Vec<&AgentThread>

List all threads.

Source

pub fn list_info(&self) -> Vec<ThreadInfo>

List thread info for sidebar display.

Source

pub fn set_description(&mut self, id: ThreadId, description: impl Into<String>)

Set description for a thread.

Source

pub fn set_foreground_description(&mut self, description: impl Into<String>)

Set description for the foreground thread.

Source

pub fn set_status(&mut self, id: ThreadId, status: ThreadStatus)

Update thread status.

Source

pub fn switch_foreground(&mut self, id: ThreadId) -> bool

Switch foreground to a different thread.

Source

pub fn clear_foreground(&mut self)

Clear the foreground — no thread is active (background all).

Source

pub fn rename(&mut self, id: ThreadId, new_label: impl Into<String>) -> bool

Rename a thread.

Source

pub fn find_best_match(&self, content: &str) -> Option<ThreadId>

Find the best matching thread for a given message content. Returns the thread ID if a good match is found, None otherwise.

Source

pub fn complete( &mut self, id: ThreadId, summary: Option<String>, result: Option<String>, )

Mark a thread as completed.

Source

pub fn fail(&mut self, id: ThreadId, error: impl Into<String>)

Mark a thread as failed.

Source

pub fn add_message( &mut self, id: ThreadId, role: MessageRole, content: impl Into<String>, )

Add a message to a thread.

Source

pub fn add_foreground_message( &mut self, role: MessageRole, content: impl Into<String>, )

Add a message to the foreground thread.

Source

pub fn remove(&mut self, id: ThreadId) -> Option<AgentThread>

Remove a thread.

Source

pub fn cleanup_ephemeral(&mut self)

Clean up old ephemeral threads.

Source

pub fn build_global_context(&self) -> String

Build global context from all threads that share context.

Source

pub fn save_to_file(&self, path: &Path) -> Result<()>

Save threads to a file.

Source

pub fn load_from_file(path: &Path) -> Result<Self>

Load threads from a file.

Source

pub fn load_or_default(path: &Path) -> Self

Load from file or create with default chat thread.

Source

pub fn create_thread(&mut self, label: impl Into<String>) -> ThreadId

Alias for create_chat (old API compatibility).

Source

pub fn switch_to(&mut self, id: ThreadId) -> Option<ThreadId>

Alias for switch_foreground that returns old foreground ID (old API compatibility).

Source

pub fn get_by_id(&self, id: ThreadId) -> Option<&AgentThread>

Get a thread by ID (compatibility - already exists as get()).

Source

pub fn get_by_id_mut(&mut self, id: ThreadId) -> Option<&mut AgentThread>

Get a mutable thread by ID (compatibility - already exists as get_mut()).

Trait Implementations§

Source§

impl Default for ThreadManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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