From 63438b64a9731b7adfd99a5e84f4c988bf33eca8 Mon Sep 17 00:00:00 2001 From: Li Xiangtian <1193027052@qq.com> Date: Fri, 5 Jun 2026 19:46:11 +0800 Subject: [PATCH] feat: allow disabling delegation tools --- core/src/agent_api/capabilities.rs | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/core/src/agent_api/capabilities.rs b/core/src/agent_api/capabilities.rs index d7004ee..46287fc 100644 --- a/core/src/agent_api/capabilities.rs +++ b/core/src/agent_api/capabilities.rs @@ -18,6 +18,8 @@ use std::collections::HashMap; use std::path::{Path, PathBuf}; use std::sync::Arc; +const DISABLE_DELEGATION_TOOLS_ENV: &str = "A3S_CODE_DISABLE_DELEGATION_TOOLS"; + pub(super) struct SessionCapabilityInput<'a> { pub(super) code_config: &'a CodeConfig, pub(super) base_config: &'a AgentConfig, @@ -163,6 +165,9 @@ fn register_task_capability( use crate::tools::register_task_with_mcp; let registry = AgentRegistry::new(); + let disable_delegation_tools = disable_delegation_tools_from_env( + std::env::var(DISABLE_DELEGATION_TOOLS_ENV).ok().as_deref(), + ); let built_in_agent_dirs = built_in_agent_dirs(workspace); for dir in code_config .agent_dirs @@ -178,6 +183,10 @@ fn register_task_capability( registry.register_worker(worker.clone()); } + if disable_delegation_tools { + return Arc::new(registry); + } + let parent_context = ChildRunContext { security_provider: opts.security_provider.clone(), hook_engine: None, @@ -203,6 +212,17 @@ fn register_task_capability( registry } +fn disable_delegation_tools_from_env(value: Option<&str>) -> bool { + value + .map(|value| { + matches!( + value.trim().to_ascii_lowercase().as_str(), + "1" | "true" | "yes" | "on" + ) + }) + .unwrap_or(false) +} + fn built_in_agent_dirs(workspace: &Path) -> Vec { let mut dirs = Vec::new(); if let Some(home) = std::env::var_os("HOME").or_else(|| std::env::var_os("USERPROFILE")) { @@ -265,6 +285,26 @@ fn group_mcp_tools_by_server(all_tools: Vec<(String, McpTool)>) -> HashMap