Skip to main content

adk_acp/
toolset.rs

1//! ACP toolset — multiple ACP agents as a single ADK Toolset.
2
3use std::sync::Arc;
4
5use adk_core::{ReadonlyContext, Result, Tool, Toolset};
6use async_trait::async_trait;
7
8use crate::tool::AcpAgentTool;
9
10/// A collection of ACP agents exposed as an ADK Toolset.
11///
12/// Each agent becomes a named tool that can be invoked by the parent ADK agent.
13///
14/// # Example
15///
16/// ```rust,ignore
17/// use adk_acp::{AcpToolset, AcpAgentTool};
18///
19/// let toolset = AcpToolset::new("coding-agents")
20///     .add(AcpAgentTool::new("claude-code").description("Complex refactoring"))
21///     .add(AcpAgentTool::new("codex").description("Quick code generation"));
22///
23/// let agent = LlmAgentBuilder::new("orchestrator")
24///     .toolset(Arc::new(toolset))
25///     .build()?;
26/// ```
27pub struct AcpToolset {
28    name: String,
29    agents: Vec<Arc<AcpAgentTool>>,
30}
31
32impl AcpToolset {
33    /// Create a new empty ACP toolset.
34    pub fn new(name: impl Into<String>) -> Self {
35        Self { name: name.into(), agents: Vec::new() }
36    }
37
38    /// Add an ACP agent tool to the toolset.
39    pub fn with_agent(mut self, tool: AcpAgentTool) -> Self {
40        self.agents.push(Arc::new(tool));
41        self
42    }
43}
44
45#[async_trait]
46impl Toolset for AcpToolset {
47    fn name(&self) -> &str {
48        &self.name
49    }
50
51    async fn tools(&self, _ctx: Arc<dyn ReadonlyContext>) -> Result<Vec<Arc<dyn Tool>>> {
52        Ok(self.agents.iter().map(|a| a.clone() as Arc<dyn Tool>).collect())
53    }
54}