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(agent): update subagent documentation and tests
Steven Enamakel99c1a2348160
diff --git a/crates/openhuman-embed/src/agent/spec.rs b/crates/openhuman-embed/src/agent/spec.rsindex 75baa21c4a..a1bcf07434 100644--- a/crates/openhuman-embed/src/agent/spec.rs+++ b/crates/openhuman-embed/src/agent/spec.rs@@ -317,11 +317,12 @@ impl AgentSpec {self}- /// Sub-agents only this agent can delegate to, each under its own id.+ /// Sub-agents only this agent can ask to work, each under its own id.///- /// Each becomes a `delegate_<id>` tool on this agent and a worker in this- /// agent's own catalogue; other agents on the runtime never see it. Ids- /// follow the agent-id rules and must not name a built-in definition.+ /// 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.pub fn subagents<I, S>(mut self, subagents: I) -> SelfwhereI: IntoIterator<Item = (S, AgentDefinitionSpec)>,diff --git a/crates/openhuman-embed/tests/isolation_subagents.rs b/crates/openhuman-embed/tests/isolation_subagents.rsindex b1c1456fa1..6e5829f730 100644--- a/crates/openhuman-embed/tests/isolation_subagents.rs+++ b/crates/openhuman-embed/tests/isolation_subagents.rs@@ -99,6 +99,19 @@ fn sub_agents_stay_with_the_agent_that_declared_them() {"a is offered its own helper: {:?}",tool_names(&a_requests[0]));+ let a_body: serde_json::Value =+ serde_json::from_slice(&a_requests[0].body).expect("A's provider request JSON");+ let spawn_spec = a_body["tools"]+ .as_array()+ .expect("provider request tools")+ .iter()+ .find(|tool| tool.pointer("/function/name").and_then(|v| v.as_str()) == Some("spawn_subagent"))+ .expect("canonical spawn tool schema");+ assert_eq!(+ spawn_spec.pointer("/function/parameters/properties/agent_id/enum"),+ Some(&serde_json::json!(["a_helper"])),+ "A's spawn schema lists only its declared helper"+ );assert!(!tool_names(&a_requests[0]).iter()@@ -130,6 +143,12 @@ fn sub_agents_stay_with_the_agent_that_declared_them() {let b_requests = chat_requests(&b_provider).await;assert!(!b_requests.is_empty());+ assert!(+ !tool_names(&b_requests[0])+ .iter()+ .any(|tool| tool == "spawn_subagent"),+ "an agent with no declared helpers does not receive the spawn tool"+ );for request in &b_requests {assert!(!tool_names(request).iter().any(|t| t == "delegate_a_helper"),@@ -147,3 +166,120 @@ fn sub_agents_stay_with_the_agent_that_declared_them() {.expect("test task");});}++#[test]+fn host_only_and_disallowed_scopes_do_not_opt_into_declared_helpers() {+ runtime().block_on(async {+ tokio::spawn(async move {+ let backend = stub_backend().await;+ let runtime_provider = scripted_provider(Vec::new(), "runtime-provider").await;+ let runtime = Runtime::builder()+ .config(offline_config())+ .workspace(Workspace::Ephemeral)+ .backend_url(backend.uri())+ .provider(route(&runtime_provider, "runtime-model"))+ .access(Access::full())+ .build()+ .await+ .expect("runtime builds");++ let host_only_provider = scripted_provider(+ vec![+ tool_call_completion(+ "spawn_subagent",+ &serde_json::json!({+ "agent_id": "host_helper",+ "prompt": "do host-only work",+ "task_key": "host-helper-task"+ })+ .to_string(),+ ),+ common::chat_completion("host-only done"),+ ],+ "host-only done",+ )+ .await;+ let host_only = runtime+ .agent(+ AgentSpec::new("host-only-lead")+ .provider(route(&host_only_provider, "host-only-model"))+ .definition(+ AgentDefinitionSpec::new().tools(ToolScopeSpec::HostOnly),+ )+ .subagents([(+ "host_helper",+ AgentDefinitionSpec::new()+ .system_prompt("HOST-ONLY-HELPER-MARK")+ .when_to_use("host-only helper"),+ )]),+ )+ .expect("host-only agent with declared helper builds");+ host_only+ .run("try the helper")+ .await+ .expect("host-only turn returns");+ let host_requests = chat_requests(&host_only_provider).await;+ assert!(!host_requests.is_empty());+ assert!(!tool_names(&host_requests[0]).iter().any(|name| name == "spawn_subagent"));+ assert!(host_requests+ .iter()+ .all(|request| !String::from_utf8_lossy(&request.body)+ .contains("HOST-ONLY-HELPER-MARK")));++ let denied_provider = scripted_provider(+ vec![+ tool_call_completion(+ "spawn_subagent",+ &serde_json::json!({+ "agent_id": "denied_helper",+ "prompt": "do denied work",+ "task_key": "denied-helper-task"+ })+ .to_string(),+ ),+ common::chat_completion("denied turn done"),+ ],+ "denied turn done",+ )+ .await;+ let denied = runtime+ .agent(+ AgentSpec::new("denied-lead")+ .provider(route(&denied_provider, "denied-model"))+ .definition(+ AgentDefinitionSpec::new()+ .tools(ToolScopeSpec::Named(Vec::new()))+ .disallow_tools(["spawn_subagent"]),+ )+ .subagents([(+ "denied_helper",+ AgentDefinitionSpec::new()+ .system_prompt("DISALLOWED-HELPER-MARK")+ .when_to_use("disallowed helper"),+ )]),+ )+ .expect("agent with explicit spawn denial builds");+ denied+ .run("try the helper")+ .await+ .expect("disallowed turn returns");+ let denied_requests = chat_requests(&denied_provider).await;+ assert!(!denied_requests.is_empty());+ assert!(!tool_names(&denied_requests[0])+ .iter()+ .any(|name| name == "spawn_subagent"));+ assert!(denied_requests+ .iter()+ .all(|request| !String::from_utf8_lossy(&request.body)+ .contains("DISALLOWED-HELPER-MARK")));++ assert_eq!(+ chat_requests(&runtime_provider).await.len(),+ 0,+ "no helper work falls back to the runtime provider"+ );+ })+ .await+ .expect("test task");+ });+}