Skip to main content

a3s_code_core/tools/builtin/
mod.rs

1//! Native Rust implementations of all built-in tools
2//!
3//! These replace the previous `a3s-tools` binary backend with direct Rust
4//! implementations that execute in-process. Each tool implements the `Tool` trait.
5//!
6//! `agentic_search` and `agentic_parse` are native built-in tools.
7//! Session builders decide whether they are enabled by default based on config.
8
9pub(crate) mod agentic_parse;
10pub(crate) mod agentic_search;
11mod bash;
12pub mod batch;
13mod edit;
14mod git_worktree;
15mod glob_tool;
16mod grep;
17mod ls;
18mod patch;
19mod read;
20mod web_fetch;
21mod web_search;
22mod write;
23
24use super::registry::ToolRegistry;
25use std::sync::Arc;
26
27/// Register all baseline built-in tools with the registry.
28///
29/// Note: `batch` is NOT registered here — it requires an `Arc<ToolRegistry>`
30/// and must be registered after the registry is wrapped in an Arc.
31pub fn register_builtins(registry: &ToolRegistry) {
32    registry.register_builtin(Arc::new(read::ReadTool));
33    registry.register_builtin(Arc::new(write::WriteTool));
34    registry.register_builtin(Arc::new(edit::EditTool));
35    registry.register_builtin(Arc::new(patch::PatchTool));
36    registry.register_builtin(Arc::new(bash::BashTool));
37    registry.register_builtin(Arc::new(grep::GrepTool));
38    registry.register_builtin(Arc::new(glob_tool::GlobTool));
39    registry.register_builtin(Arc::new(ls::LsTool));
40    registry.register_builtin(Arc::new(web_fetch::WebFetchTool));
41    registry.register_builtin(Arc::new(web_search::WebSearchTool));
42    registry.register_builtin(Arc::new(git_worktree::GitWorktreeTool));
43}
44
45/// Register the batch tool. Must be called after the registry is wrapped in Arc.
46pub fn register_batch(registry: &Arc<ToolRegistry>) {
47    registry.register_builtin(Arc::new(batch::BatchTool::new(Arc::clone(registry))));
48}
49
50/// Register the built-in agentic tools.
51///
52/// - `agentic_search`: multi-phase semantic code search
53/// - `agentic_parse`: LLM-enhanced document parsing
54pub fn register_agentic_tools(
55    registry: &Arc<ToolRegistry>,
56    llm: Option<Arc<dyn crate::llm::LlmClient>>,
57    search_enabled: bool,
58    parse_enabled: bool,
59) {
60    if search_enabled {
61        registry.register_builtin(Arc::new(agentic_search::AgenticSearchTool::new()));
62    }
63    if parse_enabled {
64        let llm_client =
65            llm.expect("agentic_parse requires an LLM client when registered as a built-in tool");
66        registry.register_builtin(Arc::new(agentic_parse::AgenticParseTool::new(llm_client)));
67    }
68}
69
70/// Register the task delegation tools (task, parallel_task).
71///
72/// Must be called after the registry is wrapped in Arc. Requires an LLM client
73/// and the workspace path so child agent loops can be spawned inline.
74/// Optionally accepts an MCP manager so child sessions inherit MCP tools.
75pub fn register_task(
76    registry: &Arc<ToolRegistry>,
77    llm_client: Arc<dyn crate::llm::LlmClient>,
78    agent_registry: Arc<crate::subagent::AgentRegistry>,
79    workspace: String,
80) {
81    register_task_with_mcp(registry, llm_client, agent_registry, workspace, None);
82}
83
84/// Register the task delegation tools with optional MCP manager.
85///
86/// When `mcp_manager` is provided, child subagent sessions will have access
87/// to all MCP tools from connected servers.
88pub fn register_task_with_mcp(
89    registry: &Arc<ToolRegistry>,
90    llm_client: Arc<dyn crate::llm::LlmClient>,
91    agent_registry: Arc<crate::subagent::AgentRegistry>,
92    workspace: String,
93    mcp_manager: Option<Arc<crate::mcp::manager::McpManager>>,
94) {
95    use crate::tools::task::{ParallelTaskTool, RunTeamTool, TaskExecutor, TaskTool};
96    let executor = Arc::new(match mcp_manager {
97        Some(mcp) => TaskExecutor::with_mcp(agent_registry, llm_client, workspace, mcp),
98        None => TaskExecutor::new(agent_registry, llm_client, workspace),
99    });
100    registry.register_builtin(Arc::new(TaskTool::new(Arc::clone(&executor))));
101    registry.register_builtin(Arc::new(ParallelTaskTool::new(Arc::clone(&executor))));
102    registry.register_builtin(Arc::new(RunTeamTool::new(executor)));
103}
104
105/// Register the Skill tool for skill-based tool access control.
106pub fn register_skill(
107    registry: &Arc<ToolRegistry>,
108    llm_client: Arc<dyn crate::llm::LlmClient>,
109    skill_registry: Arc<crate::skills::SkillRegistry>,
110    tool_executor: Arc<crate::tools::ToolExecutor>,
111    base_config: crate::agent::AgentConfig,
112) {
113    use crate::tools::skill::SkillTool;
114    registry.register_builtin(Arc::new(SkillTool::new(
115        skill_registry,
116        llm_client,
117        tool_executor,
118        base_config,
119    )));
120}