The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(subagent_host): extract definition tool filtering into tool_prep
Steven Enamakelcdae7027124a
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rsindex 383ea4c881..c9143d7283 100644--- a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs+++ b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs@@ -15,7 +15,7 @@ use crate::agent::prompts::{PromptContext, SubagentRenderOptions};use crate::agent::session_host::dedup_visible_tool_specs;use crate::agent::subagent_host::definition_iter_cap;use crate::agent::subagent_host::tool_prep::{- filter_tool_indices_with_nested_spawn, is_subagent_spawn_tool, subagent_prompt_protocol,+ filter_definition_tool_indices, is_subagent_spawn_tool, subagent_prompt_protocol,};use crate::agent::subagent_host::types::{SubagentMode, SubagentRunError, SubagentRunOptions, SubagentRunOutcome,@@ -476,68 +476,16 @@ async fn run_typed_mode(};// ── Filter tools per definition + per-spawn override ───────────────- let nested_spawn_ids = definition.allowed_subagent_ids();- let explicitly_declares_nested_spawn = |name: &str| {- is_subagent_spawn_tool(name)- && (definition.extra_tools.iter().any(|tool| tool == name)- || matches!(- &definition.tools,- tinyagents_definition::ToolScope::Named(names)- if names.iter().any(|tool| tool == name)- ))- };- let nested_spawn_allowed = |name: &str| {- nested_spawn_depth_available- && !nested_spawn_ids.is_empty()- && explicitly_declares_nested_spawn(name)- };- let nested_spawn_granted = parent- .all_tools- .iter()- .any(|tool| nested_spawn_allowed(tool.name()));- let mut allowed_indices = filter_tool_indices_with_nested_spawn(+ let (mut allowed_indices, nested_spawn_granted) = filter_definition_tool_indices(&parent.all_tools,- &definition.tools,- &definition.disallowed_tools,+ definition,options.skill_filter_override.as_deref().or(definition.skill_filter.as_deref()),- nested_spawn_granted,+ nested_spawn_depth_available,);- // Sub-agents are leaves unless their own definition explicitly declares a- // spawn tool, and the host's checked depth budget admits another child.- // Keep the normal definition scope, denylist, and inherited ceiling as- // independent constraints on that opt-in.- let before = allowed_indices.len();- allowed_indices.retain(|&i| {- let name = parent.all_tools[i].name();- !is_subagent_spawn_tool(name) || nested_spawn_allowed(name)- });- let stripped = before - allowed_indices.len();- if stripped > 0 {- tracing::debug!(- agent_id = %definition.id,- stripped,- "[subagent_host] removed sub-agent spawn tools from sub-agent's tool surface"- );- }-- // ── Force-include extra_tools ──────────────────────────────────────- if !definition.extra_tools.is_empty() {- for (i, tool) in parent.all_tools.iter().enumerate() {- let name = tool.name();- if definition.extra_tools.iter().any(|n| n == name)- && !allowed_indices.contains(&i)- && !crate::tools::rules::glob_list_matches(&definition.disallowed_tools, name)- && (!is_subagent_spawn_tool(name) || nested_spawn_allowed(name))- {- allowed_indices.push(i);- }- }- }-// A child may only narrow an explicit profile/channel ceiling, never widen// it back to `all_tools`. The parent's own role-specific prompt surface is// intentionally not a ceiling: coordinators delegate effectful work todiff --git a/crates/openhuman-core/src/agent/subagent_host/tool_prep.rs b/crates/openhuman-core/src/agent/subagent_host/tool_prep.rsindex efb0696a8c..30dd6ee690 100644--- a/crates/openhuman-core/src/agent/subagent_host/tool_prep.rs+++ b/crates/openhuman-core/src/agent/subagent_host/tool_prep.rs@@ -127,6 +127,67 @@ pub(super) fn filter_tool_indices_with_nested_spawn(.collect()}+/// Applies a child's definition scope, denylist, and checked host grant to+/// the parent's registered tools before the inherited visibility ceiling.+pub(super) fn filter_definition_tool_indices(+ parent_tools: &[Box<dyn Tool>],+ definition: &AgentDefinition,+ skill_filter: Option<&str>,+ nested_spawn_depth_available: bool,+) -> (Vec<usize>, bool) {+ let nested_spawn_ids = definition.allowed_subagent_ids();+ let explicitly_declares_nested_spawn = |name: &str| {+ is_subagent_spawn_tool(name)+ && (definition.extra_tools.iter().any(|tool| tool == name)+ || matches!(+ &definition.tools,+ ToolScope::Named(names) if names.iter().any(|tool| tool == name)+ ))+ };+ let nested_spawn_allowed = |name: &str| {+ nested_spawn_depth_available+ && !nested_spawn_ids.is_empty()+ && explicitly_declares_nested_spawn(name)+ };+ let nested_spawn_granted = parent_tools+ .iter()+ .any(|tool| nested_spawn_allowed(tool.name()));+ let mut allowed = filter_tool_indices_with_nested_spawn(+ parent_tools,+ &definition.tools,+ &definition.disallowed_tools,+ skill_filter,+ nested_spawn_granted,+ );++ let before = allowed.len();+ allowed.retain(|&index| {+ let name = parent_tools[index].name();+ !is_subagent_spawn_tool(name) || nested_spawn_allowed(name)+ });+ let stripped = before - allowed.len();+ if stripped > 0 {+ tracing::debug!(+ agent_id = %definition.id,+ stripped,+ "[subagent_host] removed sub-agent spawn tools from sub-agent's tool surface"+ );+ }++ for (index, tool) in parent_tools.iter().enumerate() {+ let name = tool.name();+ if definition.extra_tools.iter().any(|extra| extra == name)+ && !allowed.contains(&index)+ && !crate::tools::rules::glob_list_matches(&definition.disallowed_tools, name)+ && (!is_subagent_spawn_tool(name) || nested_spawn_allowed(name))+ {+ allowed.push(index);+ }+ }++ (allowed, nested_spawn_granted)+}+/// Intersect a child definition's tool indices with the tools the parent turn/// actually exposes. An empty parent set is the legacy "unknown/unrestricted"/// sentinel used by internal callers and older tests.