Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(subagent): hide rule-withheld tools from child prompt

Steven Enamakel6274feb235f0
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
index 9cd9f9da4f..16448c95dd 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
@@ -26,7 +26,7 @@ use crate::agent::harness::{
MAX_SPAWN_DEPTH,
};
use crate::agent::prompts::{
- render_subagent_system_prompt_with_format, PromptContext, PromptTool, SubagentRenderOptions,
+ render_subagent_system_prompt_with_format, PromptContext, SubagentRenderOptions,
};
use crate::agent::subagent_host::subagent_iter_cap_with_autonomous_lift;
use crate::agent::subagent_host::tool_prep::{
@@ -728,7 +728,18 @@ async fn run_typed_mode(
&parent.subagent_tool_ceiling_names,
);
- let filtered_specs: Vec<ToolSpec> = allowed_indices
+ // The rules the child runs under: a tool they withhold stays callable
+ // (`allowed_names`) but off the specs and prompt this host renders.
+ let child_rules = options
+ .run_context
+ .for_subagent(definition, config.as_ref().ok().map(AsRef::as_ref))
+ .tool_rules;
+ let listed = super::super::tool_prep::rule_listed_indices(
+ &allowed_indices,
+ &parent.all_tools,
+ child_rules.as_deref(),
+ );
+ let filtered_specs: Vec<ToolSpec> = listed
.iter()
.map(|&i| parent.all_tool_specs[i].as_ref().clone())
.collect();
@@ -761,17 +772,7 @@ async fn run_typed_mode(
.cloned()
.collect();
- let prompt_tools: Vec<PromptTool<'_>> = allowed_indices
- .iter()
- .map(|&i| {
- let t = parent.all_tools[i].as_ref();
- PromptTool {
- name: std::borrow::Cow::Borrowed(t.name()),
- description: std::borrow::Cow::Borrowed(t.description()),
- parameters_schema: Some(t.parameters_schema().to_string()),
- }
- })
- .collect();
+ let prompt_tools = super::super::tool_prep::prompt_tools_for(&listed, &parent.all_tools);
let visible_tool_names: std::collections::HashSet<String> =
prompt_tools.iter().map(|t| t.name.to_string()).collect();
let (prompt_tool_call_format, dispatcher_instructions) =
diff --git a/crates/openhuman-core/src/agent/subagent_host/tool_prep.rs b/crates/openhuman-core/src/agent/subagent_host/tool_prep.rs
index 046ada3615..fb1c144b19 100644
--- a/crates/openhuman-core/src/agent/subagent_host/tool_prep.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/tool_prep.rs
@@ -161,6 +161,52 @@ mod recovery_visibility_tests;
/// [`PromptContext`], `File` sources are read from disk relative to the
/// workspace `prompts/` directory or the agent crate's bundled prompts.
///
+/// The allowed indices whose tools the sub-agent's rules let it list. A
+/// withheld tool stays allowed — the harness gate decides calls — but is kept
+/// off the specs and catalogue the host renders into the child's prompt.
+pub(super) fn rule_listed_indices(
+ allowed: &[usize],
+ tools: &[Box<dyn Tool>],
+ rules: Option<&tinyagents_harness::tool::ToolRulePolicy>,
+) -> Vec<usize> {
+ let Some(rules) = rules else {
+ return allowed.to_vec();
+ };
+ allowed
+ .iter()
+ .copied()
+ .filter(|&i| {
+ let tool = tools[i].as_ref();
+ let surface = if tool.exposure() == tinytools::ToolExposure::Deferred {
+ tinytools::Surface::Search
+ } else {
+ tinytools::Surface::Catalog
+ };
+ rules
+ .rules
+ .visible(&tinytools::ToolSubject::of(tool), &rules.context, surface)
+ })
+ .collect()
+}
+
+/// The prompt catalogue entries for `indices`.
+pub(super) fn prompt_tools_for<'a>(
+ indices: &[usize],
+ tools: &'a [Box<dyn Tool>],
+) -> Vec<crate::agent::prompts::PromptTool<'a>> {
+ indices
+ .iter()
+ .map(|&i| {
+ let tool = tools[i].as_ref();
+ crate::agent::prompts::PromptTool {
+ name: std::borrow::Cow::Borrowed(tool.name()),
+ description: std::borrow::Cow::Borrowed(tool.description()),
+ parameters_schema: Some(tool.parameters_schema().to_string()),
+ }
+ })
+ .collect()
+}
+
pub(super) fn load_prompt_source(
source: &PromptSource,
ctx: &PromptContext<'_>,