Skip to content

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

feat(agent): add parallel subagent spawn policy

Steven Enamakeldc94c5a78371
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent.rs
index 2d58fb55c3..2d187efc58 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent.rs
@@ -251,6 +251,37 @@ self.execute_with_context_inner(
}
impl SpawnAsyncSubagentTool {
+ /// Drive the tool the way a live parent turn does, over an explicit
+ /// `parent` execution context. Tests only: production turns reach the tool
+ /// through [`SpawnAsyncSubagentDispatch`] with their own carrier.
+ #[cfg(test)]
+ pub(crate) async fn execute_under_parent(
+ &self,
+ args: serde_json::Value,
+ options: ToolCallOptions,
+ tool_context: Option<&dyn ToolRunContext>,
+ parent: crate::agent::harness::ParentExecutionContext,
+ ) -> anyhow::Result<ToolResult> {
+ let live_parent = super::live_parent_run_context("direct-async-subagent", parent);
+ let detached_data = live_parent.data.detached_child();
+ let detached_cancellation = detached_data.cancellation.clone();
+ let detached_parent = live_parent
+ .child(
+ RunConfig::new(format!("async-subagent-{}", uuid::Uuid::new_v4())),
+ detached_data,
+ )
+ .map_err(|error| anyhow::anyhow!(error.to_string()))?
+ .with_cancellation(detached_cancellation);
+ self.execute_with_context_inner(
+ args,
+ options,
+ tool_context,
+ live_parent.data.child(),
+ Some(detached_parent),
+ )
+ .await
+ }
+
pub(crate) async fn execute_with_live_parent_context(
&self,
args: serde_json::Value,
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents.rs
index 7473f8b902..9103983472 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents.rs
@@ -252,6 +252,29 @@ let workspace_descriptor = tool_context.and_then(|ctx| ctx.workspace().cloned())
}
}
+#[cfg(test)]
+impl SpawnParallelAgentsTool {
+ /// Drive the tool the way a live parent turn does, over an explicit
+ /// `parent` execution context. Tests only: production turns reach the tool
+ /// through [`SpawnParallelAgentsDispatch`] with their own carrier.
+ pub(crate) async fn execute_under_parent(
+ &self,
+ args: serde_json::Value,
+ parent: crate::agent::harness::ParentExecutionContext,
+ ) -> anyhow::Result<ToolResult> {
+ let live_parent = super::live_parent_run_context("direct-spawn-parallel", parent);
+ execute_spawn_parallel_agents(
+ args,
+ live_parent.cancellation.clone(),
+ live_parent.workspace.clone(),
+ live_parent.data.child(),
+ Some(&live_parent),
+ None,
+ )
+ .await
+ }
+}
+
#[cfg(test)]
#[path = "spawn_parallel_agents_tests.rs"]
mod tests;
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents_policy_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents_policy_tests.rs
index 401524fa89..6f337c8142 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents_policy_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents_policy_tests.rs
@@ -156,14 +156,14 @@ async fn rejects_more_tasks_than_parent_parallel_limit() {
let _ = AgentDefinitionRegistry::init_global_builtins();
let tool = SpawnParallelAgentsTool::new();
let parent = parent_context(2);
- let result = with_parent_context(parent, async {
- tool.execute(json!({
+ let result = (async {
+ tool.execute_under_parent(json!({
"tasks": [
{ "agent_id": "researcher", "prompt": "one" },
{ "agent_id": "planner", "prompt": "two" },
{ "agent_id": "critic", "prompt": "three" }
]
- }))
+ }), parent.clone())
.await
})
.await
@@ -182,13 +182,13 @@ async fn collects_immediate_task_validation_failures() {
let tool = SpawnParallelAgentsTool::new();
let parent = parent_context(4);
- let result = with_parent_context(parent, async {
- tool.execute(json!({
+ let result = (async {
+ tool.execute_under_parent(json!({
"tasks": [
{ "agent_id": " ", "prompt": "missing agent", "ownership": "files: none" },
{ "agent_id": "__missing_agent__", "prompt": "unknown agent" }
]
- }))
+ }), parent.clone())
.await
})
.await
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents_tests.rs
index aee5926bbe..1cd1d6c488 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents_tests.rs
@@ -1,5 +1,5 @@
use super::*;
-use crate::agent::harness::fork_context::{with_parent_context, ParentExecutionContext};
+use crate::agent::harness::fork_context::ParentExecutionContext;
use crate::agent::harness::host_definition::AgentDefinition;
use crate::agent::harness::host_definition::AgentDefinitionRegistry;
use crate::agent::orchestration::spawn_parallel::{
@@ -112,7 +112,7 @@ async fn typed_dispatch_uses_the_parent_token_for_fanout_cancellation() {
.into_tinyagents(tinyagents_harness::context::RunConfig::new("parent"));
cancellation.cancel();
- let result = with_parent_context(parent, async {
+ let result = (async {
dispatch
.execute(
&(),