Skip to content

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

feat(agent): project subagent list and wait results for tinyagents

Steven Enamakel0d4ca31de586
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/list_subagents.rs b/crates/openhuman-core/src/agent/orchestration/tools/list_subagents.rs
index af62611baf..9d1b3d48ba 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/list_subagents.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/list_subagents.rs
@@ -146,7 +146,7 @@ impl ListSubagentsTool {
}
}
-fn overlay_task_store_status(
+pub(crate) fn overlay_task_store_status(
summary: &mut DurableSubagentSessionSummary,
workspace_dir: &std::path::Path,
parent_session: &str,
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/wait_subagent.rs b/crates/openhuman-core/src/agent/orchestration/tools/wait_subagent.rs
index 36fad31d5f..5003a63309 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/wait_subagent.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/wait_subagent.rs
@@ -36,7 +36,7 @@ const MAX_TIMEOUT_SECS: u64 = 3600;
/// designed success into an `error` result. The repeated-failure breaker then
/// classifies "timed out" as transient, retries the identical call 8 times and
/// halts the turn — which is how a working coding sub-agent lost its work.
-fn requested_timeout_secs(args: &serde_json::Value) -> u64 {
+pub(crate) fn requested_timeout_secs(args: &serde_json::Value) -> u64 {
args.get("timeout_secs")
.and_then(|v| v.as_u64())
.unwrap_or(DEFAULT_TIMEOUT_SECS)
@@ -388,7 +388,7 @@ impl WaitSubagentTool {
}
/// Render a timeout/running wait response with a structured status payload.
-fn format_running_wait_message(
+pub(crate) fn format_running_wait_message(
reference: Option<&SubagentResumeRef>,
task_id: &str,
timeout_secs: u64,
@@ -409,7 +409,7 @@ fn format_running_wait_message(
}
/// Build the machine-readable wait status block returned to the orchestrator.
-fn wait_status_payload(
+pub(crate) fn wait_status_payload(
reference: Option<&SubagentResumeRef>,
task_id: &str,
status: &str,
diff --git a/crates/openhuman-core/src/agent/tinyagents/tool_registration.rs b/crates/openhuman-core/src/agent/tinyagents/tool_registration.rs
index 0e89b6587f..1d0d690f45 100644
--- a/crates/openhuman-core/src/agent/tinyagents/tool_registration.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/tool_registration.rs
@@ -7,6 +7,7 @@ use std::collections::HashSet;
use std::sync::Arc;
use tinyagents_graph::goals::GoalToolKind;
+use tinyagents_harness::context::RunContext;
use tinyagents_harness::tool::packs::USE_SKILL;
use tinyagents_harness::tool::{
CanonicalSharedToolAdapter, ToolDispatch, ToolExecScope, ToolExecution, ToolExecutionContext,
@@ -36,6 +37,258 @@ type ToolDispatchSelectorFn =
dyn Fn(&str, Arc<dyn tinytools::Tool>) -> Option<RegisteredToolDispatch> + Send + Sync;
type ToolDispatchSelector = Arc<ToolDispatchSelectorFn>;
+#[derive(Clone, Copy)]
+enum SubagentResultProjection {
+ List,
+ Wait,
+}
+
+struct ProjectedSubagentDispatch {
+ inner: RegisteredToolDispatch,
+ tool: Arc<dyn tinytools::Tool>,
+ projection: SubagentResultProjection,
+}
+
+#[async_trait::async_trait]
+impl ToolDispatch<(), OpenHumanRunContext> for ProjectedSubagentDispatch {
+ fn tool(&self) -> Arc<dyn tinytools::Tool> {
+ self.tool.clone()
+ }
+
+ fn output_origin(&self) -> tinyagents_harness::host::ContentOrigin {
+ self.inner.output_origin()
+ }
+
+ async fn execute(
+ &self,
+ state: &(),
+ call_id: tinyagents_harness::CallId,
+ arguments: serde_json::Value,
+ options: tinytools::ToolCallOptions,
+ parent: &RunContext<OpenHumanRunContext>,
+ ) -> anyhow::Result<tinytools::ToolResult> {
+ let result = self
+ .inner
+ .execute(state, call_id, arguments.clone(), options, parent)
+ .await?;
+ Ok(project_subagent_result(
+ self.projection,
+ result,
+ &arguments,
+ parent,
+ ))
+ }
+}
+
+fn project_subagent_result(
+ projection: SubagentResultProjection,
+ result: tinytools::ToolResult,
+ arguments: &serde_json::Value,
+ parent: &RunContext<OpenHumanRunContext>,
+) -> tinytools::ToolResult {
+ match projection {
+ SubagentResultProjection::List => project_list_subagents(result, parent),
+ SubagentResultProjection::Wait => project_wait_subagent(result, arguments, parent),
+ }
+}
+
+fn project_list_subagents(
+ result: tinytools::ToolResult,
+ parent: &RunContext<OpenHumanRunContext>,
+) -> tinytools::ToolResult {
+ use tinytools::{ToolContent, ToolResult};
+
+ if result.is_error {
+ return result;
+ }
+ let Some(ToolContent::Json { data }) = result.content.first() else {
+ return result;
+ };
+ let Some(rows) = data.as_array() else {
+ return result;
+ };
+ let Some(parent_ctx) = parent.data.parent.as_ref() else {
+ return result;
+ };
+ let mut summaries = Vec::new();
+ for row in rows
+ .iter()
+ .filter(|row| row.get("kind").and_then(serde_json::Value::as_str) == Some("session"))
+ {
+ let mut row = row.clone();
+ if let Some(object) = row.as_object_mut() {
+ object.remove("kind");
+ }
+ let Ok(mut summary) = serde_json::from_value::<
+ crate::agent::orchestration::subagent_sessions::DurableSubagentSessionSummary,
+ >(row) else {
+ continue;
+ };
+ crate::agent::orchestration::tools::list_subagents::overlay_task_store_status(
+ &mut summary,
+ &parent_ctx.workspace_dir,
+ &parent_ctx.session_id,
+ );
+ summaries.push(summary);
+ }
+ ToolResult::success(format!(
+ "[subagent_sessions]\n{}\n[/subagent_sessions]",
+ serde_json::to_string_pretty(&summaries).unwrap_or_else(|_| "[]".into())
+ ))
+}
+
+fn project_wait_subagent(
+ result: tinytools::ToolResult,
+ arguments: &serde_json::Value,
+ parent: &RunContext<OpenHumanRunContext>,
+) -> tinytools::ToolResult {
+ use tinyagents_orchestration::subagent::SubagentResumeRef;
+ use tinytools::{ToolContent, ToolResult};
+
+ if result.is_error {
+ return result;
+ }
+ let Some(ToolContent::Json { data }) = result.content.first() else {
+ return result;
+ };
+ let Some(object) = data.as_object() else {
+ return result;
+ };
+ let Some(parent_ctx) = parent.data.parent.as_ref() else {
+ return result;
+ };
+ let extensions = object
+ .get("extensions")
+ .and_then(serde_json::Value::as_object);
+ let task_id = extensions
+ .and_then(|values| values.get("task_id"))
+ .and_then(serde_json::Value::as_str)
+ .or_else(|| object.get("task_id").and_then(serde_json::Value::as_str))
+ .or_else(|| arguments.get("task_id").and_then(serde_json::Value::as_str))
+ .unwrap_or("")
+ .to_owned();
+ let agent_id = extensions
+ .and_then(|values| values.get("agent_id"))
+ .and_then(serde_json::Value::as_str)
+ .or_else(|| object.get("agent").and_then(serde_json::Value::as_str))
+ .unwrap_or("unknown")
+ .to_owned();
+ if task_id.is_empty() {
+ return result;
+ }
+ let parent_thread = parent.data.thread_id.as_deref();
+ let store = crate::agent::orchestration::subagent_sessions::SubagentSessionStore::new(
+ parent_ctx.workspace_dir.clone(),
+ );
+ let session_id = crate::agent::orchestration::subagent_sessions::list_for_parent(
+ &store,
+ &parent_ctx.session_id,
+ parent_thread,
+ )
+ .ok()
+ .and_then(|sessions| {
+ sessions
+ .into_iter()
+ .find(|session| session.current_task_id.as_deref() == Some(&task_id))
+ .map(|session| session.subagent_session_id)
+ });
+ let resume = SubagentResumeRef {
+ task_id: task_id.clone(),
+ agent_id: agent_id.clone(),
+ subagent_session_id: session_id,
+ };
+ let status = object
+ .get("status")
+ .and_then(serde_json::Value::as_str)
+ .unwrap_or("running");
+ let iterations = extensions
+ .and_then(|values| values.get("iterations"))
+ .and_then(serde_json::Value::as_u64)
+ .map(|value| value as usize);
+ let output = object
+ .get("output")
+ .and_then(serde_json::Value::as_str)
+ .unwrap_or_default();
+ let error = object
+ .get("error")
+ .and_then(serde_json::Value::as_str)
+ .unwrap_or("subagent execution failed");
+
+ match status {
+ "completed" => {
+ crate::agent::orchestration::background_completions::mark_collected(
+ &parent_ctx.workspace_dir,
+ &task_id,
+ );
+ let payload = crate::agent::orchestration::tools::wait_subagent::wait_status_payload(
+ Some(&resume),
+ &task_id,
+ "completed",
+ iterations,
+ None,
+ "synthesize the sub-agent output into the parent response",
+ );
+ ToolResult::success(format!(
+ "Sub-agent `{agent_id}` completed in {} iteration(s).\n\n[subagent_wait_result]\n{}\n[/subagent_wait_result]\n\n{output}",
+ iterations.unwrap_or_default(),
+ serde_json::to_string(&payload).unwrap_or_else(|_| "{}".into())
+ ))
+ }
+ "awaiting_input" | "awaiting_user" => {
+ let question = output;
+ let payload = crate::agent::orchestration::tools::wait_subagent::wait_status_payload(
+ Some(&resume),
+ &task_id,
+ "awaiting_user",
+ None,
+ Some(question),
+ "ask the user for the missing information, then call continue_subagent",
+ );
+ let mut message = format!(
+ "Sub-agent `{agent_id}` paused for clarification and did not finish: {question}\n\nIt cannot proceed unattended. Resume it with continue_subagent once you have an answer.\n\n[subagent_wait_result]\n{}\n[/subagent_wait_result]",
+ serde_json::to_string(&payload).unwrap_or_else(|_| "{}".into())
+ );
+ if let Some(session_id) = resume.subagent_session_id {
+ message.push_str("\n\n[subagent_resume_ref]\n");
+ message.push_str(
+ &serde_json::to_string(&serde_json::json!({
+ "task_id": task_id,
+ "agent_id": agent_id,
+ "subagent_session_id": session_id,
+ "tool": "continue_subagent"
+ }))
+ .unwrap_or_else(|_| "{}".into()),
+ );
+ message.push_str("\n[/subagent_resume_ref]");
+ }
+ ToolResult::success(message)
+ }
+ "failed" | "incomplete" | "cancelled" => {
+ let payload = crate::agent::orchestration::tools::wait_subagent::wait_status_payload(
+ Some(&resume),
+ &task_id,
+ "failed",
+ None,
+ Some(error),
+ "report the failure or retry with a corrected instruction",
+ );
+ ToolResult::error(format!(
+ "Sub-agent `{agent_id}` failed: {error}\n\n[subagent_wait_result]\n{}\n[/subagent_wait_result]",
+ serde_json::to_string(&payload).unwrap_or_else(|_| "{}".into())
+ ))
+ }
+ _ => ToolResult::success(
+ crate::agent::orchestration::tools::wait_subagent::format_running_wait_message(
+ Some(&resume),
+ &task_id,
+ crate::agent::orchestration::tools::wait_subagent::requested_timeout_secs(
+ arguments,
+ ),
+ ),
+ ),
+ }
+}
+
/// Typed-dispatch selection shared by the direct per-turn registration below
/// and by [`UseSkillDispatch`], which must resolve the SAME live-parent
/// dispatch for a packed archetype delegation (`create_image`, `do_crypto`,
@@ -224,30 +477,42 @@ fn subagent_control_dispatches(
};
let mut dispatches = std::collections::HashMap::new();
if let Some(dispatch) = make_jobs_alias("list_subagents", SubAgentJobAction::Query) {
- dispatches.insert("list_subagents".into(), dispatch);
+ dispatches.insert(
+ "list_subagents".into(),
+ Arc::new(ProjectedSubagentDispatch {
+ tool: dispatch.tool(),
+ inner: dispatch,
+ projection: SubagentResultProjection::List,
+ }) as RegisteredToolDispatch,
+ );
}
if let Some(adapter) = find_tool("wait_subagent") {
let parent_session = parent_session.clone();
+ let wait_dispatch: RegisteredToolDispatch = Arc::new(
+ SubAgentJobsTool::new(jobs.clone())
+ .with_tool_name("wait_subagent")
+ .with_description(adapter.description())
+ .with_parameters(adapter.parameters_schema())
+ .with_fixed_action(SubAgentJobAction::Await)
+ .with_identifier_fields("task_id", "subagent_session_id")
+ .with_await_timeout_field("timeout_secs", 120, 3600)
+ .with_required_identifier()
+ .with_metadata(
+ adapter.permission_level(),
+ adapter.scope(),
+ adapter.category(),
+ tinytools::ToolTimeout::Inherit,
+ )
+ .with_owner_scope(owner_scope.clone())
+ .with_sessions(store.clone(), move |_| parent_session.clone()),
+ );
dispatches.insert(
"wait_subagent".into(),
- Arc::new(
- SubAgentJobsTool::new(jobs.clone())
- .with_tool_name("wait_subagent")
- .with_description(adapter.description())
- .with_parameters(adapter.parameters_schema())
- .with_fixed_action(SubAgentJobAction::Await)
- .with_identifier_fields("task_id", "subagent_session_id")
- .with_await_timeout_field("timeout_secs", 120, 3600)
- .with_required_identifier()
- .with_metadata(
- adapter.permission_level(),
- adapter.scope(),
- adapter.category(),
- tinytools::ToolTimeout::Inherit,
- )
- .with_owner_scope(owner_scope.clone())
- .with_sessions(store.clone(), move |_| parent_session.clone()),
- ),
+ Arc::new(ProjectedSubagentDispatch {
+ tool: wait_dispatch.tool(),
+ inner: wait_dispatch,
+ projection: SubagentResultProjection::Wait,
+ }),
);
}
if let Some(adapter) = find_tool("close_subagent") {