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
feat(orchestration): condition async sub-agent guidance on parent fleet tools
Steven Enamakel85341739ec70
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 a54240eabd..9a57aac140 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@@ -5,6 +5,7 @@//! events and, when possible, persisted in the child worker thread.use crate::agent::harness::definition::AgentDefinitionRegistry;+use crate::agent::orchestration::fleet_tools::FleetToolSet;use crate::agent::messages::ChatMessage;use crate::agent::orchestration::running_subagents::{self, SubagentStatus};use crate::agent::orchestration::subagent_sessions::{@@ -196,15 +197,29 @@ impl SpawnAsyncSubagentTool {include!("spawn_async_subagent_execute.rs");/// Format the user-facing acceptance text around a structured async sub-agent reference.-fn format_async_subagent_accepted(agent_id: &str, payload_json: &str) -> String {+///+/// The wording follows what the parent can actually do: a parent without+/// `wait_subagent` (the orchestrator, #5701) is told the result arrives on its+/// own and not to poll, instead of being invited to "wait for completion".+fn format_async_subagent_accepted(agent_id: &str, payload_json: &str, fleet: &FleetToolSet) -> String {+ let guidance = if fleet.can_wait() {+ "Use the structured reference below to send more input, wait for completion, or perform a short timeout tick to check status. If the user does not need the result now, continue without blocking."+ } else {+ "Its result is delivered to you automatically on a later turn — you cannot and need not wait or poll for it (no shell/sleep, no fake status checks). Reply to the user now with what you know, say the result is on its way, and continue. The structured reference below lists the only follow-up tools you have for this worker."+ };format!(- "Accepted async sub-agent `{agent_id}`. Use the structured reference below to send more input, \- wait for completion, or perform a short timeout tick to check status. If the user does not need \- the result now, continue without blocking.\n\n[async_subagent_ref]\n{payload_json}\n[/async_subagent_ref]"+ "Accepted async sub-agent `{agent_id}`. {guidance}++[async_subagent_ref]+{payload_json}+[/async_subagent_ref]")}-/// Build the machine-readable reference the orchestrator uses to steer, wait, or poll a worker.+/// Build the machine-readable reference the orchestrator uses to follow up on a worker.+///+/// Only tools in `fleet` are offered: an instruction naming a tool the parent+/// cannot see costs an iteration of confused reasoning per delegation.fn async_subagent_ref_payload(task_id: &str,subagent_session_id: &str,@@ -213,7 +228,101 @@ fn async_subagent_ref_payload(reused: bool,reuse_decision: &str,status: &str,+ fleet: &FleetToolSet,) -> serde_json::Value {+ let mut instructions = serde_json::Map::new();+ let mut next_actions: Vec<String> = Vec::new();++ if fleet.has("steer_subagent") {+ instructions.insert(+ "send_message".into(),+ json!({+ "tool": "steer_subagent",+ "description": "Send additional instructions or context to this running async sub-agent.",+ "arguments": {+ "subagent_session_id": subagent_session_id,+ "message": "<message>",+ "mode": "steer"+ }+ }),+ );+ next_actions.push("call steer_subagent to send more input".into());+ }+ if fleet.has("wait_subagent") {+ instructions.insert(+ "wait".into(),+ json!({+ "tool": "wait_subagent",+ "description": "Block until the async sub-agent finishes, up to the timeout.",+ "arguments": { "subagent_session_id": subagent_session_id, "timeout_secs": 120 }+ }),+ );+ instructions.insert(+ "timeout_tick".into(),+ json!({+ "tool": "wait_subagent",+ "description": "Perform a short status tick without committing the parent to a long wait.",+ "arguments": { "subagent_session_id": subagent_session_id, "timeout_secs": 1 }+ }),+ );+ next_actions.push("call wait_subagent with timeout_secs to collect the result".into());+ next_actions.push("call wait_subagent with timeout_secs=1 as a timeout tick/status check".into());+ let reminder = format!(+ "Check async sub-agent {agent_id} status with wait_subagent using subagent_session_id {subagent_session_id}."+ );+ if fleet.has("wait") {+ instructions.insert(+ "delayed_tick".into(),+ json!({+ "tool": "wait",+ "description": "Trigger a delayed callback before checking this async sub-agent again.",+ "arguments": { "duration_secs": 30, "message": reminder }+ }),+ );+ }+ if fleet.has("wait_loop") {+ instructions.insert(+ "delayed_loop".into(),+ json!({+ "tool": "wait_loop",+ "description": "Trigger repeatable delayed callbacks while this async sub-agent is still relevant.",+ "arguments": {+ "duration_secs": 30,+ "message": reminder,+ "loop_key": subagent_session_id,+ "iteration": 1+ }+ }),+ );+ }+ if fleet.has("wait") || fleet.has("wait_loop") {+ next_actions.push(+ "call wait or wait_loop with the returned message to trigger a delayed status check".into(),+ );+ }+ }+ if fleet.has("continue_subagent") {+ instructions.insert(+ "answer_or_resume".into(),+ json!({+ "tool": "continue_subagent",+ "description": "Answer this worker if it pauses on ask_user_clarification (awaiting_user), or resume it later with a follow-up that keeps its context.",+ "arguments": { "subagent_session_id": subagent_session_id, "message": "<answer or follow-up>" }+ }),+ );+ next_actions.push(+ "call continue_subagent only if this worker reports awaiting_user, or to resume it with a follow-up".into(),+ );+ }+ if fleet.has("list_subagents") {+ next_actions.push("call list_subagents to re-enumerate your workers if this reference scrolls out of context".into());+ }+ next_actions.push(if fleet.can_wait() {+ "continue without waiting when the current user reply does not depend on the result".into()+ } else {+ "continue now: the result is delivered to you automatically on a later turn; never poll for it".into()+ });+json!({"task_id": task_id,"taskId": task_id,@@ -228,58 +337,9 @@ fn async_subagent_ref_payload("reused": reused,"reuse_decision": reuse_decision,"reuseDecision": reuse_decision,- "instructions": {- "send_message": {- "tool": "steer_subagent",- "description": "Send additional instructions or context to this running async sub-agent.",- "arguments": {- "subagent_session_id": subagent_session_id,- "message": "<message>",- "mode": "steer"- }- },- "wait": {- "tool": "wait_subagent",- "description": "Block until the async sub-agent finishes, up to the timeout.",- "arguments": {- "subagent_session_id": subagent_session_id,- "timeout_secs": 120- }- },- "timeout_tick": {- "tool": "wait_subagent",- "description": "Perform a short status tick without committing the parent to a long wait.",- "arguments": {- "subagent_session_id": subagent_session_id,- "timeout_secs": 1- }- },- "delayed_tick": {- "tool": "wait",- "description": "Trigger a delayed callback before checking this async sub-agent again.",- "arguments": {- "duration_secs": 30,- "message": format!("Check async sub-agent {agent_id} status with wait_subagent using subagent_session_id {subagent_session_id}.")- }- },- "delayed_loop": {- "tool": "wait_loop",- "description": "Trigger repeatable delayed callbacks while this async sub-agent is still relevant.",- "arguments": {- "duration_secs": 30,- "message": format!("Check async sub-agent {agent_id} status with wait_subagent using subagent_session_id {subagent_session_id}."),- "loop_key": subagent_session_id,- "iteration": 1- }- }- },- "next_actions": [- "call steer_subagent to send more input",- "call wait_subagent with timeout_secs to collect the result",- "call wait_subagent with timeout_secs=1 as a timeout tick/status check",- "call wait or wait_loop with the returned message to trigger a delayed status check",- "continue without waiting when the current user reply does not depend on the result"- ]+ "result_delivery": "automatic",+ "instructions": instructions,+ "next_actions": next_actions})}diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_execute.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_execute.rsindex 4fde0874e7..2ad65dbae3 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_execute.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_execute.rs@@ -92,6 +92,10 @@ impl SpawnAsyncSubagentTool {}};+ // The follow-up vocabulary offered back to the parent is limited to+ // the fleet tools its own definition exposes (see `fleet_tools`).+ let fleet = FleetToolSet::for_parent(&parent.agent_definition_id);+if !parent.allowed_subagent_ids.contains(&definition.id) {log::warn!("[spawn_async_subagent] blocked subagent outside allowlist parent={} requested={} allowed={:?}",@@ -256,11 +260,18 @@ impl SpawnAsyncSubagentTool {true,reuse_decision.as_str(),"running",+ &fleet,);+ let follow_up = if fleet.can_wait() {+ "Use the structured reference below to send more input, wait, or perform a short timeout tick."+ } else {+ "Its result is delivered to you automatically on a later turn; do not wait or poll for it."+ };return Ok(ToolResult::success(format!("Continued reusable async sub-agent `{}`. It is already running and will pick up the new instruction at its next step. \- Use the structured reference below to send more input, wait, or perform a short timeout tick.\n\n[async_subagent_ref]\n{}\n[/async_subagent_ref]",+ {}\n\n[async_subagent_ref]\n{}\n[/async_subagent_ref]",payload["agent_id"].as_str().unwrap_or("subagent"),+ follow_up,serde_json::to_string(&payload).unwrap_or_else(|_| "{}".to_string()))));@@ -785,6 +796,7 @@ impl SpawnAsyncSubagentTool {reusable.is_some(),reuse_decision.as_str(),"running",+ &fleet,);let payload_json = match serde_json::to_string(&payload) {Ok(serialized) => {