Skip to content

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

chore: files changed crates/openhuman-core/src/tools/impl/browser/browser.rs,crates/openhuman-core/s

Steven Enamakelaf5d1743253b
diff --git a/crates/openhuman-core/src/tools/impl/browser/browser.rs b/crates/openhuman-core/src/tools/impl/browser/browser.rs
index ab68e1186a..8d2c827756 100644
--- a/crates/openhuman-core/src/tools/impl/browser/browser.rs
+++ b/crates/openhuman-core/src/tools/impl/browser/browser.rs
@@ -30,7 +30,9 @@ use std::{
sync::{Arc, Mutex as StdMutex},
time::Instant,
};
-use task_actions::{approve_task_action, host_hint, parse_action, required, task_inputs};
+use task_actions::{
+ approve_task_action, host_hint, parse_action, required, task_inputs, task_outcome,
+};
use tinycomputer_bus::agent::{ContinueTaskRequest, TaskId, TaskStatus, TaskView};
use tinycomputer_bus::browser::{
Action, DownloadState, DownloadWaitRequest, NavigateRequest, ReadRequest, SessionId,
@@ -321,11 +323,18 @@ impl BrowserTool {
Ok(serde_json::to_value(view)?)
}
- /// Report a task view; a `needs_approval` pause is held with a one-use
- /// token that only `confirm_pending` (through the host gate) can spend.
+ /// Report a task view as the tool's outcome ([`task_outcome`]): a task
+ /// that failed or was cancelled under the caller is an error.
async fn report(&self, view: TaskView) -> anyhow::Result<Value> {
- let mut output = serde_json::to_value(&view)?;
- if let Some(hint) = host_hint(&view) {
+ let output = self.describe(&view).await?;
+ task_outcome(&view, output)
+ }
+
+ /// Render a task view; a `needs_approval` pause is held with a one-use
+ /// token that only `confirm_pending` (through the host gate) can spend.
+ async fn describe(&self, view: &TaskView) -> anyhow::Result<Value> {
+ let mut output = serde_json::to_value(view)?;
+ if let Some(hint) = host_hint(view) {
output["host_hint"] = json!(hint);
}
if let TaskStatus::NeedsApproval { action, target, .. } = &view.status {
@@ -369,11 +378,11 @@ impl BrowserTool {
)
.await
.map_err(anyhow::Error::msg)?;
- let mut output = self.report(view).await?;
+ let mut output = self.describe(&view).await?;
if !approved {
output["approval"] = json!("denied by the host");
}
- Ok(output)
+ task_outcome(&view, output)
}
/// `origin` is the turn this call runs under; it decides only whether an
diff --git a/crates/openhuman-core/src/tools/impl/browser/browser_task_actions.rs b/crates/openhuman-core/src/tools/impl/browser/browser_task_actions.rs
index b9d37cd73a..d47f9df626 100644
--- a/crates/openhuman-core/src/tools/impl/browser/browser_task_actions.rs
+++ b/crates/openhuman-core/src/tools/impl/browser/browser_task_actions.rs
@@ -23,6 +23,44 @@ pub(super) fn host_hint(view: &TaskView) -> Option<&'static str> {
}
}
+/// A task report as the tool's outcome: a task that failed, or was cancelled
+/// under the caller, is an error carrying its reason, hint and full report,
+/// so the turn, the failure breaker and the tool status all see the task did
+/// not finish. Every other state (running, paused for a person, input or
+/// approval, a checkpoint, done) is a success the model acts on.
+pub(super) fn task_outcome(view: &TaskView, output: Value) -> anyhow::Result<Value> {
+ let marker = crate::tools::status::TASK_FAILED_MARKER;
+ let headline = match &view.status {
+ TaskStatus::Failed {
+ step, reason, hint, ..
+ } => {
+ let at = step.map_or_else(
+ || " before any step ran".to_owned(),
+ |step| format!(" at step {step}"),
+ );
+ let mut line = format!("{marker} Browser task failed{at}: {}", reason.trim());
+ if !hint.trim().is_empty() {
+ line.push_str(&format!(" Hint: {}", hint.trim()));
+ }
+ if let Some(host) = output["host_hint"].as_str() {
+ line.push_str(&format!(" {host}"));
+ }
+ line
+ }
+ TaskStatus::Cancelled => format!(
+ "{marker} Browser task was cancelled before it finished: {}",
+ view.summary.trim()
+ ),
+ _ => return Ok(output),
+ };
+ tracing::debug!(
+ task_id = %view.id,
+ "[tool.browser] task ended without finishing; reporting a tool error"
+ );
+ let report = serde_json::to_string_pretty(&output).unwrap_or_default();
+ Err(anyhow::anyhow!("{headline}\n\n{report}"))
+}
+
pub(super) fn task_inputs(args: &Value) -> anyhow::Result<BTreeMap<String, String>> {
args["inputs"].as_object().map_or_else(
|| Ok(BTreeMap::new()),