Skip to content

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

refactor(subagent_host): allow injecting a job registry into async spawn

Steven Enamakel9430457129cd
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
index a9309292ee..5b8c7456e5 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
@@ -119,6 +119,7 @@ pub(crate) async fn run_async_spawn_via_driver_tool(
options,
"inline",
None,
+ None,
)
.await?;
let public_job_id = decode_driver_job_result(tool_result, &bundle, &task_key)?;
@@ -159,6 +160,51 @@ pub(crate) async fn spawn_async_via_driver_tool(
+ Send
+ Sync
+ 'static,
+) -> Result<String, SubagentRunError> {
+ spawn_async_via_driver_tool_using_jobs(parent, definition, input, options, None, completion).await
+}
+
+#[cfg(test)]
+pub(crate) async fn spawn_async_via_driver_tool_with_jobs(
+ parent: &RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
+ definition: crate::agent_registry::host_definition::AgentDefinition,
+ input: String,
+ options: SubagentRunOptions,
+ jobs: tinyagents_orchestration::subagent::SubAgentJobRegistry,
+ completion: impl Fn(
+ String,
+ Result<SubagentRunOutcome, String>,
+ bool,
+ ) -> Pin<Box<dyn Future<Output = ()> + Send>>
+ + Send
+ + Sync
+ + 'static,
+) -> Result<String, SubagentRunError> {
+ spawn_async_via_driver_tool_using_jobs(
+ parent,
+ definition,
+ input,
+ options,
+ Some(jobs),
+ completion,
+ )
+ .await
+}
+
+async fn spawn_async_via_driver_tool_using_jobs(
+ parent: &RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
+ definition: crate::agent_registry::host_definition::AgentDefinition,
+ input: String,
+ options: SubagentRunOptions,
+ jobs: Option<tinyagents_orchestration::subagent::SubAgentJobRegistry>,
+ completion: impl Fn(
+ String,
+ Result<SubagentRunOutcome, String>,
+ bool,
+ ) -> Pin<Box<dyn Future<Output = ()> + Send>>
+ + Send
+ + Sync
+ + 'static,
) -> Result<String, SubagentRunError> {
let task_id = options
.task_id
@@ -174,6 +220,7 @@ pub(crate) async fn spawn_async_via_driver_tool(
options,
"background",
Some(Arc::new(completion)),
+ jobs,
)
.await?;
decode_driver_job_result(tool_result, &bundle, &task_key)
@@ -193,6 +240,7 @@ async fn invoke_async_spawn_driver_tool(
options: SubagentRunOptions,
mode: &str,
completion: Option<HostCompletion>,
+ jobs_override: Option<tinyagents_orchestration::subagent::SubAgentJobRegistry>,
) -> Result<(tinytools::ToolResult, OpenHumanDriverBundle), SubagentRunError> {
use tinyagents_harness::tool::ToolDispatch;
use tinyagents_orchestration::subagent::{DriverSubAgentTool, SubAgentJobRegistry};
@@ -247,7 +295,9 @@ async fn invoke_async_spawn_driver_tool(
|request| Some(request.task_id().to_owned()),
);
let dispatch_ctx = parent.data.dispatch_ctx();
- let jobs = (*crate::core::runtime::slot_for::<SubAgentJobRegistry>(&dispatch_ctx)).clone();
+ let jobs = jobs_override.unwrap_or_else(|| {
+ (*crate::core::runtime::slot_for::<SubAgentJobRegistry>(&dispatch_ctx)).clone()
+ });
let parent_session = parent
.data
.parent
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops_tests_model_resolution_tests.rs b/crates/openhuman-core/src/agent/subagent_host/ops_tests_model_resolution_tests.rs
index ed04738978..a8116815c0 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops_tests_model_resolution_tests.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops_tests_model_resolution_tests.rs
@@ -1,7 +1,7 @@
use super::*;
use crate::agent::subagent_host::run_subagent;
use crate::agent::subagent_host::{
- run_async_spawn_via_driver_tool, spawn_async_via_driver_tool, SubagentRunStatus,
+ run_async_spawn_via_driver_tool, spawn_async_via_driver_tool_with_jobs, SubagentRunStatus,
};
use tinyagents_harness::context::{current_run_depth, with_run_depth, RunDepth};
@@ -114,11 +114,12 @@ async fn detached_driver_spawn_repairs_replayed_host_outcome_without_reexecution
first_options.task_id = Some("driver-replay-task".into());
first_options.checkpoint_dir = Some(scratch.path().join("checkpoints"));
first_options.run_context.thread_id = Some("driver-replay-thread".into());
- spawn_async_via_driver_tool(
+ spawn_async_via_driver_tool_with_jobs(
&parent,
make_def_named_tools(&[]),
"return the persisted result".into(),
first_options,
+ tinyagents_orchestration::subagent::SubAgentJobRegistry::new(),
move |_target, result, effects| {
let first_tx = first_tx.clone();
Box::pin(async move {
@@ -148,11 +149,12 @@ async fn detached_driver_spawn_repairs_replayed_host_outcome_without_reexecution
replay_options.task_id = Some("driver-replay-task".into());
replay_options.checkpoint_dir = Some(scratch.path().join("checkpoints"));
replay_options.run_context.thread_id = Some("driver-replay-thread".into());
- spawn_async_via_driver_tool(
+ spawn_async_via_driver_tool_with_jobs(
&parent,
make_def_named_tools(&[]),
"return the persisted result".into(),
replay_options,
+ tinyagents_orchestration::subagent::SubAgentJobRegistry::new(),
move |_target, result, effects| {
let replay_tx = replay_tx.clone();
Box::pin(async move {