Skip to main content

Agent

Trait Agent 

Source
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§

Source

fn name(&self) -> &str

Human-readable agent name used in logs, events, and orchestration.

Source

fn model_name(&self) -> &str

Model identifier currently bound to the agent.

Source

fn system_prompt(&self) -> &str

System prompt that seeds the agent’s behavior.

Source

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.

Source

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§

Source

fn tool_names(&self) -> Vec<String>

Names of tools currently exposed to the model.

Source

fn tool_definitions(&self) -> Vec<ToolDefinition>

Tool definitions serialized into LLM requests.

Source

fn skill_names(&self) -> Vec<String>

Human-readable skill identifiers available to this agent.

Source

fn mcp_server_names(&self) -> Vec<String>

Configured MCP server identifiers available to this agent.

Source

fn close<'a>(&'a self) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>>

Release external resources before dropping the agent.

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn reset(&self)

Reset in-memory conversational state.

Implementors§

Source§

impl Agent for PlanExecuteAgent

Available on crate feature plan-execute only.
Source§

impl Agent for ReactAgent

Source§

impl Agent for SelfReflectionAgent

Available on crate feature self-reflection only.