bamboo_engine/runtime/managers/
lifecycle.rs1use async_trait::async_trait;
2use bamboo_agent_core::tools::ToolExecutor;
3use bamboo_agent_core::{AgentError, AgentEvent, Session};
4use bamboo_domain::AgentRuntimeState;
5use bamboo_infrastructure::LLMProvider;
6use tokio::sync::mpsc;
7use tokio_util::sync::CancellationToken;
8
9use crate::runtime::config::AgentLoopConfig;
10use crate::runtime::task_context::TaskLoopContext;
11
12#[async_trait]
14pub trait LifecycleManager: Send + Sync {
15 fn initialize_run(&self, session: &Session, config: &AgentLoopConfig) -> AgentRuntimeState;
17
18 #[allow(clippy::too_many_arguments)]
20 async fn prepare_round(
21 &self,
22 session: &mut Session,
23 task_context: &mut Option<TaskLoopContext>,
24 runtime_state: &mut AgentRuntimeState,
25 round: usize,
26 max_rounds: usize,
27 config: &AgentLoopConfig,
28 cancel_token: &CancellationToken,
29 metrics_collector: Option<&crate::metrics::MetricsCollector>,
30 session_id: &str,
31 model_name: &str,
32 tools: &dyn ToolExecutor,
33 llm: &dyn LLMProvider,
34 ) -> Result<String, AgentError>;
35
36 async fn handle_round_outcome(
39 &self,
40 session: &mut Session,
41 runtime_state: &mut AgentRuntimeState,
42 task_context: &mut Option<TaskLoopContext>,
43 round: usize,
44 should_break: bool,
45 ) -> Result<bool, AgentError>;
46
47 #[allow(clippy::too_many_arguments)]
49 async fn finalize_run(
50 &self,
51 session: &mut Session,
52 runtime_state: &mut AgentRuntimeState,
53 event_tx: &mpsc::Sender<AgentEvent>,
54 session_id: &str,
55 config: &AgentLoopConfig,
56 metrics_collector: Option<&crate::metrics::MetricsCollector>,
57 task_context: Option<TaskLoopContext>,
58 );
59}