Skip to main content

AgentLifecycle

Trait AgentLifecycle 

Source
pub trait AgentLifecycle: MoFAAgent {
    // Required methods
    fn pause<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = AgentResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn resume<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = AgentResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Agent 生命周期扩展

提供额外的生命周期控制方法,用于需要更细粒度控制的场景。 这个 trait 是可选的,只有需要这些功能的 Agent 才需要实现。

§提供的方法

  • pause() - 暂停执行
  • resume() - 恢复执行

§示例

use mofa_kernel::agent::core::AgentLifecycle;

#[async_trait]
impl AgentLifecycle for MyAgent {
    async fn pause(&mut self) -> AgentResult<()> {
        self.state = AgentState::Paused;
        Ok(())
    }

    async fn resume(&mut self) -> AgentResult<()> {
        self.state = AgentState::Ready;
        Ok(())
    }
}

Required Methods§

Source

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

暂停 Agent

暂停当前执行,保持状态以便后续恢复。

§状态转换

Executing -> Paused

Source

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

恢复 Agent

从暂停状态恢复执行。

§状态转换

Paused -> Ready

Implementors§