pub trait AgentExecutor: Send + Sync {
// Required methods
fn run<'life0, 'life1, 'async_trait>(
&'life0 self,
agent: &'life1 dyn Agent,
input: AgentInput,
) -> Pin<Box<dyn Future<Output = Result<AgentOutput, AgentError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn run_stream(
&self,
input: AgentInput,
) -> BoxStream<'static, Result<ChannelEvent, AgentError>>;
}Expand description
Agent 执行器 trait
用于执行 Agent 的运行逻辑,支持工具调用、流式输出等。 这是实现 dyn 兼容的关键。
Required Methods§
Sourcefn run<'life0, 'life1, 'async_trait>(
&'life0 self,
agent: &'life1 dyn Agent,
input: AgentInput,
) -> Pin<Box<dyn Future<Output = Result<AgentOutput, AgentError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn run<'life0, 'life1, 'async_trait>(
&'life0 self,
agent: &'life1 dyn Agent,
input: AgentInput,
) -> Pin<Box<dyn Future<Output = Result<AgentOutput, AgentError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
运行 Agent
Sourcefn run_stream(
&self,
input: AgentInput,
) -> BoxStream<'static, Result<ChannelEvent, AgentError>>
fn run_stream( &self, input: AgentInput, ) -> BoxStream<'static, Result<ChannelEvent, AgentError>>
流式运行 Agent
注意:由于生命周期限制,此方法不支持 Agent 决策。 它只执行简单的工具调用循环。