From 8aa66ec943ee57c4252019ac640219ec78c2aaf7 Mon Sep 17 00:00:00 2001 From: Amit Singh Date: Wed, 22 Apr 2026 00:22:09 +0530 Subject: [PATCH] fix(agent): move research subagent filtering to tool registry --- crates/forge_app/src/tool_registry.rs | 11 ++++++++++- crates/forge_repo/src/agent.rs | 12 ------------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/crates/forge_app/src/tool_registry.rs b/crates/forge_app/src/tool_registry.rs index b923528059..dbfff3da06 100644 --- a/crates/forge_app/src/tool_registry.rs +++ b/crates/forge_app/src/tool_registry.rs @@ -245,7 +245,7 @@ impl> ToolReg let agent_tools = self.agent_executor.agent_definitions().await?; // Get agents for template rendering in Task tool description - let agents = self.services.get_agents().await?; + let mut agents = self.services.get_agents().await?; // Check if current working directory is indexed let environment = self.services.get_environment(); @@ -258,6 +258,15 @@ impl> ToolReg // Build TemplateConfig from ForgeConfig for tool description templates let config = self.services.get_config()?; + + // Filter out research subagents from task tool description when disabled + if !config.research_subagent { + agents.retain(|agent| { + let id = agent.id.as_str(); + id != "sage" && id != "agent" + }); + } + let template_config = TemplateConfig { max_read_size: config.max_read_lines as usize, max_line_length: config.max_line_chars, diff --git a/crates/forge_repo/src/agent.rs b/crates/forge_repo/src/agent.rs index 5e3dd3bd0e..313d759a85 100644 --- a/crates/forge_repo/src/agent.rs +++ b/crates/forge_repo/src/agent.rs @@ -203,7 +203,6 @@ impl + DirectoryReader Ok(agent_defs .into_iter() - .filter(|def| filter_agent(def, &config)) .map(|def| { def.into_agent( ProviderId::from(session.provider_id.clone()), @@ -214,11 +213,9 @@ impl + DirectoryReader } async fn get_agent_infos(&self) -> anyhow::Result> { - let config = self.infra.get_config()?; let agent_defs = self.load_agents().await?; Ok(agent_defs .into_iter() - .filter(|def| filter_agent(def, &config)) .map(|def| forge_domain::AgentInfo { id: def.id, title: def.title, @@ -228,15 +225,6 @@ impl + DirectoryReader } } -/// Returns `false` for agents that are disabled by a feature flag in the -/// configuration, `true` for all others. -fn filter_agent(def: &AgentDefinition, config: &ForgeConfig) -> bool { - if def.id.as_str() == forge_domain::AgentId::SAGE.as_str() && !config.research_subagent { - return false; - } - true -} - #[cfg(test)] mod tests { use forge_domain::AgentId;