Skip to main content

adk_devtools/
toolset.rs

1//! [`DevToolset`] — the developer tools as a single [`Toolset`].
2
3use std::sync::Arc;
4
5use adk_core::{ReadonlyContext, Result, Tool, Toolset};
6use async_trait::async_trait;
7
8use crate::tools::{
9    ApplyPatchTool, BashTool, EditFileTool, GlobTool, GrepTool, ReadFileTool, WriteFileTool,
10};
11use crate::workspace::Workspace;
12
13/// Bundles the developer tools (`read_file`, `write_file`, `edit_file`, `apply_patch`,
14/// `glob`, `grep`, `bash`) so they can be attached to an agent in one call.
15///
16/// Mutating tools (`write_file`, `edit_file`, `apply_patch`) are omitted when the workspace is
17/// read-only, and `bash` is omitted when bash is disabled — so the toolset the
18/// model sees always matches what the workspace actually permits.
19pub struct DevToolset {
20    workspace: Workspace,
21    include_bash: bool,
22}
23
24impl DevToolset {
25    /// Create a toolset over `workspace` with all permitted tools enabled.
26    pub fn new(workspace: Workspace) -> Self {
27        Self { workspace, include_bash: true }
28    }
29
30    /// Enable or disable exposing the `bash` tool (independent of the workspace
31    /// bash flag; both must allow it).
32    pub fn with_bash(mut self, include: bool) -> Self {
33        self.include_bash = include;
34        self
35    }
36}
37
38#[async_trait]
39impl Toolset for DevToolset {
40    fn name(&self) -> &str {
41        "devtools"
42    }
43
44    async fn tools(&self, _ctx: Arc<dyn ReadonlyContext>) -> Result<Vec<Arc<dyn Tool>>> {
45        let ws = self.workspace.clone();
46        let mut tools: Vec<Arc<dyn Tool>> = vec![
47            Arc::new(ReadFileTool::new(ws.clone())),
48            Arc::new(GlobTool::new(ws.clone())),
49            Arc::new(GrepTool::new(ws.clone())),
50        ];
51        if ws.is_writable() {
52            tools.push(Arc::new(WriteFileTool::new(ws.clone())));
53            tools.push(Arc::new(EditFileTool::new(ws.clone())));
54            tools.push(Arc::new(ApplyPatchTool::new(ws.clone())));
55        }
56        if self.include_bash && ws.bash_allowed() {
57            tools.push(Arc::new(BashTool::new(ws.clone())));
58        }
59        Ok(tools)
60    }
61}