Skip to content

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

refactor: dispatch worker subagents with parent context

Steven Enamakel7d376baf4553
diff --git a/crates/openhuman-core/src/agent/orchestration/tools.rs b/crates/openhuman-core/src/agent/orchestration/tools.rs
index c90d3ea7cb..3ce44d13a8 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools.rs
@@ -78,6 +78,7 @@ pub use spawn_async_subagent::SpawnAsyncSubagentTool;
pub(crate) use spawn_parallel_agents::SpawnParallelAgentsDispatch;
pub use spawn_parallel_agents::SpawnParallelAgentsTool;
pub use spawn_subagent::SpawnSubagentTool;
+pub(crate) use spawn_worker_thread::SpawnWorkerThreadDispatch;
pub use spawn_worker_thread::SpawnWorkerThreadTool;
pub use steer_subagent::SteerSubagentTool;
pub use wait::{WaitLoopTool, WaitTool};
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_worker_thread.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_worker_thread.rs
index c180afe857..262f053dc8 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_worker_thread.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_worker_thread.rs
@@ -15,12 +15,47 @@ use crate::agent::harness::subagent_runner::{run_subagent, SubagentRunOptions};
use crate::memory::conversations;
use async_trait::async_trait;
use serde_json::json;
+use std::sync::Arc;
+use tinyagents_harness::context::RunContext;
+use tinyagents_harness::tool::{ToolDispatch, ToolExecutionContext};
use tinytools::ToolRunContext;
use tinytools::{PermissionLevel, Tool, ToolCallOptions, ToolResult};
/// Spawns a sub-agent in a dedicated worker thread.
pub struct SpawnWorkerThreadTool;
+pub(crate) struct SpawnWorkerThreadDispatch {
+ tool: Arc<dyn Tool>,
+}
+
+impl SpawnWorkerThreadDispatch {
+ pub(crate) fn new(tool: Arc<dyn Tool>) -> Self {
+ Self { tool }
+ }
+}
+
+#[async_trait]
+impl ToolDispatch<(), crate::agent::tinyagents::host::OpenHumanRunContext>
+ for SpawnWorkerThreadDispatch
+{
+ fn tool(&self) -> Arc<dyn Tool> {
+ self.tool.clone()
+ }
+
+ async fn execute(
+ &self,
+ _state: &(),
+ arguments: serde_json::Value,
+ _options: ToolCallOptions,
+ parent: &RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
+ ) -> anyhow::Result<ToolResult> {
+ let context = ToolExecutionContext::from_run_context(parent);
+ SpawnWorkerThreadTool::new()
+ .execute_with_parent_context(arguments, Some(&context), parent.data.child())
+ .await
+ }
+}
+
impl Default for SpawnWorkerThreadTool {
fn default() -> Self {
Self::new()
@@ -108,6 +143,22 @@ impl Tool for SpawnWorkerThreadTool {
args: serde_json::Value,
_options: ToolCallOptions,
tool_context: Option<&dyn ToolRunContext>,
+ ) -> anyhow::Result<ToolResult> {
+ self.execute_with_parent_context(
+ args,
+ tool_context,
+ crate::agent::tinyagents::host::OpenHumanRunContext::new(),
+ )
+ .await
+ }
+}
+
+impl SpawnWorkerThreadTool {
+ pub(crate) async fn execute_with_parent_context(
+ &self,
+ args: serde_json::Value,
+ tool_context: Option<&dyn ToolRunContext>,
+ run_context: crate::agent::tinyagents::host::OpenHumanRunContext,
) -> anyhow::Result<ToolResult> {
let started = std::time::Instant::now();
@@ -252,7 +303,7 @@ impl Tool for SpawnWorkerThreadTool {
thread_id: tool_context
.and_then(ToolRunContext::thread_id)
.map(str::to_owned),
- run_context: Default::default(),
+ run_context,
worker_thread_id: Some(worker_thread_id.clone()),
initial_history: None,
checkpoint_dir: None,
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs b/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs
index 495c84ffd0..022955eb31 100644
--- a/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs
@@ -11,7 +11,9 @@ use tinyagents_registry::{
CapabilityRegistry, ComponentKind, RegistryDiagnostic, RegistrySnapshot,
};
-use crate::agent::orchestration::tools::{SpawnAsyncSubagentDispatch, SpawnParallelAgentsDispatch};
+use crate::agent::orchestration::tools::{
+ SpawnAsyncSubagentDispatch, SpawnParallelAgentsDispatch, SpawnWorkerThreadDispatch,
+};
use crate::agent::tinyagents::host::OpenHumanRunContext;
use crate::agent::tinyagents::tools::{CanonicalSharedToolAdapter, EarlyExitHook};
use crate::agent::tinyagents::turn_policy::is_subagent_spawn_or_delegate_tool;
@@ -99,6 +101,9 @@ pub(super) fn register_turn_tools_and_agents(
} else if name == "spawn_async_subagent" {
harness
.register_tool_dispatch(Arc::new(SpawnAsyncSubagentDispatch::new(adapter)));
+ } else if name == "spawn_worker_thread" {
+ harness
+ .register_tool_dispatch(Arc::new(SpawnWorkerThreadDispatch::new(adapter)));
} else {
harness.register_tool(adapter);
}