Skip to content

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

refactor(orchestration): trim dispatch outcomes to shared helpers

Steven Enamakelae5b6d922c3d
diff --git a/crates/openhuman-core/src/agent/orchestration/tools.rs b/crates/openhuman-core/src/agent/orchestration/tools.rs
index ef0c955aa0..b9c48f4a95 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools.rs
@@ -2,6 +2,8 @@
#[path = "tools/awaiting_user.rs"]
pub(crate) mod awaiting_user;
+#[path = "tools/dispatch_outcomes.rs"]
+mod dispatch;
#[path = "tools/spawn_subagent_surface.rs"]
mod spawn_subagent;
#[path = "tools/subagent_abort_report.rs"]
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 dce7011e39..8240626e03 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/dispatch_outcomes.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/dispatch_outcomes.rs
@@ -1,44 +1,11 @@
-//! Pure result mapping and framing for synchronous delegation dispatch.
-
-use super::DispatchMode;
-use tinytools::ToolResult;
-
-pub(super) fn awaiting_outcome_to_tool_result(
- outcome: &crate::agent::subagent_host::SubagentRunOutcome,
- question: &str,
- checkpointed: bool,
-) -> ToolResult {
- if !checkpointed {
- let question_json = serde_json::to_string(question)
- .unwrap_or_else(|_| "\"<unserializable question>\"".into());
- return ToolResult::error(format!(
- "The sub-agent `{}` paused to ask a question, but its state could not be saved and this delegation has no durable session to fall back on, so it cannot be resumed. Its progress is lost. Tell the user what it was asking — {} — and that the delegation has to be started again; do NOT call continue_subagent with task_id `{}`, there is nothing for it to resume.",
- outcome.agent_id, question_json, outcome.task_id
- ));
- }
- ToolResult::success(super::super::awaiting_user::awaiting_user_envelope(
- &outcome.task_id,
- &outcome.agent_id,
- None,
- question,
- checkpointed,
- ))
-}
-
-pub(super) fn format_subagent_failure(tool_name: &str, message: &str) -> String {
- format!(
- "{tool_name} failed and did not complete — no work was performed and no results were produced. Do NOT treat this as success or fabricate an output; report the failure to the user. Error: {message}"
- )
-}
+//! Result helpers shared by the asynchronous spawn completion path.
pub(crate) fn is_unexecuted_tool_call_stub(output: &str) -> bool {
use tinytools_agent::dialect::{contains_tool_call_payload, strip_tool_calls_from_response};
if !contains_tool_call_payload(output) {
return false;
}
- if let Ok(serde_json::Value::Object(map)) =
- serde_json::from_str::<serde_json::Value>(output.trim())
- {
+ if let Ok(serde_json::Value::Object(map)) = serde_json::from_str(output.trim()) {
if map.contains_key("tool_calls") {
return true;
}
@@ -48,35 +15,6 @@ pub(crate) fn is_unexecuted_tool_call_stub(output: &str) -> bool {
.any(char::is_alphanumeric)
}
-const INLINE_RESULT_NOTE: &str = "\n\n[INLINE_RESULT] This delegation ran inline and is complete as returned — there is no sub-agent worker for it. Do NOT call wait_subagent, list_subagents or continue_subagent for this delegation.";
-const NO_WORKER_NOTE: &str = "\n\n[INLINE_RESULT] This delegation ran inline and registered no sub-agent worker, so there is nothing to collect: do NOT call wait_subagent, list_subagents or continue_subagent for it. Re-delegate with a corrected prompt instead.";
-
-pub(crate) fn with_inline_result_note(output: String, mode: DispatchMode) -> String {
- if mode == DispatchMode::Blocking {
- format!("{output}{INLINE_RESULT_NOTE}")
- } else {
- output
- }
-}
-
-pub(crate) fn incomplete_envelope(
- tool_name: &str,
- reason: &str,
- output: &str,
- mode: DispatchMode,
-) -> String {
- let envelope = format!(
- "[SUBAGENT_INCOMPLETE] the {tool_name} sub-agent {reason} and did not finish. Below is partial progress only — do NOT report it as done or re-run the identical delegation unchanged.\n\nPartial progress:\n{output}"
- );
- if mode == DispatchMode::Blocking {
- format!("{envelope}{NO_WORKER_NOTE}")
- } else {
- 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,
failure_cause: Option<tinyagents_harness::no_progress::ClassifiedStopCause>,
@@ -88,28 +26,3 @@ pub(crate) fn incomplete_stop(
),
)
}
-
-/// 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,
- failure_cause: Option<tinyagents_harness::no_progress::ClassifiedStopCause>,
- envelope: String,
-) -> ToolResult {
- let stop = crate::agent::session_host::stop_summary::stop_from_incomplete_with_cause(
- reason,
- failure_cause,
- );
- 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)
-}