pub trait Agent {
// Required method
fn run_request_with_context<'life0, 'async_trait>(
&'life0 mut self,
request: RunRequest,
context: RunContext,
) -> Pin<Box<dyn Future<Output = Result<RunOutput, AgentError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided methods
fn run_request<'life0, 'async_trait>(
&'life0 mut self,
request: RunRequest,
) -> Pin<Box<dyn Future<Output = Result<RunOutput, AgentError>> + Send + 'async_trait>>
where Self: Send + 'async_trait,
'life0: 'async_trait { ... }
fn run<'life0, 'life1, 'async_trait>(
&'life0 mut self,
input: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<String, AgentError>> + Send + 'async_trait>>
where Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn run_stream_request_with_context<'a, 'async_trait>(
&'a mut self,
request: RunRequest,
context: RunContext,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'a, Result<MessageChunk, AgentError>>, AgentError>> + Send + 'async_trait>>
where Self: Send + 'async_trait,
'a: 'async_trait { ... }
fn run_stream_request<'a, 'async_trait>(
&'a mut self,
request: RunRequest,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'a, Result<MessageChunk, AgentError>>, AgentError>> + Send + 'async_trait>>
where Self: Send + 'async_trait,
'a: 'async_trait { ... }
fn run_stream<'a, 'async_trait>(
&'a mut self,
input: &'a str,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'a, Result<MessageChunk, AgentError>>, AgentError>> + Send + 'async_trait>>
where Self: Send + 'async_trait,
'a: 'async_trait { ... }
}Expand description
Reasoning-loop interface: one run takes the user input, drives the
reasoning loop, and returns the final answer.
Every reasoning loop (the built-in ReActAgent and custom
implementations) implements this trait. Cooperative cancellation and
deadlines are carried through RunContext.
The streaming and non-streaming entry points share the same semantics:
the reply is either given whole (run) or returned as a
MessageChunk stream (run_stream, ending with
MessageChunk::Done).
Required Methods§
Sourcefn run_request_with_context<'life0, 'async_trait>(
&'life0 mut self,
request: RunRequest,
context: RunContext,
) -> Pin<Box<dyn Future<Output = Result<RunOutput, AgentError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn run_request_with_context<'life0, 'async_trait>(
&'life0 mut self,
request: RunRequest,
context: RunContext,
) -> Pin<Box<dyn Future<Output = Result<RunOutput, AgentError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
One structured run with caller-provided execution context.
§Errors
Returns AgentError::Memory when context access fails;
AgentError::Provider when communicating with the LLM fails;
AgentError::TooManyToolRounds when the model keeps requesting
tools beyond AgentConfig::max_tool_rounds without a final answer;
AgentError::Cancelled when the run is cooperatively cancelled;
AgentError::DeadlineExceeded when the run-level deadline elapses.
Provided Methods§
Sourcefn run_request<'life0, 'async_trait>(
&'life0 mut self,
request: RunRequest,
) -> Pin<Box<dyn Future<Output = Result<RunOutput, AgentError>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
fn run_request<'life0, 'async_trait>(
&'life0 mut self,
request: RunRequest,
) -> Pin<Box<dyn Future<Output = Result<RunOutput, AgentError>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
One structured run with a generated RunContext.
Sourcefn run<'life0, 'life1, 'async_trait>(
&'life0 mut self,
input: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<String, AgentError>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn run<'life0, 'life1, 'async_trait>(
&'life0 mut self,
input: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<String, AgentError>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
One run: record the user input, drive the reasoning loop, and return the model’s final answer as text.
Sourcefn run_stream_request_with_context<'a, 'async_trait>(
&'a mut self,
request: RunRequest,
context: RunContext,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'a, Result<MessageChunk, AgentError>>, AgentError>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'a: 'async_trait,
fn run_stream_request_with_context<'a, 'async_trait>(
&'a mut self,
request: RunRequest,
context: RunContext,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'a, Result<MessageChunk, AgentError>>, AgentError>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'a: 'async_trait,
Streaming structured run with caller-provided execution context.
Sourcefn run_stream_request<'a, 'async_trait>(
&'a mut self,
request: RunRequest,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'a, Result<MessageChunk, AgentError>>, AgentError>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'a: 'async_trait,
fn run_stream_request<'a, 'async_trait>(
&'a mut self,
request: RunRequest,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'a, Result<MessageChunk, AgentError>>, AgentError>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'a: 'async_trait,
Streaming structured run with a generated RunContext.
Sourcefn run_stream<'a, 'async_trait>(
&'a mut self,
input: &'a str,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'a, Result<MessageChunk, AgentError>>, AgentError>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'a: 'async_trait,
fn run_stream<'a, 'async_trait>(
&'a mut self,
input: &'a str,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'a, Result<MessageChunk, AgentError>>, AgentError>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'a: 'async_trait,
Streaming run: same semantics as run, with the reply
returned as a stream of message chunks (see MessageChunk), ending
with MessageChunk::Done; errors are produced as Err items and
terminate the stream (no Done afterwards).
The default implementation is not truly streaming — it completes the
structured run first, then emits a single MessageChunk::Delta with
the final answer and a MessageChunk::Done carrying the run
summary. Implementations that need per-token streaming or tool
progress should override this method.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".