Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions core/src/agent_api/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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<PathBuf> {
let mut dirs = Vec::new();
if let Some(home) = std::env::var_os("HOME").or_else(|| std::env::var_os("USERPROFILE")) {
Expand Down Expand Up @@ -265,6 +285,26 @@ fn group_mcp_tools_by_server(all_tools: Vec<(String, McpTool)>) -> HashMap<Strin
by_server
}

#[cfg(test)]
mod tests {
use super::disable_delegation_tools_from_env;

#[test]
fn disable_delegation_tools_accepts_common_truthy_values() {
for value in ["1", "true", "TRUE", " yes ", "on", "On"] {
assert!(disable_delegation_tools_from_env(Some(value)));
}
}

#[test]
fn disable_delegation_tools_rejects_empty_missing_and_falsey_values() {
for value in ["", "0", "false", "no", "off", "enabled"] {
assert!(!disable_delegation_tools_from_env(Some(value)));
}
assert!(!disable_delegation_tools_from_env(None));
}
}

fn build_context_providers(
opts: &SessionOptions,
workspace: &Path,
Expand Down
Loading