Skip to content

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

feat(orchestration): add subagent continuation and dispatch outcome tracking

Steven Enamakel8e0db631a017
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/continue_subagent.rs b/crates/openhuman-core/src/agent/orchestration/tools/continue_subagent.rs
index a3e0368a6e..98a22a62ce 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/continue_subagent.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/continue_subagent.rs
@@ -598,12 +598,12 @@ impl ContinueSubagentTool {
worktree_path: None,
changed_files: Vec::new(),
dirty_status: None,
- stop: None,
+ stop: super::incomplete_stop(&reason),
})
.await;
}
}
- Ok(ToolResult::success(format!(
+ let envelope = format!(
"[SUBAGENT_INCOMPLETE]\n\
task_id: {}\n\
agent_id: {}\n\
@@ -614,7 +614,14 @@ impl ContinueSubagentTool {
report this as done; relay the partial result and the blocker to the \
user, or take a different approach.",
outcome.task_id, outcome.agent_id, outcome.output,
- )))
+ );
+ Ok(super::stopped_subagent_result(
+ "continue_subagent",
+ &outcome.agent_id,
+ &outcome.task_id,
+ &reason,
+ envelope,
+ ))
}
SubagentRunStatus::Cancelled => {
tracing::info!(
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs b/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs
index 148330c152..fe228bb560 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs
@@ -572,7 +572,7 @@ pub(crate) async fn dispatch_subagent_with_live_parent(
worktree_path: None,
changed_files: Vec::new(),
dirty_status: None,
- stop: None,
+ stop: incomplete_stop(&reason),
})
.await;
}
@@ -585,12 +585,13 @@ pub(crate) async fn dispatch_subagent_with_live_parent(
outcome.task_id,
outcome.iterations,
);
- Ok(ToolResult::success(incomplete_envelope(
+ Ok(stopped_subagent_result(
tool_name,
- reason,
- &outcome.output,
- mode,
- )))
+ &outcome.agent_id,
+ &outcome.task_id,
+ &reason,
+ incomplete_envelope(tool_name, &reason, &outcome.output, mode),
+ ))
}
SubagentRunStatus::Cancelled => {
log::info!(
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/dispatch_outcomes.rs b/crates/openhuman-core/src/agent/orchestration/tools/dispatch_outcomes.rs
index cfb07600b0..1015612399 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/dispatch_outcomes.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/dispatch_outcomes.rs
@@ -74,3 +74,32 @@ pub(crate) fn incomplete_envelope(
envelope
}
}
+
+/// How a sub-agent handed back as `Incomplete { reason }` was stopped
+/// (iteration cap or failure breaker), for its `SubagentCompleted` event.
+pub(crate) fn incomplete_stop(reason: &str) -> Option<crate::agent::turn_stop::TurnStop> {
+ Some(crate::agent::turn_stop::TurnStop::from_incomplete_reason(
+ reason,
+ ))
+}
+
+/// The parent's tool result for a sub-agent the harness stopped early: a
+/// **failure** carrying `envelope` (the actionable "did not finish" framing
+/// plus the stop summary and partial progress), so the parent's failure
+/// policy and its trace see the stop. It used to be a success the parent
+/// could narrate as done.
+pub(crate) fn stopped_subagent_result(
+ tool_name: &str,
+ agent_id: &str,
+ task_id: &str,
+ reason: &str,
+ envelope: String,
+) -> ToolResult {
+ let stop = crate::agent::turn_stop::TurnStop::from_incomplete_reason(reason);
+ log::debug!(
+ "[subagent] {tool_name} child stopped early agent_id={agent_id} task_id={task_id} \
+ {}; returning a failed tool result",
+ stop.status_message()
+ );
+ ToolResult::error(envelope)
+}
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.rs
index 4e05020954..27cae36c46 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
@@ -482,7 +482,7 @@ impl SpawnSubagentTool {
worktree_path: None,
changed_files: Vec::new(),
dirty_status: None,
- stop: None,
+ stop: super::incomplete_stop(&reason),
})
.await;
}
@@ -501,7 +501,13 @@ impl SpawnSubagentTool {
delegation unchanged.",
outcome.task_id, outcome.agent_id, outcome.output,
);
- Ok(ToolResult::success(envelope))
+ Ok(super::stopped_subagent_result(
+ "spawn_subagent",
+ &outcome.agent_id,
+ &outcome.task_id,
+ &reason,
+ envelope,
+ ))
}
SubagentRunStatus::Cancelled => {
tracing::info!(