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: preserve typed delegation context
Steven Enamakel6f519dc85e42
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/close_subagent.rs b/crates/openhuman-core/src/agent/orchestration/tools/close_subagent.rsindex b99f5fc025..5b378cf413 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/close_subagent.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/close_subagent.rs@@ -136,7 +136,10 @@ impl CloseSubagentTool {) {Ok(sessions) => sessions.iter()- .any(|session| session.subagent_session_id == subagent_session_id),+ .any(|session| {+ session.subagent_session_id == subagent_session_id+ && session.parent_thread_id.as_deref() == parent_thread_id+ }),Err(err) => {return Ok(ToolResult::error(format!("close_subagent: failed to read sub-agent sessions: {err}"diff --git a/crates/openhuman-core/src/agent/orchestration/tools/close_subagent_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/close_subagent_tests.rsindex 91aaddd9d7..2f97ae3ffa 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/close_subagent_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/close_subagent_tests.rs@@ -1,11 +1,13 @@use super::*;-use crate::agent::harness::fork_context::{with_parent_context, ParentExecutionContext};+use crate::agent::harness::fork_context::ParentExecutionContext;use crate::agent::prompts::ToolCallFormat;use crate::config::AgentConfig;use crate::memory::{Memory, MemoryCategory, MemoryEntry, NamespaceSummary, RecallOpts};use std::collections::HashSet;use std::path::Path;use std::sync::Arc;+use tinyagents_harness::context::RunConfig;+use tinyagents_harness::tool::ToolDispatch;#[tokio::test]async fn missing_session_id_is_rejected() {@@ -20,13 +22,7 @@ async fn rejects_session_from_different_parent_thread() {let store = SubagentSessionStore::new(workspace.path().to_path_buf());let session = seed_session(&store, "thread-b");- let res = with_parent_context(parent_context(workspace.path()), async {- CloseSubagentTool::new()- .execute(json!({ "subagent_session_id": session.subagent_session_id }))- .await- })- .await- .unwrap();+ let res = close_for_thread(workspace.path(), "thread-a", &session.subagent_session_id).await;assert!(res.is_error);assert!(res.output().contains("not found for this parent thread"));@@ -43,13 +39,7 @@ async fn closes_session_owned_by_current_parent_thread() {let store = SubagentSessionStore::new(workspace.path().to_path_buf());let session = seed_session(&store, "thread-a");- let res = with_parent_context(parent_context(workspace.path()), async {- CloseSubagentTool::new()- .execute(json!({ "subagent_session_id": session.subagent_session_id }))- .await- })- .await- .unwrap();+ let res = close_for_thread(workspace.path(), "thread-a", &session.subagent_session_id).await;assert!(!res.is_error, "{}", res.output());assert!(res.output().contains("closed=true"));@@ -60,6 +50,26 @@ async fn closes_session_owned_by_current_parent_thread() {);}+async fn close_for_thread(+ workspace: &Path,+ thread_id: &str,+ subagent_session_id: &str,+) -> tinytools::ToolResult {+ let parent = parent_context(workspace);+ let run = crate::agent::tinyagents::host::OpenHumanRunContext::new()+ .with_parent(parent)+ .into_tinyagents(RunConfig::new("close-subagent-test").with_thread(thread_id));+ CloseSubagentDispatch::new(Arc::new(CloseSubagentTool::new()))+ .execute(+ &(),+ json!({ "subagent_session_id": subagent_session_id }),+ tinytools::ToolCallOptions::default(),+ &run,+ )+ .await+ .expect("close dispatch")+}+fn seed_session(store: &SubagentSessionStore,parent_thread_id: &str,diff --git a/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs b/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rsindex c9e135794f..a8ff47af0d 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs@@ -213,11 +213,6 @@ pub(crate) async fn dispatch_subagent_with_live_parent(run_context: crate::agent::tinyagents::host::OpenHumanRunContext,live_parent: Option<&RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>>,) -> anyhow::Result<ToolResult> {- let Some(live_parent) = live_parent else {- return Ok(ToolResult::error(- "delegation requires a live harness run context.",- ));- };let parent_workspace_descriptor = tool_context.and_then(|ctx| ctx.workspace().cloned()).or_else(|| run_context.workspace.clone());@@ -258,6 +253,15 @@ pub(crate) async fn dispatch_subagent_with_live_parent(}}+ // Registry and policy failures are deterministic and safe to report even+ // to a raw tool caller. Executing a valid delegation still requires the+ // typed harness carrier below, which supplies cancellation and authority.+ let Some(live_parent) = live_parent else {+ return Ok(ToolResult::error(+ "delegation requires a live harness run context.",+ ));+ };+// ── Forward the current turn's attached image(s) to a vision sub-agent ──// The orchestrator runs on a non-vision tier and keeps the user's image as a// text placeholder (`[Image: … #att:<id>]`), so a delegated sub-agent woulddiff --git a/crates/openhuman-core/src/agent/orchestration/tools/dispatch_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/dispatch_tests.rsindex ec3c48e8e3..285821bab9 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/dispatch_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/dispatch_tests.rs@@ -74,17 +74,27 @@ fn typed_dispatch_registration_recognises_every_synthesised_delegate_surface() {"properties": { "toolkit": { "enum": ["gmail"] } }}),});+ let archetype_name = crate::agent::harness::definition::AgentDefinitionRegistry::global()+ .expect("builtins registry")+ .list()+ .into_iter()+ .next()+ .expect("at least one built-in")+ .delegate_name+ .clone()+ .unwrap_or_else(|| "delegate_researcher".to_owned());for tool in [collapsed,Arc::new(DelegationRegistrationTool {- name: "delegate_researcher",+ name: Box::leak(archetype_name.into_boxed_str()),parameters: serde_json::json!({}),}),integration,] {assert!(DelegationDispatch::for_tool(tool).is_some(),- "every synthesised delegation name must select the typed dispatch"+ "every synthesised delegation name must select the typed dispatch: {}",+ tool.name(),);}}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 22378befff..e59c9e19ca 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@@ -101,7 +101,7 @@ pub(crate) async fn execute_spawn_parallel_agents(};let Some(live_parent) = live_parent else {return Ok(ToolResult::error(- "spawn_parallel_agents requires a live harness run context.",+ "spawn_parallel_agents called outside of an agent turn",));};let outcome = run_spawn_parallel_tasks_with_cancellation_and_workspace(diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents_tests.rsindex 6e69050af3..ad15c89d31 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents_tests.rs@@ -192,16 +192,17 @@ async fn typed_dispatch_uses_the_parent_token_for_fanout_cancellation() {let cancellation = tinyagents_harness::CancellationToken::new();let workspace = tinytools::WorkspaceDescriptor::new("/work/parent-action");let started = Arc::new(tokio::sync::Notify::new());- let parent_run = OpenHumanRunContext::new()- .with_cancellation(cancellation.clone())- .with_workspace(workspace.clone())- .into_tinyagents(tinyagents_harness::context::RunConfig::new("parent"));let dispatch = SpawnParallelAgentsDispatch::new(Arc::new(SpawnParallelAgentsTool::new()));let mut parent = parent_context(4);parent.turn_model_source =crate::agent::tinyagents::TurnModelSource::from_model(Arc::new(BlockingFanoutModel {started: started.clone(),}));+ let parent_run = OpenHumanRunContext::new()+ .with_parent(parent.clone())+ .with_cancellation(cancellation.clone())+ .with_workspace(workspace.clone())+ .into_tinyagents(tinyagents_harness::context::RunConfig::new("parent"));let run = with_parent_context(parent, async {dispatchdiff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tests.rsindex 1d4de1e090..c26546a40c 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tests.rs@@ -236,14 +236,14 @@ async fn legacy_archetype_alias_is_normalized_to_agent_id() {.unwrap();assert!(result.is_error);// The alias resolved: the call got past argument validation and only- // failed later, on the missing parent turn.+ // failed later, because raw tool execution has no typed harness parent.assert!(!result.output().contains("agent_id is required"),"{}",result.output());assert!(- result.output().contains("called outside of an agent turn"),+ result.output().contains("requires a live harness run context"),"{}",result.output());@@ -276,8 +276,8 @@ async fn async_default_self_heals_to_blocking_without_delivery_thread() {"thread-less spawn_subagent must not hit the async delivery guard: {out}");assert!(- out.contains("spawn_subagent called outside of an agent turn"),- "expected the blocking path's own error: {out}"+ out.contains("requires a live harness run context"),+ "a raw tool call must reject missing typed authority: {out}");}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 dc6e528399..c2c257272e 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@@ -203,12 +203,6 @@ impl SpawnSubagentTool {if prompt.is_empty() {return Ok(ToolResult::error("spawn_subagent: `prompt` is required"));}- let Some(live_parent) = live_parent else {- return Ok(ToolResult::error(- "spawn_subagent requires a live harness run context.",- ));- };-let registry = match AgentDefinitionRegistry::global() {Some(reg) => reg,None => {@@ -409,6 +403,15 @@ impl SpawnSubagentTool {}}+ // Input, registry, allowlist, and integration validation are safe to+ // perform without a live run. A valid spawn must still fail closed+ // unless its typed harness parent carries authority and cancellation.+ let Some(live_parent) = live_parent else {+ return Ok(ToolResult::error(+ "spawn_subagent requires a live harness run context.",+ ));+ };+// Async-by-default only holds where the finished result has somewhere// to land. `spawn_async_subagent` delivers thread-addressed (see// `background_delivery`), so outside a chat turn (flow `agent` node,diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_worker_thread_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_worker_thread_tests.rsindex 8871e207a9..42446d9cd9 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_worker_thread_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_worker_thread_tests.rs@@ -5,6 +5,8 @@ use crate::memory::conversations::CreateConversationThread;use std::path::PathBuf;use std::sync::Arc;use tempfile::TempDir;+use tinyagents_harness::context::RunConfig;+use tinyagents_harness::tool::ToolDispatch;struct MockMemory;#[async_trait]@@ -105,24 +107,12 @@ async fn rejects_if_already_worker_thread() {).unwrap();- let parent = test_parent_ctx(temp.path().to_path_buf());- with_parent_context(parent, async {- let tool = SpawnWorkerThreadTool::new();- let result = tool- .execute(json!({- "agent_id": "researcher",- "prompt": "do it",- "task_title": "Task"- }))- .await- .unwrap();+ let result = spawn_from_thread(temp.path(), thread_id).await;- assert!(result.is_error);- assert!(result- .output()- .contains("cannot spawn other worker threads"));- })- .await;+ assert!(result.is_error);+ assert!(result+ .output()+ .contains("cannot spawn other worker threads"));}#[tokio::test]@@ -142,24 +132,32 @@ async fn rejects_if_has_parent_thread_id() {).unwrap();- let parent = test_parent_ctx(temp.path().to_path_buf());- with_parent_context(parent, async {- let tool = SpawnWorkerThreadTool::new();- let result = tool- .execute(json!({+ let result = spawn_from_thread(temp.path(), thread_id).await;++ assert!(result.is_error);+ assert!(result+ .output()+ .contains("cannot spawn other worker threads"));+}++async fn spawn_from_thread(workspace: &std::path::Path, thread_id: &str) -> tinytools::ToolResult {+ let parent = test_parent_ctx(workspace.to_path_buf());+ let run = crate::agent::tinyagents::host::OpenHumanRunContext::new()+ .with_parent(parent)+ .into_tinyagents(RunConfig::new("worker-depth-test").with_thread(thread_id));+ SpawnWorkerThreadDispatch::new(Arc::new(SpawnWorkerThreadTool::new()))+ .execute(+ &(),+ json!({"agent_id": "researcher","prompt": "do it","task_title": "Task"- }))- .await- .unwrap();-- assert!(result.is_error);- assert!(result- .output()- .contains("cannot spawn other worker threads"));- })- .await;+ }),+ tinytools::ToolCallOptions::default(),+ &run,+ )+ .await+ .expect("worker dispatch")}#[tokio::test]diff --git a/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_tests.rsindex 7feb812ec6..95a88f137c 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_tests.rs@@ -13,6 +13,7 @@ use parking_lot::Mutex;use serde_json::json;use std::path::Path;use std::sync::Arc;+use tinyagents_harness::context::RunConfig;use tinyinference_llm::message::Message;use tinyinference_llm::model::{ChatModel, ModelProfile, ModelRequest, ModelResponse};use tinytools::Tool;@@ -119,12 +120,23 @@ async fn archetype_delegation_defaults_to_async_with_durable_session_e2e() {let mut ctx = parent_context(workspace.path(), provider.clone(), vec![]);ctx.session_id = "tools-e2e-async-session".into();+ let mut parent_data = crate::agent::tinyagents::host::OpenHumanRunContext::new();+ parent_data.thread_id = Some("thread-async-parent".into());+ let parent_run = parent_data+ .with_parent(ctx.clone())+ .into_tinyagents(RunConfig::new("archetype-async-e2e").with_thread("thread-async-parent"));let result = with_parent_context(ctx, async {- tool.execute(json!({- "prompt": format!("Research {ARCHETYPE_DELEGATION_CANARY} in the background"),- "model": "test-model"- }))- .await+ super::archetype_delegation::execute_archetype_delegation_with_live_parent(+ &tool.agent_id.0,+ &tool.tool_name,+ json!({+ "prompt": format!("Research {ARCHETYPE_DELEGATION_CANARY} in the background"),+ "model": "test-model"+ }),+ None,+ parent_run.data.child(),+ Some(&parent_run),+ ).await}).await.expect("tool execution");@@ -247,14 +259,26 @@ async fn continue_subagent_resumes_idle_durable_session_e2e() {let mut ctx = parent_context(workspace.path(), provider.clone(), vec![]);ctx.session_id = "tools-e2e-continue-session".into();+ let mut parent_data = crate::agent::tinyagents::host::OpenHumanRunContext::new();+ parent_data.thread_id = Some("thread-continue-parent".into());+ let parent_run = parent_data+ .with_parent(ctx.clone())+ .into_tinyagents(+ RunConfig::new("continue-async-e2e").with_thread("thread-continue-parent"),+ );let session_id = session.subagent_session_id.clone();let result = with_parent_context(ctx, async {ContinueSubagentTool::new()- .execute(json!({- "task_id": session_id,- "agent_id": "researcher",- "message": "looks good — proceed with continue-durable-canary"- }))+ .execute_with_live_parent_context(+ json!({+ "task_id": session_id,+ "agent_id": "researcher",+ "message": "looks good — proceed with continue-durable-canary"+ }),+ None,+ parent_run.data.child(),+ Some(&parent_run),+ ).await}).await