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
refactor(agent): simplify host request invocation handling
Steven Enamakel5426743a37b9
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rsindex 1e913a65a1..6dfb074694 100644--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs@@ -294,7 +294,7 @@ async fn invoke_async_spawn_driver_tool(invoke_driver_tool_with_request(parent,HostRequest {- invocation: HostInvocation::Agent(definition),+ invocation: definition,options,},input,@@ -622,7 +622,7 @@ impl OpenHumanSubagentHost {) -> Result<SubagentRunOutcome, SubagentRunError> {let fallback_agent_id = self.definition.id.clone();let request = HostRequest {- invocation: HostInvocation::Agent(self.definition),+ invocation: self.definition,options: self.options,};let driver = OpenHumanDriverBundle::with_in_flight_for(diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rsindex c21c8fbfec..287e83a138 100644--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs@@ -5,7 +5,6 @@ pub(crate) struct OpenHumanDriverBundle {Arc<SubagentDriver<crate::agent::tinyagents::host::OpenHumanRunContext, HostRequest>>,pub(crate) failures: Arc<Mutex<HashMap<SubagentTaskKey, SubagentRunError>>>,pub(crate) host_outcome: Arc<Mutex<HashMap<SubagentTaskKey, SubagentRunOutcome>>>,- pub(super) configured_tool_result: Arc<Mutex<HashMap<SubagentTaskKey, tinytools::ToolResult>>>,pub(crate) persistence: Arc<OpenHumanPersistence>,}@@ -37,7 +36,6 @@ impl OpenHumanDriverBundle {) -> Result<Self, SubagentRunError> {let failures = Arc::new(Mutex::new(HashMap::new()));let host_outcome = Arc::new(Mutex::new(HashMap::new()));- let configured_tool_result = Arc::new(Mutex::new(HashMap::new()));let plans = Arc::new(Mutex::new(HashMap::new()));let planner = Arc::new(OpenHumanPlanner {plans: Arc::clone(&plans),@@ -46,7 +44,6 @@ impl OpenHumanDriverBundle {plans,failures: Arc::clone(&failures),host_outcome: Arc::clone(&host_outcome),- configured_tool_result: Arc::clone(&configured_tool_result),});let persistence = Arc::new(OpenHumanPersistence::new(checkpoint_dir)@@ -69,7 +66,6 @@ impl OpenHumanDriverBundle {driver,failures,host_outcome,- configured_tool_result,persistence,})}@@ -77,31 +73,18 @@ impl OpenHumanDriverBundle {#[derive(Clone)]pub(crate) struct HostRequest {- pub(super) invocation: HostInvocation,+ pub(super) invocation: crate::agent_registry::host_definition::AgentDefinition,pub(crate) options: SubagentRunOptions,}-#[derive(Clone)]-pub(super) enum HostInvocation {- Agent(crate::agent_registry::host_definition::AgentDefinition),- ConfiguredTool {- agent_id: String,- tool: Arc<dyn tinytools::Tool>,- arguments: serde_json::Value,- },-}-impl HostRequest {pub(super) fn agent_id(&self) -> &str {- match &self.invocation {- HostInvocation::Agent(definition) => &definition.id,- HostInvocation::ConfiguredTool { agent_id, .. } => agent_id,- }+ &self.invocation.id}}struct PreparedHostPlan {- invocation: HostInvocation,+ invocation: crate::agent_registry::host_definition::AgentDefinition,options: SubagentRunOptions,}@@ -164,7 +147,6 @@ struct OpenHumanExecutor {plans: Arc<Mutex<HashMap<SubagentTaskKey, PreparedHostPlan>>>,failures: Arc<Mutex<HashMap<SubagentTaskKey, SubagentRunError>>>,host_outcome: Arc<Mutex<HashMap<SubagentTaskKey, SubagentRunOutcome>>>,- configured_tool_result: Arc<Mutex<HashMap<SubagentTaskKey, tinytools::ToolResult>>>,}#[async_trait]@@ -201,8 +183,7 @@ impl SubagentExecutor<crate::agent::tinyagents::host::OpenHumanRunContext> for O.last().map(Message::text).unwrap_or_default();- match invocation {- HostInvocation::Agent(definition) => {+ {let native = crate::agent::tinyagents::NativeSubagentRunContext {depth: native_run_config.lineage.depth,config: native_run_config,@@ -244,107 +225,6 @@ impl SubagentExecutor<crate::agent::tinyagents::host::OpenHumanRunContext> for O))}}- }- HostInvocation::ConfiguredTool {- agent_id,- tool,- arguments,- } => {- let tool_context = tinyagents_harness::tool::ToolExecutionContext::from_run_context(- &execution.prepared.run_context,- tinyagents_harness::CallId::new(format!("delegate-{}", task_key.task_id)),- );- let cancellation = execution.cancellation.clone();- let invoke = Box::pin(async move {- tokio::select! {- _ = cancellation.cancelled() => (- Ok(tinytools::ToolResult::error(- "delegate: cancelled before the configured agent completed"- )),- true,- ),- result = tool.execute_with_context(- arguments,- tinytools::ToolCallOptions::default(),- Some(&tool_context),- ) => (result, false),- }- });- let result = match dispatch.into_core() {- Some(core) => {- crate::core::runtime::CoreContext::scope_with_turn_origin(- core, origin, invoke,- )- .await- }- None => invoke.await,- };- match result {- (Ok(tool_result), cancelled) => {- let output = tool_result.output();- let status = if cancelled {- SubagentRunStatus::Cancelled- } else if tool_result.is_error {- SubagentRunStatus::Incomplete {- reason: "configured delegate reported failure".into(),- }- } else {- SubagentRunStatus::Completed- };- self.host_outcome- .lock()- .unwrap_or_else(|p| p.into_inner())- .insert(- task_key.clone(),- SubagentRunOutcome {- task_id: task_key.task_id.clone(),- agent_id: agent_id.clone(),- output: output.clone(),- iterations: 1,- failure_cause: None,- elapsed: std::time::Duration::ZERO,- mode: crate::agent::subagent_host::SubagentMode::Typed,- status,- final_history: Vec::new(),- usage: SubagentUsage::default(),- artifact_paths: Vec::new(),- persistence_disposition: tinyagents_orchestration::subagent::SubagentPersistenceDisposition::TerminalInserted,- },- );- let mut neutral = SubagentOutcome::cancelled(task_key.task_id.clone());- neutral.output = output;- neutral- .extensions- .insert("agent_id".into(), serde_json::Value::String(agent_id));- neutral- .extensions- .insert("iterations".into(), serde_json::Value::Number(1.into()));- neutral.status = if cancelled {- SubagentOutcomeKind::Cancelled- } else if tool_result.is_error {- SubagentOutcomeKind::Incomplete(SubagentIncomplete::new(- "configured delegate reported failure",- ))- } else {- SubagentOutcomeKind::Completed- };- self.configured_tool_result- .lock()- .unwrap_or_else(|p| p.into_inner())- .insert(task_key, tool_result);- Ok(neutral)- }- (Err(error), _) => {- self.failures- .lock()- .unwrap_or_else(|p| p.into_inner())- .insert(task_key, SubagentRunError::Provider(error));- Err(SubagentError::Execution(- "configured delegate execution failed".into(),- ))- }- }- }}}}diff --git a/crates/openhuman-core/src/agent/tinyagents/tool_registration_tests.rs b/crates/openhuman-core/src/agent/tinyagents/tool_registration_tests.rsindex aece9c8e55..09e307dc82 100644--- a/crates/openhuman-core/src/agent/tinyagents/tool_registration_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/tool_registration_tests.rs@@ -103,7 +103,7 @@ impl Tool for NamedTopologyTool {}#[test]-fn capability_diagnostics_only_projects_live_delegation_graph() {+fn capability_diagnostics_omit_retired_graphs() {let names = ["agent_teams:member","delegation",@@ -121,7 +121,7 @@ fn capability_diagnostics_only_projects_live_delegation_graph() {.iter().map(|diagnostic| diagnostic.name.as_str()).collect();- assert_eq!(reused_names, vec!["delegation"]);+ assert!(reused_names.is_empty(), "retired graph diagnostics: {reused_names:?}");}#[tokio::test]diff --git a/crates/openhuman-core/src/agent_runs/schemas_tests.rs b/crates/openhuman-core/src/agent_runs/schemas_tests.rsindex 2841e52aee..3550f7ac72 100644--- a/crates/openhuman-core/src/agent_runs/schemas_tests.rs+++ b/crates/openhuman-core/src/agent_runs/schemas_tests.rs@@ -80,7 +80,7 @@ fn deserialize_params_and_helpers_cover_success_and_failure_paths() {#[tokio::test]-async fn registry_snapshot_omits_retired_graphs_and_keeps_delegation() {+async fn registry_snapshot_omits_retired_graphs() {let result = handle_registry_snapshot(DispatchCtx::process_default(), Map::new()).await.expect("registry snapshot is available");@@ -92,7 +92,10 @@ async fn registry_snapshot_omits_retired_graphs_and_keeps_delegation() {.iter().filter_map(|component| component.get("id").and_then(Value::as_str)).collect();- assert!(ids.contains(&"delegation"), "snapshot ids: {ids:?}");+ assert!(+ !ids.contains(&"delegation"),+ "snapshot includes the retired delegation graph: {ids:?}"+ );assert!(!ids.iter().any(|id| id.starts_with("agent_teams:")),"snapshot includes a retired team graph: {ids:?}"diff --git a/crates/openhuman-core/src/tools/ops.rs b/crates/openhuman-core/src/tools/ops.rsindex b5d15c25a5..08311c2618 100644--- a/crates/openhuman-core/src/tools/ops.rs+++ b/crates/openhuman-core/src/tools/ops.rs@@ -433,13 +433,6 @@ pub fn all_tools_with_runtime(Some(crate::tools::sources::ANCHOR_AFTER_SEARCH),));- // Keep the hosted-tool placement stable for registered sources that still- // use the former post-delegate slot.- tools.extend(crate::tools::sources::build_registered_tool_sources(- &source_ctx,- Some(crate::tools::sources::ANCHOR_AFTER_DELEGATE),- ));-// Hosting tools — deploy a workspace directory through the compiled// TinyHosts module. Registered only once a credential// actually resolves (`[hosting].api_key`, else the provider's environment@@ -472,6 +465,13 @@ pub fn all_tools_with_runtime(// Image metadata is always available for user-provided images.tools.push(Box::new(ImageInfoTool::new(security.clone())));+ // Keep hosted tools using the former post-delegate slot in their stable+ // catalogue position after image metadata and before Composio.+ tools.extend(crate::tools::sources::build_registered_tool_sources(+ &source_ctx,+ Some(crate::tools::sources::ANCHOR_AFTER_DELEGATE),+ ));+let composio_tools = crate::integrations::composio::all_composio_agent_tools(root_config);if composio_tools.is_empty() {tracing::debug!("[integrations] composio unavailable — skipping");diff --git a/crates/openhuman-core/src/tools/sources_tests.rs b/crates/openhuman-core/src/tools/sources_tests.rsindex 66cf32f561..09bee1e804 100644--- a/crates/openhuman-core/src/tools/sources_tests.rs+++ b/crates/openhuman-core/src/tools/sources_tests.rs@@ -118,8 +118,8 @@ fn unregistering_a_source_removes_its_tools() {fn anchored_sources_sit_where_the_catalogue_always_listed_them() {// The pre-refactor catalogue built a host's media / file-storage tools// right after the search tools (before hosting, web3 and image_info) and- // its place / market-data tools right after the delegation tool, ahead of- // the Composio tools; the order is a prompt-cache input.+ // its place / market-data tools right after image_info, ahead of the+ // Composio tools; the order is a prompt-cache input.let tmp = TempDir::new().unwrap();let anchor_tools = |names: &[&str]| -> Vec<Box<dyn Tool>> {names@@ -172,8 +172,8 @@ fn anchored_sources_sit_where_the_catalogue_always_listed_them() {// hosting/web3, and follow the built-ins that precede the search tools.assert!(pos("file_read") < pos("anchor_fake_search_a"));assert!(pos("anchor_fake_search_b") < pos("image_info"));- // End sources, and sources with an unknown anchor, trail every built-in- // and keep registration order.+ // The post-image-info anchor precedes Composio, while end sources and+ // sources with an unknown anchor trail every built-in.assert!(pos("image_info") < pos("anchor_fake_delegate"));assert!(pos("anchor_fake_delegate") < pos("anchor_fake_end"));assert!(pos("anchor_fake_end") < pos("anchor_fake_unknown"));diff --git a/tests/raw_coverage/agent_orchestration_e2e.rs b/tests/raw_coverage/agent_orchestration_e2e.rsindex cd96d60fc8..4b510b057b 100644--- a/tests/raw_coverage/agent_orchestration_e2e.rs+++ b/tests/raw_coverage/agent_orchestration_e2e.rs@@ -222,3 +222,48 @@ fn str_at<'a>(value: &'a Value, pointer: &str) -> &'a str {.unwrap_or_else(|| panic!("expected a string at {pointer} in {value}"))}+// ── subagent: cancel / steer ────────────────────────────────────────────────++/// The background-tasks drawer's Cancel and steer controls. Both answer+/// **structurally** for a task that is not running rather than erroring — the+/// drawer's row may be stale, and a stale row must not raise. `steer` goes+/// further and says *why* it did nothing.+#[tokio::test]+async fn subagent_steer_honours_and_defaults_the_queue_mode() {+ let _lock = env_lock_async().await;+ let h = setup().await;++ let collect = h+ .ok(+ 3504,+ "openhuman.subagent_steer",+ json!({+ "taskId": "sub-not-running",+ "message": "note this for later",+ "mode": "collect",+ }),+ )+ .await;+ assert_eq!(+ collect.get("mode").and_then(Value::as_str),+ Some("collect"),+ "an explicit queue mode is honoured and echoed: {collect}"+ );++ // An unrecognised mode falls back to steer rather than erroring.+ let bogus_mode = h+ .ok(+ 3505,+ "openhuman.subagent_steer",+ json!({ "taskId": "sub-not-running", "message": "hi", "mode": "teleport" }),+ )+ .await;+ assert_eq!(+ bogus_mode.get("mode").and_then(Value::as_str),+ Some("steer"),+ "an unknown mode degrades to the default: {bogus_mode}"+ );++ h.join.abort();+}+