Skip to content

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

refactor(agent): update subagent scope documentation and logic

Steven Enamakel31b22ecc6afe
diff --git a/crates/openhuman-embed/src/agent/build.rs b/crates/openhuman-embed/src/agent/build.rs
index 8ae0412375..41b2f87799 100644
--- a/crates/openhuman-embed/src/agent/build.rs
+++ b/crates/openhuman-embed/src/agent/build.rs
@@ -433,9 +433,9 @@ fn opt_named_belt_into_discovery(scope: &mut tinyagents_definition::ToolScope) {
}
}
-/// Lets a named-scope agent reach only the child agents it explicitly owns.
-/// The caller must clear inherited roster entries first and exclude HostOnly
-/// agents, whose named empty belt is a hard prohibition on acting tools.
+ /// Lets a named-scope agent reach only the child agents it explicitly owns.
+ /// Apply the existing inherited-roster policy first and exclude HostOnly
+ /// agents, whose named empty belt is a hard prohibition on acting tools.
fn opt_named_belt_into_spawn(scope: &mut tinyagents_definition::ToolScope) {
use tinyagents_definition::ToolScope;
const SPAWN_SUBAGENT: &str = "spawn_subagent";
diff --git a/crates/openhuman-embed/src/agent/spec.rs b/crates/openhuman-embed/src/agent/spec.rs
index a1bcf07434..dafd1cf72c 100644
--- a/crates/openhuman-embed/src/agent/spec.rs
+++ b/crates/openhuman-embed/src/agent/spec.rs
@@ -320,9 +320,11 @@ impl AgentSpec {
/// Sub-agents only this agent can ask to work, each under its own id.
///
/// They become workers in this agent's own catalogue and are reachable
- /// through the asynchronous `spawn_subagent` tool's `agent_id` selection.
- /// Other agents on the runtime never see them. Ids follow the agent-id
- /// rules and must not name a built-in definition.
+ /// through the asynchronous `spawn_subagent` tool's `agent_id` selection
+ /// when its scope permits that tool. HostOnly scopes exclude it, and an
+ /// explicit `disallow_tools` rule can still deny it. Other agents on the
+ /// runtime never see these workers. Ids follow the agent-id rules and must
+ /// not name a built-in definition.
pub fn subagents<I, S>(mut self, subagents: I) -> Self
where
I: IntoIterator<Item = (S, AgentDefinitionSpec)>,
diff --git a/crates/openhuman-embed/tests/isolation_subagents.rs b/crates/openhuman-embed/tests/isolation_subagents.rs
index 0ea8978f4c..18d7511292 100644
--- a/crates/openhuman-embed/tests/isolation_subagents.rs
+++ b/crates/openhuman-embed/tests/isolation_subagents.rs
@@ -110,6 +110,19 @@ fn sub_agents_stay_with_the_agent_that_declared_them() {
== Some("spawn_subagent")
})
.expect("canonical spawn tool schema");
+ assert_eq!(
+ a_body["tools"]
+ .as_array()
+ .expect("provider request tools")
+ .iter()
+ .filter(|tool| {
+ tool.pointer("/function/name").and_then(|v| v.as_str())
+ == Some("spawn_subagent")
+ })
+ .count(),
+ 1,
+ "A receives one canonical spawn tool"
+ );
assert_eq!(
spawn_spec.pointer("/function/parameters/properties/agent_id/enum"),
Some(&serde_json::json!(["a_helper"])),
@@ -206,6 +219,7 @@ fn host_only_and_disallowed_scopes_do_not_opt_into_declared_helpers() {
.agent(
AgentSpec::new("host-only-lead")
.provider(route(&host_only_provider, "host-only-model"))
+ .bare_prompt("You are a host-managed agent.")
.definition(AgentDefinitionSpec::new().tools(ToolScopeSpec::HostOnly))
.subagents([(
"host_helper",
@@ -228,6 +242,12 @@ fn host_only_and_disallowed_scopes_do_not_opt_into_declared_helpers() {
.iter()
.all(|request| !String::from_utf8_lossy(&request.body)
.contains("HOST-ONLY-HELPER-MARK")));
+ let host_tool_results = host_requests
+ .iter()
+ .map(common::tool_results)
+ .collect::<Vec<_>>()
+ .join("\n");
+ assert_refused_without_async_reference(&host_tool_results);
let denied_provider = scripted_provider(
vec![
@@ -252,7 +272,7 @@ fn host_only_and_disallowed_scopes_do_not_opt_into_declared_helpers() {
.definition(
AgentDefinitionSpec::new()
.tools(ToolScopeSpec::Named(Vec::new()))
- .disallow_tools(["spawn_subagent"]),
+ .disallow_tools(["spawn_*"]),
)
.subagents([(
"denied_helper",
@@ -275,6 +295,12 @@ fn host_only_and_disallowed_scopes_do_not_opt_into_declared_helpers() {
.iter()
.all(|request| !String::from_utf8_lossy(&request.body)
.contains("DISALLOWED-HELPER-MARK")));
+ let denied_tool_results = denied_requests
+ .iter()
+ .map(common::tool_results)
+ .collect::<Vec<_>>()
+ .join("\n");
+ assert_refused_without_async_reference(&denied_tool_results);
assert_eq!(
chat_requests(&runtime_provider).await.len(),
@@ -286,3 +312,19 @@ fn host_only_and_disallowed_scopes_do_not_opt_into_declared_helpers() {
.expect("test task");
});
}
+
+fn assert_refused_without_async_reference(result: &str) {
+ let lowercase = result.to_ascii_lowercase();
+ assert!(
+ lowercase.contains("not available")
+ || lowercase.contains("not allowed")
+ || lowercase.contains("not in the current session"),
+ "the attempted spawn must return an explicit refusal: {result}"
+ );
+ for reference_field in ["task_id", "subagent_session_id", "status"] {
+ assert!(
+ !result.contains(reference_field),
+ "a refused spawn must not return an asynchronous task reference: {result}"
+ );
+ }
+}