Skip to main content

bamboo_engine/runtime/managers/
tool.rs

1use crate::metrics::MetricsCollector;
2use async_trait::async_trait;
3use bamboo_agent_core::tools::{ToolCall, ToolSchema};
4use bamboo_agent_core::{AgentError, AgentEvent, Session};
5use tokio::sync::mpsc;
6
7use crate::runtime::config::AgentLoopConfig;
8use crate::runtime::task_context::TaskLoopContext;
9
10/// Result of a round's tool execution.
11#[derive(Debug, Clone)]
12pub struct ToolRoundResult {
13    pub awaiting_clarification: bool,
14    pub should_break: bool,
15    pub tool_calls_count: usize,
16}
17
18/// Manages tool surface, schemas, routing, execution, and output processing.
19#[async_trait]
20pub trait ToolManager: Send + Sync {
21    /// Resolve available tool schemas for the session.
22    fn resolve_tool_schemas(&self, config: &AgentLoopConfig, session: &Session) -> Vec<ToolSchema>;
23
24    /// Execute tool calls for a round.
25    #[allow(clippy::too_many_arguments)]
26    async fn execute_tool_calls(
27        &self,
28        tool_calls: &[ToolCall],
29        event_tx: &mpsc::Sender<AgentEvent>,
30        metrics_collector: Option<&MetricsCollector>,
31        session_id: &str,
32        round_id: &str,
33        round: usize,
34        session: &mut Session,
35        config: &AgentLoopConfig,
36        task_context: &mut Option<TaskLoopContext>,
37        tool_schemas: &[ToolSchema],
38    ) -> Result<ToolRoundResult, AgentError>;
39}