The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix: retain parent context for direct delegation
Steven Enamakel696be978aa3b
diff --git a/crates/openhuman-core/src/agent/orchestration/tools.rs b/crates/openhuman-core/src/agent/orchestration/tools.rsindex e58bf1cc92..2e21331ac4 100644--- a/crates/openhuman-core/src/agent/orchestration/tools.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools.rs@@ -63,6 +63,23 @@ mod worker_thread;pub(crate) use dispatch::DelegationDispatch;+/// Recreate the minimal live TinyAgents carrier for callers that invoke a+/// concrete tool directly inside `with_parent_context`. Normal agent turns+/// always arrive through the typed dispatchers with their original carrier;+/// this compatibility path keeps controller/test callers inside an explicit+/// parent context from losing their recursive delegation authority.+pub(crate) fn ambient_parent_run_context(+ kind: &str,+) -> Option<+ tinyagents_harness::context::RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,+> {+ crate::agent::harness::current_parent().map(|parent| {+ crate::agent::tinyagents::host::OpenHumanRunContext::new()+ .with_parent(parent)+ .into_tinyagents(tinyagents_harness::context::RunConfig::new(kind))+ })+}+pub(crate) use agent_prepare_context::AgentPrepareContextDispatch;pub use agent_prepare_context::{run_context_scout, run_context_scout_with_catalog, AgentPrepareContextTool,diff --git a/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context/scout_run.rs b/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context/scout_run.rsindex b83a96c07b..0d2e10046a 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context/scout_run.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context/scout_run.rs@@ -225,12 +225,6 @@ pub(super) async fn run_context_scout_with_catalog_and_workspace(>,>,) -> anyhow::Result<ToolResult> {- let Some(live_parent) = live_parent else {- return Ok(ToolResult::error(- "agent_prepare_context requires a live harness run context.",- ));- };- let parent = run_context.parent.clone();let question = question.trim().to_string();let focus = focus.map(|s| s.to_string());@@ -247,6 +241,13 @@ pub(super) async fn run_context_scout_with_catalog_and_workspace());}+ let Some(live_parent) = live_parent else {+ return Ok(ToolResult::error(+ "agent_prepare_context requires a live harness run context.",+ ));+ };+ let parent = run_context.parent.clone();+let registry = match AgentDefinitionRegistry::global() {Some(reg) => reg,None => {diff --git a/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context/tool.rs b/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context/tool.rsindex b9575d794c..23b44ffa4f 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context/tool.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context/tool.rs@@ -231,6 +231,18 @@ impl Tool for AgentPrepareContextTool {_options: ToolCallOptions,tool_context: Option<&dyn ToolRunContext>,) -> anyhow::Result<ToolResult> {+ if let Some(live_parent) = super::super::ambient_parent_run_context("direct-context-scout")+ {+ let run_context = live_parent.data.child();+ return self+ .execute_with_live_parent_context(+ args,+ tool_context,+ run_context,+ Some(&live_parent),+ )+ .await;+ }self.execute_with_parent_context(args,tool_context,@@ -260,7 +272,13 @@ impl AgentPrepareContextTool {run_context: crate::agent::tinyagents::host::OpenHumanRunContext,live_parent: Option<&RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>>,) -> anyhow::Result<ToolResult> {- let prepared_sources = run_context.prepared_context_sources.as_ref();+ let ambient_prepared_sources =+ crate::agent::harness::current_agent_context_prepared_sources();+ let prepared_sources = if run_context.prepared_context_sources.is_empty() {+ ambient_prepared_sources.as_slice()+ } else {+ run_context.prepared_context_sources.as_ref()+ };if !prepared_sources.is_empty() {tracing::info!(target: "agent_prepare_context",diff --git a/crates/openhuman-core/src/agent/orchestration/tools/archetype_delegation.rs b/crates/openhuman-core/src/agent/orchestration/tools/archetype_delegation.rsindex e4d7b47824..2f5f230b42 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/archetype_delegation.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/archetype_delegation.rs@@ -178,6 +178,18 @@ pub(crate) async fn execute_archetype_delegation(tool_context: Option<&dyn ToolRunContext>,run_context: crate::agent::tinyagents::host::OpenHumanRunContext,) -> anyhow::Result<ToolResult> {+ if let Some(live_parent) = super::ambient_parent_run_context("direct-archetype-delegation") {+ let run_context = live_parent.data.child();+ return execute_archetype_delegation_with_live_parent(+ agent_id,+ tool_name,+ args,+ tool_context,+ run_context,+ Some(&live_parent),+ )+ .await;+ }execute_archetype_delegation_with_live_parent(agent_id,tool_name,diff --git a/crates/openhuman-core/src/agent/orchestration/tools/close_subagent.rs b/crates/openhuman-core/src/agent/orchestration/tools/close_subagent.rsindex 97df6686ef..b99f5fc025 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/close_subagent.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/close_subagent.rs@@ -92,8 +92,12 @@ impl Tool for CloseSubagentTool {_options: ToolCallOptions,tool_context: Option<&dyn ToolRunContext>,) -> anyhow::Result<ToolResult> {- self.execute_with_parent_context(args, None, tool_context)- .await+ self.execute_with_parent_context(+ args,+ crate::agent::harness::current_parent(),+ tool_context,+ )+ .await}}diff --git a/crates/openhuman-core/src/agent/orchestration/tools/continue_subagent.rs b/crates/openhuman-core/src/agent/orchestration/tools/continue_subagent.rsindex 6d86a73901..4b2bc6c900 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/continue_subagent.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/continue_subagent.rs@@ -225,6 +225,17 @@ impl Tool for ContinueSubagentTool {_options: ToolCallOptions,tool_context: Option<&dyn ToolRunContext>,) -> anyhow::Result<ToolResult> {+ if let Some(live_parent) = super::ambient_parent_run_context("direct-continue-subagent") {+ let run_context = live_parent.data.child();+ return self+ .execute_with_live_parent_context(+ args,+ tool_context,+ run_context,+ Some(&live_parent),+ )+ .await;+ }self.execute_with_parent_context(args,tool_context,diff --git a/crates/openhuman-core/src/agent/orchestration/tools/skill_delegation.rs b/crates/openhuman-core/src/agent/orchestration/tools/skill_delegation.rsindex de8173db54..74077374b7 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/skill_delegation.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/skill_delegation.rs@@ -225,6 +225,18 @@ pub(crate) async fn execute_skill_delegation(tool_context: Option<&dyn ToolRunContext>,run_context: crate::agent::tinyagents::host::OpenHumanRunContext,) -> anyhow::Result<ToolResult> {+ if let Some(live_parent) = super::ambient_parent_run_context("direct-skill-delegation") {+ let run_context = live_parent.data.child();+ return execute_skill_delegation_with_live_parent(+ tool_name,+ connected_toolkits,+ args,+ tool_context,+ run_context,+ Some(&live_parent),+ )+ .await;+ }execute_skill_delegation_with_live_parent(tool_name,connected_toolkits,diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent.rsindex 9dddd360cf..53767e540c 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent.rs@@ -163,13 +163,37 @@ impl Tool for SpawnAsyncSubagentTool {async fn execute_with_context(&self,- _args: serde_json::Value,- _options: ToolCallOptions,- _tool_context: Option<&dyn ToolRunContext>,+ args: serde_json::Value,+ options: ToolCallOptions,+ tool_context: Option<&dyn ToolRunContext>,) -> anyhow::Result<ToolResult> {- Ok(ToolResult::error(- "spawn_async_subagent requires a live harness run context.",- ))+ if let Some(live_parent) = super::ambient_parent_run_context("direct-async-subagent") {+ let detached_data = live_parent.data.detached_child();+ let detached_cancellation = detached_data.cancellation.clone();+ let detached_parent = live_parent+ .child(+ RunConfig::new(format!("async-subagent-{}", uuid::Uuid::new_v4())),+ detached_data,+ )+ .map_err(|error| anyhow::anyhow!(error.to_string()))?+ .with_cancellation(detached_cancellation);+ return self+ .execute_with_live_parent_context(+ args,+ tool_context,+ live_parent.data.child(),+ detached_parent,+ )+ .await;+ }+ self.execute_with_context_inner(+ args,+ options,+ tool_context,+ crate::agent::tinyagents::host::OpenHumanRunContext::new(),+ None,+ )+ .await}}diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents.rsindex be386d2b6d..22378befff 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents.rs@@ -237,6 +237,16 @@ impl Tool for SpawnParallelAgentsTool {_options: ToolCallOptions,tool_context: Option<&dyn ToolRunContext>,) -> anyhow::Result<ToolResult> {+ if let Some(live_parent) = super::ambient_parent_run_context("direct-spawn-parallel") {+ return execute_spawn_parallel_agents(+ args,+ live_parent.cancellation.clone(),+ live_parent.workspace.clone(),+ live_parent.data.child(),+ Some(&live_parent),+ )+ .await;+ }let workspace_descriptor = tool_context.and_then(|ctx| ctx.workspace().cloned());execute_spawn_parallel_agents(args,diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tool_impl.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tool_impl.rsindex a7601c5b67..dc6e528399 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tool_impl.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tool_impl.rs@@ -105,6 +105,17 @@ impl Tool for SpawnSubagentTool {_options: ToolCallOptions,tool_context: Option<&dyn ToolRunContext>,) -> anyhow::Result<ToolResult> {+ if let Some(live_parent) = super::ambient_parent_run_context("direct-spawn-subagent") {+ let run_context = live_parent.data.child();+ return self+ .execute_with_live_parent_context(+ args,+ tool_context,+ run_context,+ Some(&live_parent),+ )+ .await;+ }self.execute_with_parent_context(args,tool_context,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.rsindex a8e1685562..a25cc03b1d 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@@ -148,6 +148,17 @@ impl Tool for SpawnWorkerThreadTool {_options: ToolCallOptions,tool_context: Option<&dyn ToolRunContext>,) -> anyhow::Result<ToolResult> {+ if let Some(live_parent) = super::ambient_parent_run_context("direct-spawn-worker") {+ let run_context = live_parent.data.child();+ return self+ .execute_with_live_parent_context(+ args,+ tool_context,+ run_context,+ Some(&live_parent),+ )+ .await;+ }self.execute_with_parent_context(args,tool_context,