Skip to content

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

refactor: dispatch continuations with parent context

Steven Enamakel32ed39b4a838
diff --git a/crates/openhuman-core/src/agent/orchestration/tools.rs b/crates/openhuman-core/src/agent/orchestration/tools.rs
index bd6481aff2..c65736d6e1 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools.rs
@@ -69,6 +69,7 @@ pub use agent_prepare_context::{
pub use archetype_delegation::{ArchetypeDelegationTool, DelegationTarget};
pub use close_subagent::CloseSubagentTool;
pub use collapsed_delegation::{CollapsedDelegationTool, DelegateTarget, DELEGATE_TO_TOOL_NAME};
+pub(crate) use continue_subagent::ContinueSubagentDispatch;
pub use continue_subagent::ContinueSubagentTool;
pub use delegate_graph::DelegateGraphTool;
pub use list_subagents::ListSubagentsTool;
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/continue_subagent.rs b/crates/openhuman-core/src/agent/orchestration/tools/continue_subagent.rs
index fa4bb558c9..37d224b8da 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/continue_subagent.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/continue_subagent.rs
@@ -17,11 +17,46 @@ use crate::agent::messages::ChatMessage;
use crate::agent::progress::AgentProgress;
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};
pub struct ContinueSubagentTool;
+pub(crate) struct ContinueSubagentDispatch {
+ tool: Arc<dyn Tool>,
+}
+
+impl ContinueSubagentDispatch {
+ pub(crate) fn new(tool: Arc<dyn Tool>) -> Self {
+ Self { tool }
+ }
+}
+
+#[async_trait]
+impl ToolDispatch<(), crate::agent::tinyagents::host::OpenHumanRunContext>
+ for ContinueSubagentDispatch
+{
+ 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);
+ ContinueSubagentTool::new()
+ .execute_with_parent_context(arguments, Some(&context), parent.data.child())
+ .await
+ }
+}
+
impl Default for ContinueSubagentTool {
fn default() -> Self {
Self::new()
@@ -166,6 +201,22 @@ impl Tool for ContinueSubagentTool {
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 ContinueSubagentTool {
+ 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 task_id = args
.get("task_id")
@@ -371,7 +422,7 @@ impl Tool for ContinueSubagentTool {
thread_id: tool_context
.and_then(ToolRunContext::thread_id)
.map(str::to_owned),
- run_context: Default::default(),
+ run_context,
worker_thread_id: checkpoint.worker_thread_id.clone(),
initial_history: Some(history),
checkpoint_dir: Some(checkpoint_dir.clone()),
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 13a2290e03..d98a10f3c6 100644
--- a/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs
@@ -12,8 +12,8 @@ use tinyagents_registry::{
};
use crate::agent::orchestration::tools::{
- SpawnAsyncSubagentDispatch, SpawnParallelAgentsDispatch, SpawnSubagentDispatch,
- SpawnWorkerThreadDispatch,
+ ContinueSubagentDispatch, SpawnAsyncSubagentDispatch, SpawnParallelAgentsDispatch,
+ SpawnSubagentDispatch, SpawnWorkerThreadDispatch,
};
use crate::agent::tinyagents::host::OpenHumanRunContext;
use crate::agent::tinyagents::tools::{CanonicalSharedToolAdapter, EarlyExitHook};
@@ -107,6 +107,9 @@ pub(super) fn register_turn_tools_and_agents(
.register_tool_dispatch(Arc::new(SpawnWorkerThreadDispatch::new(adapter)));
} else if name == "spawn_subagent" {
harness.register_tool_dispatch(Arc::new(SpawnSubagentDispatch::new(adapter)));
+ } else if name == "continue_subagent" {
+ harness
+ .register_tool_dispatch(Arc::new(ContinueSubagentDispatch::new(adapter)));
} else {
harness.register_tool(adapter);
}