Skip to main content

AgentRuntimeTrait

Trait AgentRuntimeTrait 

Source
pub trait AgentRuntimeTrait: Send + Sync {
    // Required methods
    fn run<'life0, 'life1, 'async_trait>(
        &'life0 self,
        task: &'life1 str,
        config: AgentConfig,
    ) -> Pin<Box<dyn Future<Output = Layer2Result<AgentResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn run_stream<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        task: &'life1 str,
        config: AgentConfig,
        callback: &'life2 dyn AgentLoopCallback,
    ) -> Pin<Box<dyn Future<Output = Layer2Result<AgentResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn run_stream_abortable<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        task: &'life1 str,
        config: AgentConfig,
        callback: &'life2 dyn AgentLoopCallback,
        abort_flag: Arc<AtomicBool>,
    ) -> Pin<Box<dyn Future<Output = Layer2Result<AgentResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn start<'life0, 'life1, 'async_trait>(
        &'life0 self,
        task: &'life1 str,
        config: AgentConfig,
    ) -> Pin<Box<dyn Future<Output = Layer2Result<SessionId>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn pause<'life0, 'life1, 'async_trait>(
        &'life0 self,
        session_id: &'life1 SessionId,
    ) -> Pin<Box<dyn Future<Output = Layer2Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn resume<'life0, 'life1, 'async_trait>(
        &'life0 self,
        session_id: &'life1 SessionId,
    ) -> Pin<Box<dyn Future<Output = Layer2Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn stop<'life0, 'life1, 'async_trait>(
        &'life0 self,
        session_id: &'life1 SessionId,
    ) -> Pin<Box<dyn Future<Output = Layer2Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn status(&self, session_id: &SessionId) -> Layer2Result<AgentState>;
    fn send_message<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        session_id: &'life1 SessionId,
        message: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Layer2Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn submit_tool_result<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        session_id: &'life1 SessionId,
        tool_call_id: &'life2 str,
        result: ToolResult,
    ) -> Pin<Box<dyn Future<Output = Layer2Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
}
Expand description

Agent 运行时接口

定义 Agent 执行的核心生命周期操作。

Required Methods§

Source

fn run<'life0, 'life1, 'async_trait>( &'life0 self, task: &'life1 str, config: AgentConfig, ) -> Pin<Box<dyn Future<Output = Layer2Result<AgentResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

启动 Agent 执行

§Arguments
  • task - 用户任务描述
  • config - Agent 配置
§Returns

执行结果,包含最终状态和输出

Source

fn run_stream<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, task: &'life1 str, config: AgentConfig, callback: &'life2 dyn AgentLoopCallback, ) -> Pin<Box<dyn Future<Output = Layer2Result<AgentResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

流式启动 Agent 执行

Source

fn run_stream_abortable<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, task: &'life1 str, config: AgentConfig, callback: &'life2 dyn AgentLoopCallback, abort_flag: Arc<AtomicBool>, ) -> Pin<Box<dyn Future<Output = Layer2Result<AgentResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

流式启动 Agent 执行(支持中断)

Source

fn start<'life0, 'life1, 'async_trait>( &'life0 self, task: &'life1 str, config: AgentConfig, ) -> Pin<Box<dyn Future<Output = Layer2Result<SessionId>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

启动 Agent 并返回会话 ID(用于流式执行)

§Arguments
  • task - 用户任务描述
  • config - Agent 配置
§Returns

会话 ID,用于后续操作

Source

fn pause<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 SessionId, ) -> Pin<Box<dyn Future<Output = Layer2Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

暂停正在执行的 Agent

§Arguments
  • session_id - 会话 ID
Source

fn resume<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 SessionId, ) -> Pin<Box<dyn Future<Output = Layer2Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

恢复暂停的 Agent

§Arguments
  • session_id - 会话 ID
Source

fn stop<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 SessionId, ) -> Pin<Box<dyn Future<Output = Layer2Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

停止 Agent 执行

§Arguments
  • session_id - 会话 ID
Source

fn status(&self, session_id: &SessionId) -> Layer2Result<AgentState>

获取 Agent 当前状态

§Arguments
  • session_id - 会话 ID
Source

fn send_message<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, session_id: &'life1 SessionId, message: &'life2 str, ) -> Pin<Box<dyn Future<Output = Layer2Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

向 Agent 发送消息

§Arguments
  • session_id - 会话 ID
  • message - 消息内容
Source

fn submit_tool_result<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, session_id: &'life1 SessionId, tool_call_id: &'life2 str, result: ToolResult, ) -> Pin<Box<dyn Future<Output = Layer2Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

获取 Agent 的工具调用结果

§Arguments
  • session_id - 会话 ID
  • tool_call_id - 工具调用 ID

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§