Skip to content

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

fix(toolpacks): scope direct-handoff closure to explicit pack owners

Steven Enamakel2365e8aecb90
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/awaiting_user_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/awaiting_user_tests.rs
index 294dc1f155..a7d47eacac 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/awaiting_user_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/awaiting_user_tests.rs
@@ -162,5 +162,9 @@ fn a_repaused_subagent_gets_the_same_injection_safe_envelope() {
env.contains("This resumes the existing child"),
"every pause envelope must resume the existing child (checkpointed={checkpointed}): {env}"
);
+ assert!(
+ env.contains("do not choose a new task_key"),
+ "every pause envelope must keep the original task key (checkpointed={checkpointed}): {env}"
+ );
}
}
diff --git a/crates/openhuman-core/src/agent/session_host/builder/builder_tests_tool_exposure_tests.rs b/crates/openhuman-core/src/agent/session_host/builder/builder_tests_tool_exposure_tests.rs
index de3d8adf23..c2cb49786a 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/builder_tests_tool_exposure_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/builder_tests_tool_exposure_tests.rs
@@ -229,43 +229,60 @@ fn named_belt_keeps_its_listed_members() {
fn orchestrator_reaches_the_replaced_specialists_tools_through_discovery() {
let tmp = tempfile::TempDir::new().unwrap();
let config = test_config(&tmp);
- let definition =
- crate::agent_registry::host_definition::AgentDefinitionRegistry::builtins_only()
- .get("orchestrator")
- .cloned()
- .expect("orchestrator built-in definition");
- let agent = crate::agent::OpenHumanSessionHost::from_config_with_definition(
- &crate::core::runtime::DispatchCtx::ambient(),
- &config,
- &definition,
+ let definitions = std::sync::Arc::new(
+ crate::agent_registry::host_definition::AgentDefinitionRegistry::builtins_only(),
+ );
+ let definition = definitions
+ .get("orchestrator")
+ .cloned()
+ .expect("orchestrator built-in definition");
+ let core = crate::core::runtime::CoreContext::for_test_with_config(
+ crate::core::runtime::DomainSet::full(),
+ config.clone(),
)
- .expect("orchestrator session build");
- let deferred = agent.deferred_tool_names;
- let visible = agent.visible_tool_names;
- let policy = agent.tool_policy_session;
- // Unconditionally registered members only: language commands run through shell and need
- // host Node runtime and the wallet family needs the `web3`
- // feature, so a test profile without them cannot see them either way.
- for tool in [
- "cron",
- "config_snapshot",
- "service_restart",
- "gitbooks_search",
- "edit",
- "curl",
- "read_diff",
- "run_linter",
- "run_tests",
- "mcp_registry_installed_list",
- ] {
- assert!(
- deferred.contains(tool),
- "`{tool}` must be deferred; got {deferred:?}"
- );
- assert!(!visible.contains(tool), "`{tool}` must stay off the wire");
- assert!(
- policy.is_allowed(tool),
- "`{tool}` must be callable once found"
- );
- }
+ .derive_with(
+ crate::core::runtime::ContextOverlay::new(
+ config.clone(),
+ crate::core::runtime::DomainSet::full(),
+ crate::tools::toolpacks::ToolGroups::packed(),
+ )
+ .definitions(definitions),
+ );
+
+ crate::core::runtime::CoreContext::sync_scope(core, || {
+ let agent = crate::agent::OpenHumanSessionHost::from_config_with_definition(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ &definition,
+ )
+ .expect("orchestrator session build");
+ let deferred = agent.deferred_tool_names;
+ let visible = agent.visible_tool_names;
+ let policy = agent.tool_policy_session;
+ // Unconditionally registered members only: language commands run through shell and need
+ // host Node runtime and the wallet family needs the `web3`
+ // feature, so a test profile without them cannot see them either way.
+ for tool in [
+ "cron",
+ "config_snapshot",
+ "service_restart",
+ "gitbooks_search",
+ "edit",
+ "curl",
+ "read_diff",
+ "run_linter",
+ "run_tests",
+ "mcp_registry_installed_list",
+ ] {
+ assert!(
+ deferred.contains(tool),
+ "`{tool}` must be deferred; got {deferred:?}"
+ );
+ assert!(!visible.contains(tool), "`{tool}` must stay off the wire");
+ assert!(
+ policy.is_allowed(tool),
+ "`{tool}` must be callable once found"
+ );
+ }
+ });
}
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_tool_policy_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_tool_policy_tests.rs
index 3d1937b695..2715f9ead4 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware_tool_policy_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_tool_policy_tests.rs
@@ -247,8 +247,9 @@ async fn a_use_skill_denial_names_a_delegate_this_session_can_call() {
"the denial itself must survive: {message}"
);
assert!(
- message.contains("Call `spawn_subagent` instead"),
- "the denial must name the callable owner hand-off: {message}"
+ message.contains("Call `spawn_subagent` to delegate")
+ && message.contains("owned by `workflow_builder`"),
+ "the denial must name the callable spawn tool and owning specialist: {message}"
);
}
@@ -405,7 +406,7 @@ async fn a_prompt_hidden_delegate_is_not_offered_as_a_direct_route() {
let pack = crate::tools::toolpacks::pack("workflows").expect("workflows pack");
let route = mw.route_for_pack(pack);
assert!(
- !route.contains("Call `spawn_subagent`"),
+ !route.contains("Call `spawn_subagent` to delegate"),
"a prompt-hidden delegate must not be advertised as a direct call: {route}"
);
assert!(
diff --git a/crates/openhuman-core/src/agent_registry/agents/orchestrator/prompt_tests_installed_skills_tests.rs b/crates/openhuman-core/src/agent_registry/agents/orchestrator/prompt_tests_installed_skills_tests.rs
index 87f3c7d4cc..6bee838715 100644
--- a/crates/openhuman-core/src/agent_registry/agents/orchestrator/prompt_tests_installed_skills_tests.rs
+++ b/crates/openhuman-core/src/agent_registry/agents/orchestrator/prompt_tests_installed_skills_tests.rs
@@ -89,7 +89,7 @@ fn render_installed_skills_empty_is_omitted() {
fn prompt_documents_the_single_always_async_spawn_contract() {
assert!(ARCHETYPE.contains("Calls are asynchronous; completed results arrive automatically."));
assert!(ARCHETYPE.contains("Reuse the same `task_key` to continue a worker"));
- assert!(ARCHETYPE.contains("including one paused for clarification"));
+ assert!(ARCHETYPE.contains("including a child paused for clarification"));
for retired in [
"blocking: true",
"continue_subagent",
diff --git a/crates/openhuman-core/src/tools/toolpacks/ops.rs b/crates/openhuman-core/src/tools/toolpacks/ops.rs
index 5b9231985a..6b0005b7dd 100644
--- a/crates/openhuman-core/src/tools/toolpacks/ops.rs
+++ b/crates/openhuman-core/src/tools/toolpacks/ops.rs
@@ -143,9 +143,11 @@ pub fn is_withheld_from(agent_id: &str, tool: &str) -> bool {
/// guessed at tool names, and never handed off. Closing the raw tools leaves the
/// hand-off as the route, and the pack listing then names it (`route_sentence`).
///
-/// Close tools owned by specialists that this agent can reach through its
+/// Close packs whose task family this agent can reach through its
/// `spawn_subagent` schema. The schema's agent-id enum is the same allowlist
-/// enforced during execution, so this keeps a single route to each capability.
+/// enforced during execution. The host's explicit closure-owner table is used
+/// instead of every `ToolPack::owners` entry because some agents own only
+/// auxiliary tools in a broader pack.
pub fn closed_by_direct_handoff(agent_id: &str, tools: &[&dyn Tool]) -> Vec<&'static str> {
let reachable_owners: HashSet<String> = tools
.iter()
@@ -170,9 +172,14 @@ pub fn closed_by_direct_handoff(agent_id: &str, tools: &[&dyn Tool]) -> Vec<&'st
.iter()
.filter(|pack| !pack.is_owner(agent_id))
.filter(|pack| {
- pack.owners
+ registry::DIRECT_HANDOFF_PACK_OWNERS
.iter()
- .any(|owner| reachable_owners.contains(*owner))
+ .find(|(pack_id, _)| *pack_id == pack.id)
+ .is_some_and(|(_, owners)| {
+ owners
+ .iter()
+ .any(|owner| reachable_owners.contains(*owner))
+ })
})
.flat_map(|pack| pack.tools.iter().copied())
.filter(|name| groups.mode_for_tool(name) == super::groups::GroupMode::Withheld)
diff --git a/crates/openhuman-core/src/tools/toolpacks/registry.rs b/crates/openhuman-core/src/tools/toolpacks/registry.rs
index d9ea667800..617787a6ef 100644
--- a/crates/openhuman-core/src/tools/toolpacks/registry.rs
+++ b/crates/openhuman-core/src/tools/toolpacks/registry.rs
@@ -359,6 +359,18 @@ pub const PACKS: &[ToolPack] = &[
},
];
+/// Pack families that a directly callable `spawn_subagent` owner replaces for
+/// this host. This is separate from `ToolPack::owners`: a pack may give an
+/// agent a few auxiliary tools without making that agent the route for the
+/// whole family (for example, media specialists own image helpers in the
+/// coding pack, but the Master Agent still owns ordinary coding work).
+pub const DIRECT_HANDOFF_PACK_OWNERS: &[(&str, &[&str])] = &[
+ ("workflows", &["workflow_builder", "flow_discovery"]),
+ ("skills", &["skill_setup"]),
+ ("documents", &["presentation_agent"]),
+ ("media", &["image_agent", "video_agent", "vision_agent"]),
+];
+
/// The lookup surface over [`PACKS`] handed to the generic `use_skill` tool
/// (`tinyagents_harness_tools::skills`). `NOT_FOUND_MARKER` is the host's status
/// vocabulary, so a "no such skill / tool" result classifies as `NotFound`.
diff --git a/crates/openhuman-core/src/tools/toolpacks/toolpacks_tests_scoping_and_visibility_tests.rs b/crates/openhuman-core/src/tools/toolpacks/toolpacks_tests_scoping_and_visibility_tests.rs
index d354d67f3e..afb15da413 100644
--- a/crates/openhuman-core/src/tools/toolpacks/toolpacks_tests_scoping_and_visibility_tests.rs
+++ b/crates/openhuman-core/src/tools/toolpacks/toolpacks_tests_scoping_and_visibility_tests.rs
@@ -334,11 +334,19 @@ fn spawn_tool_schema_closes_only_reachable_specialist_packs() {
let raw = registry_with_all(&[
"skill_registry_install",
"media_generate_image",
+ "propose_workflow",
+ "generate_presentation",
+ "edit",
"wallet_status",
]);
let spawn = crate::agent::orchestration::tools::SpawnSubagentTool::scoped(vec![
"skill_setup".to_string(),
"image_agent".to_string(),
+ "video_agent".to_string(),
+ "vision_agent".to_string(),
+ "workflow_builder".to_string(),
+ "flow_discovery".to_string(),
+ "presentation_agent".to_string(),
]);
let tools: Vec<&dyn tinytools::Tool> = raw
.iter()
@@ -346,8 +354,25 @@ fn spawn_tool_schema_closes_only_reachable_specialist_packs() {
.chain(std::iter::once(&spawn as &dyn tinytools::Tool))
.collect();
- let closed = closed_by_direct_handoff("orchestrator", &tools);
+ let core = crate::core::runtime::CoreContext::for_test(
+ crate::core::runtime::DomainSet::full(),
+ None,
+ )
+ .derive_with(crate::core::runtime::ContextOverlay::new(
+ crate::config::Config::default(),
+ crate::core::runtime::DomainSet::full(),
+ super::super::ToolGroups::packed(),
+ ));
+ let closed = crate::core::runtime::CoreContext::sync_scope(core, || {
+ closed_by_direct_handoff("orchestrator", &tools)
+ });
assert!(closed.contains(&"skill_registry_install"), "{closed:?}");
assert!(closed.contains(&"media_generate_image"), "{closed:?}");
+ assert!(closed.contains(&"propose_workflow"), "{closed:?}");
+ assert!(closed.contains(&"generate_presentation"), "{closed:?}");
+ assert!(
+ !closed.contains(&"edit"),
+ "auxiliary coding-pack owners must not close the Master Agent's coding family: {closed:?}"
+ );
assert!(!closed.contains(&"wallet_status"), "{closed:?}");
}