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(())
}
}