Skip to content

Commit 63438b6

Browse files
committed
feat: allow disabling delegation tools
1 parent bc14c31 commit 63438b6

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

core/src/agent_api/capabilities.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ use std::collections::HashMap;
1818
use std::path::{Path, PathBuf};
1919
use std::sync::Arc;
2020

21+
const DISABLE_DELEGATION_TOOLS_ENV: &str = "A3S_CODE_DISABLE_DELEGATION_TOOLS";
22+
2123
pub(super) struct SessionCapabilityInput<'a> {
2224
pub(super) code_config: &'a CodeConfig,
2325
pub(super) base_config: &'a AgentConfig,
@@ -163,6 +165,9 @@ fn register_task_capability(
163165
use crate::tools::register_task_with_mcp;
164166

165167
let registry = AgentRegistry::new();
168+
let disable_delegation_tools = disable_delegation_tools_from_env(
169+
std::env::var(DISABLE_DELEGATION_TOOLS_ENV).ok().as_deref(),
170+
);
166171
let built_in_agent_dirs = built_in_agent_dirs(workspace);
167172
for dir in code_config
168173
.agent_dirs
@@ -178,6 +183,10 @@ fn register_task_capability(
178183
registry.register_worker(worker.clone());
179184
}
180185

186+
if disable_delegation_tools {
187+
return Arc::new(registry);
188+
}
189+
181190
let parent_context = ChildRunContext {
182191
security_provider: opts.security_provider.clone(),
183192
hook_engine: None,
@@ -203,6 +212,17 @@ fn register_task_capability(
203212
registry
204213
}
205214

215+
fn disable_delegation_tools_from_env(value: Option<&str>) -> bool {
216+
value
217+
.map(|value| {
218+
matches!(
219+
value.trim().to_ascii_lowercase().as_str(),
220+
"1" | "true" | "yes" | "on"
221+
)
222+
})
223+
.unwrap_or(false)
224+
}
225+
206226
fn built_in_agent_dirs(workspace: &Path) -> Vec<PathBuf> {
207227
let mut dirs = Vec::new();
208228
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<Strin
265285
by_server
266286
}
267287

288+
#[cfg(test)]
289+
mod tests {
290+
use super::disable_delegation_tools_from_env;
291+
292+
#[test]
293+
fn disable_delegation_tools_accepts_common_truthy_values() {
294+
for value in ["1", "true", "TRUE", " yes ", "on", "On"] {
295+
assert!(disable_delegation_tools_from_env(Some(value)));
296+
}
297+
}
298+
299+
#[test]
300+
fn disable_delegation_tools_rejects_empty_missing_and_falsey_values() {
301+
for value in ["", "0", "false", "no", "off", "enabled"] {
302+
assert!(!disable_delegation_tools_from_env(Some(value)));
303+
}
304+
assert!(!disable_delegation_tools_from_env(None));
305+
}
306+
}
307+
268308
fn build_context_providers(
269309
opts: &SessionOptions,
270310
workspace: &Path,

0 commit comments

Comments
 (0)