Skip to content

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

fix(delegate): route configured delegate through shared driver lifecycle

Steven Enamakelf7581f92bb3f
diff --git a/crates/openhuman-core/src/agent/subagent_host/mod.rs b/crates/openhuman-core/src/agent/subagent_host/mod.rs
index b4fd843b50..5d3229808d 100644
--- a/crates/openhuman-core/src/agent/subagent_host/mod.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/mod.rs
@@ -59,6 +59,7 @@ pub use autonomous::{definition_iter_cap, subagent_iter_cap_with_autonomous_lift
pub(crate) use lifecycle::load_subagent_checkpoint;
pub(crate) use lifecycle::{checkpoint_resume, continue_subagent_via_driver_tool};
pub(crate) use lifecycle::run_subagent_via_driver_tool;
+pub(crate) use lifecycle::run_configured_delegate_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/tools/delegate.rs b/crates/openhuman-core/src/tools/delegate.rs
index 54a2a70a55..1122dd2239 100644
--- a/crates/openhuman-core/src/tools/delegate.rs
+++ b/crates/openhuman-core/src/tools/delegate.rs
@@ -29,12 +29,8 @@ pub struct DelegateTool {
depth: u32,
}
-/// Typed harness dispatch for the config-defined `delegate` tool.
-///
-/// The configured tool remains the canonical executor (and therefore retains
-/// its configured agents, model routing, and security policy); this wrapper
-/// supplies the live thread/workspace context and makes cancellation explicit
-/// instead of relying on a task-local carrier.
+/// Host adapter that places the config-defined one-shot executor behind the
+/// shared driver lifecycle while retaining the configured Tool instance.
pub(crate) struct DelegateToolDispatch {
tool: Arc<dyn Tool>,
}
@@ -58,17 +54,24 @@ impl ToolDispatch<(), crate::agent::tinyagents::host::OpenHumanRunContext>
_state: &(),
_call_id: tinyagents_harness::CallId,
arguments: serde_json::Value,
- options: ToolCallOptions,
+ _options: ToolCallOptions,
parent: &RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
) -> anyhow::Result<ToolResult> {
- let context = ToolExecutionContext::from_run_context(parent, _call_id.clone());
- let child = parent.data.child();
- tokio::select! {
- _ = child.cancellation.cancelled() => Ok(ToolResult::error(
- "delegate: cancelled before the configured agent completed"
- )),
- result = self.tool.execute_with_context(arguments, options, Some(&context)) => result,
- }
+ let agent_id = arguments
+ .get("agent")
+ .and_then(serde_json::Value::as_str)
+ .map(str::trim)
+ .filter(|agent| !agent.is_empty())
+ .unwrap_or("delegate")
+ .to_owned();
+ crate::agent::subagent_host::run_configured_delegate_via_driver_tool(
+ parent,
+ self.tool.clone(),
+ arguments,
+ agent_id,
+ )
+ .await
+ .map_err(|error| anyhow::anyhow!("delegate: {error}"))
}
}