pub struct Agent { /* private fields */ }Expand description
The agent runtime that orchestrates LLM calls and tool execution.
Implementations§
Source§impl Agent
impl Agent
Sourcepub fn new(
provider: Arc<dyn Provider>,
tools: ToolRegistry,
config: AgentConfig,
) -> Self
pub fn new( provider: Arc<dyn Provider>, tools: ToolRegistry, config: AgentConfig, ) -> Self
Create a new agent with the given provider and tools.
Sourcepub fn clear_messages(&mut self)
pub fn clear_messages(&mut self)
Clear the message history.
Sourcepub fn add_message(&mut self, message: Message)
pub fn add_message(&mut self, message: Message)
Add a message to the history.
Sourcepub fn replace_messages(&mut self, messages: Vec<Message>)
pub fn replace_messages(&mut self, messages: Vec<Message>)
Replace the message history.
Sourcepub fn set_provider(&mut self, provider: Arc<dyn Provider>)
pub fn set_provider(&mut self, provider: Arc<dyn Provider>)
Replace the provider implementation (used for model/provider switching).
Sourcepub fn register_message_fetchers(
&mut self,
steering: Option<MessageFetcher>,
follow_up: Option<MessageFetcher>,
)
pub fn register_message_fetchers( &mut self, steering: Option<MessageFetcher>, follow_up: Option<MessageFetcher>, )
Register async fetchers for queued steering/follow-up messages.
This is additive: multiple sources (e.g. RPC, extensions) can register fetchers, and the agent will poll all of them.
Sourcepub fn extend_tools<I>(&mut self, tools: I)
pub fn extend_tools<I>(&mut self, tools: I)
Extend the tool registry with additional tools (e.g. extension-registered tools).
Sourcepub fn queue_steering(&mut self, message: Message) -> u64
pub fn queue_steering(&mut self, message: Message) -> u64
Queue a steering message (delivered after tool completion).
Sourcepub fn queue_follow_up(&mut self, message: Message) -> u64
pub fn queue_follow_up(&mut self, message: Message) -> u64
Queue a follow-up message (delivered when agent becomes idle).
Sourcepub const fn set_queue_modes(
&mut self,
steering: QueueMode,
follow_up: QueueMode,
)
pub const fn set_queue_modes( &mut self, steering: QueueMode, follow_up: QueueMode, )
Configure queue delivery modes.
Sourcepub fn queued_message_count(&self) -> usize
pub fn queued_message_count(&self) -> usize
Count queued messages (steering + follow-up).
pub fn provider(&self) -> Arc<dyn Provider>
pub const fn stream_options(&self) -> &StreamOptions
pub const fn stream_options_mut(&mut self) -> &mut StreamOptions
Sourcepub async fn run(
&mut self,
user_input: impl Into<String>,
on_event: impl Fn(AgentEvent) + Send + Sync + 'static,
) -> Result<AssistantMessage>
pub async fn run( &mut self, user_input: impl Into<String>, on_event: impl Fn(AgentEvent) + Send + Sync + 'static, ) -> Result<AssistantMessage>
Run the agent with a user message.
Returns a stream of events and the final assistant message.
Sourcepub async fn run_with_abort(
&mut self,
user_input: impl Into<String>,
abort: Option<AbortSignal>,
on_event: impl Fn(AgentEvent) + Send + Sync + 'static,
) -> Result<AssistantMessage>
pub async fn run_with_abort( &mut self, user_input: impl Into<String>, abort: Option<AbortSignal>, on_event: impl Fn(AgentEvent) + Send + Sync + 'static, ) -> Result<AssistantMessage>
Run the agent with a user message and abort support.
Sourcepub async fn run_with_content(
&mut self,
content: Vec<ContentBlock>,
on_event: impl Fn(AgentEvent) + Send + Sync + 'static,
) -> Result<AssistantMessage>
pub async fn run_with_content( &mut self, content: Vec<ContentBlock>, on_event: impl Fn(AgentEvent) + Send + Sync + 'static, ) -> Result<AssistantMessage>
Run the agent with structured content (text + images).
Sourcepub async fn run_with_content_with_abort(
&mut self,
content: Vec<ContentBlock>,
abort: Option<AbortSignal>,
on_event: impl Fn(AgentEvent) + Send + Sync + 'static,
) -> Result<AssistantMessage>
pub async fn run_with_content_with_abort( &mut self, content: Vec<ContentBlock>, abort: Option<AbortSignal>, on_event: impl Fn(AgentEvent) + Send + Sync + 'static, ) -> Result<AssistantMessage>
Run the agent with structured content (text + images) and abort support.
Sourcepub async fn run_with_message_with_abort(
&mut self,
message: Message,
abort: Option<AbortSignal>,
on_event: impl Fn(AgentEvent) + Send + Sync + 'static,
) -> Result<AssistantMessage>
pub async fn run_with_message_with_abort( &mut self, message: Message, abort: Option<AbortSignal>, on_event: impl Fn(AgentEvent) + Send + Sync + 'static, ) -> Result<AssistantMessage>
Run the agent with a pre-constructed user message and abort support.
Sourcepub async fn run_continue_with_abort(
&mut self,
abort: Option<AbortSignal>,
on_event: impl Fn(AgentEvent) + Send + Sync + 'static,
) -> Result<AssistantMessage>
pub async fn run_continue_with_abort( &mut self, abort: Option<AbortSignal>, on_event: impl Fn(AgentEvent) + Send + Sync + 'static, ) -> Result<AssistantMessage>
Continue the agent loop without adding a new prompt message (used for retries).
Auto Trait Implementations§
impl Freeze for Agent
impl !RefUnwindSafe for Agent
impl Send for Agent
impl Sync for Agent
impl Unpin for Agent
impl UnsafeUnpin for Agent
impl !UnwindSafe for Agent
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
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