Skip to content

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

refactor(subagent): route dispatch through driver tool runner

Steven Enamakelba86d603ed72
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs b/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs
index 0d5a3b46b8..fd3b0f8ae5 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs
@@ -1,7 +1,7 @@
//! Subagent dispatch logic shared by all agent delegation tools.
use crate::agent::subagent_host::{
- run_subagent_with_parent, SubagentRunOptions, SubagentRunStatus,
+ run_subagent_via_driver_tool, SubagentRunOptions, SubagentRunStatus,
};
use crate::agent_registry::host_definition::AgentDefinitionRegistry;
use crate::progress::AgentProgress;
@@ -418,8 +418,14 @@ pub(crate) async fn dispatch_subagent_with_live_parent(
message_run_queue: None,
};
- let run =
- run_subagent_with_parent(live_parent, definition.clone(), prompt.to_owned(), options).await;
+ let run = run_subagent_via_driver_tool(
+ live_parent,
+ definition.clone(),
+ prompt.to_owned(),
+ options,
+ )
+ .await
+ .map(|(outcome, _job_id)| outcome);
match run {
Ok(outcome) => {
let emit_lifecycle_effects = outcome.should_emit_lifecycle_effects();
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
index 275c1e2579..0244180f96 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
@@ -95,11 +95,11 @@ pub async fn continue_subagent(
continue_subagent_with_parent(&root, original_key, definition.clone(), input, options).await
}
-/// Runs a host-prepared async spawn through TinyAgents' registered driver
+/// Runs a host-prepared subagent through TinyAgents' registered driver
/// dispatcher and shared Jobs/Message registry. Product preflight and result
/// delivery stay with the caller; the generic driver owns child registration,
/// execution, control queues, and terminal lifecycle transitions.
-pub(crate) async fn run_async_spawn_via_driver_tool(
+pub(crate) async fn run_subagent_via_driver_tool(
parent: &RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
definition: crate::agent_registry::host_definition::AgentDefinition,
input: String,
@@ -111,7 +111,8 @@ pub(crate) async fn run_async_spawn_via_driver_tool(
.unwrap_or_else(|| format!("sub-{}", uuid::Uuid::new_v4()));
let mut options = options;
options.task_id = Some(task_id.clone());
- let task_key = SubagentTaskKey::from_context(parent, task_id.clone(), None);
+ let parent_thread_id = parent.thread_id().map(|id| id.as_str().to_owned());
+ let task_key = SubagentTaskKey::from_context(parent, task_id.clone(), parent_thread_id);
let (tool_result, bundle) =
invoke_async_spawn_driver_tool(parent, definition, input, options, "inline", None, None)
.await?;
diff --git a/crates/openhuman-core/src/agent/subagent_host/mod.rs b/crates/openhuman-core/src/agent/subagent_host/mod.rs
index 44f52476e0..6ec1c2c42b 100644
--- a/crates/openhuman-core/src/agent/subagent_host/mod.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/mod.rs
@@ -57,8 +57,7 @@ mod persisted_compat_tests;
// Public API — the entry point and the shapes it returns.
pub use autonomous::{definition_iter_cap, subagent_iter_cap_with_autonomous_lift};
pub(crate) use lifecycle::load_subagent_checkpoint;
-#[cfg(test)]
-pub(crate) use lifecycle::run_async_spawn_via_driver_tool;
+pub(crate) use lifecycle::run_subagent_via_driver_tool;
#[cfg(test)]
pub(crate) use lifecycle::spawn_async_via_driver_tool_with_jobs;
pub(crate) use lifecycle::spawn_async_via_driver_tool;
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 9ca6e4eaea..c826008d73 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_with_jobs, SubagentRunStatus,
+ run_subagent_via_driver_tool, spawn_async_via_driver_tool_with_jobs, SubagentRunStatus,
};
use tinyagents_harness::context::{current_run_depth, with_run_depth, RunDepth};
@@ -52,7 +52,7 @@ async fn runner_rejects_spawn_beyond_max_depth() {
}
#[tokio::test]
-async fn prepared_async_spawn_runs_through_driver_jobs_dispatcher() {
+async fn prepared_subagent_runs_through_driver_jobs_dispatcher() {
let scratch = tempfile::tempdir().expect("isolated async spawn fixture");
let workspace = scratch.path().join("workspace");
std::fs::create_dir_all(&workspace).expect("create isolated workspace");
@@ -67,7 +67,7 @@ async fn prepared_async_spawn_runs_through_driver_jobs_dispatcher() {
.with_thread("driver-spawn-thread"),
);
- let (outcome, job_id) = run_async_spawn_via_driver_tool(
+ let (outcome, job_id) = run_subagent_via_driver_tool(
&parent,
make_def_named_tools(&[]),
"return the requested result".into(),