pub struct Agent { /* private fields */ }
Expand description
Agents are the main interface for building agentic systems.
Construct agents by calling the builder, setting an llm, configure hooks, tools and other customizations.
§Important defaults
- The default context is the
DefaultContext
, executing tools locally with theLocalExecutor
. - A default
stop
tool is provided for agents to explicitly stop if needed - The default
SystemPrompt
instructs the agent with chain of thought and some common safeguards, but is otherwise quite bare. In a lot of cases this can be sufficient.
Implementations§
Source§impl Agent
impl Agent
Sourcepub async fn query(&mut self, query: impl Into<String> + Debug) -> Result<()>
pub async fn query(&mut self, query: impl Into<String> + Debug) -> Result<()>
Run the agent with a user message. The agent will loop completions, make tool calls, until no new messages are available.
Sourcepub async fn query_once(
&mut self,
query: impl Into<String> + Debug,
) -> Result<()>
pub async fn query_once( &mut self, query: impl Into<String> + Debug, ) -> Result<()>
Run the agent with a user message once.
Sourcepub async fn run(&mut self) -> Result<()>
pub async fn run(&mut self) -> Result<()>
Run the agent with without user message. The agent will loop completions, make tool calls, until no new messages are available.
Sourcepub async fn run_once(&mut self) -> Result<()>
pub async fn run_once(&mut self) -> Result<()>
Run the agent with without user message. The agent will loop completions, make tool calls, until
Sourcepub async fn history(&self) -> Vec<ChatMessage>
pub async fn history(&self) -> Vec<ChatMessage>
Retrieve the message history of the agent
Sourcepub fn context(&self) -> &dyn AgentContext
pub fn context(&self) -> &dyn AgentContext
Access the agent’s context
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
The agent is still running
Sourcepub fn is_stopped(&self) -> bool
pub fn is_stopped(&self) -> bool
The agent stopped
Sourcepub fn is_pending(&self) -> bool
pub fn is_pending(&self) -> bool
The agent has not (ever) started
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Agent
impl !RefUnwindSafe for Agent
impl Send for Agent
impl Sync for Agent
impl Unpin for Agent
impl !UnwindSafe for Agent
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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 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>
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