pub trait Agent: Send + Sync {
Show 15 methods
// Required methods
fn name(&self) -> &str;
fn model_name(&self) -> &str;
fn system_prompt(&self) -> &str;
fn execute<'a>(
&'a self,
task: &'a str,
) -> Pin<Box<dyn Future<Output = Result<String, ReactError>> + Send + 'a>>;
fn execute_stream<'a>(
&'a self,
task: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<AgentEvent, ReactError>> + Send + 'a>>, ReactError>> + Send + 'a>>;
// Provided methods
fn tool_names(&self) -> Vec<String> { ... }
fn tool_definitions(&self) -> Vec<ToolDefinition> { ... }
fn skill_names(&self) -> Vec<String> { ... }
fn mcp_server_names(&self) -> Vec<String> { ... }
fn close<'a>(&'a self) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>> { ... }
fn execute_stream_with_cancel<'a>(
&'a self,
task: &'a str,
cancel: CancellationToken,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<AgentEvent, ReactError>> + Send + 'a>>, ReactError>> + Send + 'a>> { ... }
fn chat<'a>(
&'a self,
message: &'a str,
) -> Pin<Box<dyn Future<Output = Result<String, ReactError>> + Send + 'a>> { ... }
fn chat_stream<'a>(
&'a self,
message: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<AgentEvent, ReactError>> + Send + 'a>>, ReactError>> + Send + 'a>> { ... }
fn chat_stream_with_cancel<'a>(
&'a self,
message: &'a str,
cancel: CancellationToken,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<AgentEvent, ReactError>> + Send + 'a>>, ReactError>> + Send + 'a>> { ... }
fn reset(&self) { ... }
}Expand description
Unified Agent execution interface
Establishes an execution model that is driven by a mutable borrow, allowing the Agent
to internally maintain dialogue state, tool caches, or connection handles, while the
workflow layer can safely serialize access through Mutex.
Required Methods§
Sourcefn model_name(&self) -> &str
fn model_name(&self) -> &str
Model identifier currently bound to the agent.
Sourcefn system_prompt(&self) -> &str
fn system_prompt(&self) -> &str
System prompt that seeds the agent’s behavior.
Sourcefn execute<'a>(
&'a self,
task: &'a str,
) -> Pin<Box<dyn Future<Output = Result<String, ReactError>> + Send + 'a>>
fn execute<'a>( &'a self, task: &'a str, ) -> Pin<Box<dyn Future<Output = Result<String, ReactError>> + Send + 'a>>
Execute a task and return the final answer.
Sourcefn execute_stream<'a>(
&'a self,
task: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<AgentEvent, ReactError>> + Send + 'a>>, ReactError>> + Send + 'a>>
fn execute_stream<'a>( &'a self, task: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<AgentEvent, ReactError>> + Send + 'a>>, ReactError>> + Send + 'a>>
Execute a task and stream lifecycle events.
Provided Methods§
Sourcefn tool_names(&self) -> Vec<String>
fn tool_names(&self) -> Vec<String>
Names of tools currently exposed to the model.
Sourcefn tool_definitions(&self) -> Vec<ToolDefinition>
fn tool_definitions(&self) -> Vec<ToolDefinition>
Tool definitions serialized into LLM requests.
Sourcefn skill_names(&self) -> Vec<String>
fn skill_names(&self) -> Vec<String>
Human-readable skill identifiers available to this agent.
Sourcefn mcp_server_names(&self) -> Vec<String>
fn mcp_server_names(&self) -> Vec<String>
Configured MCP server identifiers available to this agent.
Sourcefn close<'a>(&'a self) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>>
fn close<'a>(&'a self) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>>
Release external resources before dropping the agent.
Sourcefn execute_stream_with_cancel<'a>(
&'a self,
task: &'a str,
cancel: CancellationToken,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<AgentEvent, ReactError>> + Send + 'a>>, ReactError>> + Send + 'a>>
fn execute_stream_with_cancel<'a>( &'a self, task: &'a str, cancel: CancellationToken, ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<AgentEvent, ReactError>> + Send + 'a>>, ReactError>> + Send + 'a>>
Execute a task with cooperative cancellation support.
The default implementation wraps Self::execute_stream with a
cancellation-aware wrapper. When cancel is triggered, the stream
yields AgentEvent::Cancelled and terminates.
Sourcefn chat<'a>(
&'a self,
message: &'a str,
) -> Pin<Box<dyn Future<Output = Result<String, ReactError>> + Send + 'a>>
fn chat<'a>( &'a self, message: &'a str, ) -> Pin<Box<dyn Future<Output = Result<String, ReactError>> + Send + 'a>>
Alias of Self::execute for chat-centric call sites.
Sourcefn chat_stream<'a>(
&'a self,
message: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<AgentEvent, ReactError>> + Send + 'a>>, ReactError>> + Send + 'a>>
fn chat_stream<'a>( &'a self, message: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<AgentEvent, ReactError>> + Send + 'a>>, ReactError>> + Send + 'a>>
Alias of Self::execute_stream for chat-centric call sites.
Sourcefn chat_stream_with_cancel<'a>(
&'a self,
message: &'a str,
cancel: CancellationToken,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<AgentEvent, ReactError>> + Send + 'a>>, ReactError>> + Send + 'a>>
fn chat_stream_with_cancel<'a>( &'a self, message: &'a str, cancel: CancellationToken, ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<AgentEvent, ReactError>> + Send + 'a>>, ReactError>> + Send + 'a>>
Chat streaming variant with cooperative cancellation support.
The default implementation wraps Self::chat_stream with a
cancellation-aware wrapper. When cancel is triggered, the stream
yields AgentEvent::Cancelled and terminates.
Implementors§
impl Agent for PlanExecuteAgent
plan-execute only.impl Agent for ReactAgent
impl Agent for SelfReflectionAgent
self-reflection only.