Skip to content

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

refactor(tinyagents): delegate tool outcome classification to TinyAgents

Steven Enamakelcff33900acfe
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/tool_outcome_classifier.rs b/crates/openhuman-core/src/agent/tinyagents/host/tool_outcome_classifier.rs
index 449df07002..04e04e18e2 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/tool_outcome_classifier.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/tool_outcome_classifier.rs
@@ -1,81 +1,15 @@
-//! Host implementation of [`ToolOutcomeClassifier`] over OpenHuman's
-//! `tool_status` domain.
+//! OpenHuman's timeout-safety policy over TinyAgents' shared status classifier.
//!
-//! This is `docs/specs/plan-agents.md` Phase 4. The agent runtime knows a tool
-//! call returned; it does not know whether the thing that came back is a
-//! success, something to re-dispatch, or a dead end. OpenHuman already owns that
-//! judgement in [`crate::tool_status`], whose
-//! [`classify`](tinytools::status::classify) turns raw tool error
-//! text into a [`ClassifiedFailure`](tinytools::status::ClassifiedFailure)
-//! (a [`ToolFailureClass`] plus a user-facing category). This adapter is the one
-//! place that mapping is projected onto the crate's three-way
-//! [`OutcomeClass`].
-//!
-//! # Contract mismatches resolved here
-//!
-//! **1. `ClassifiedFailure::recoverable` is NOT the retryability signal.**
-//! The tempting one-liner is `if failure.recoverable { RetryableFailure }`. It
-//! is wrong. `recoverable` means `category == FailureCategory::Recoverable`, and
-//! [`ToolFailureClass::Unknown`] — *anything the heuristic could not classify* —
-//! sits in that category so the UI can offer "try again" copy. The crate's
-//! contract for [`OutcomeClass::RetryableFailure`] is much stronger: it is "an
-//! assertion by the host that repeating is acceptable", made without knowing
-//! whether the tool had side effects. An unclassified failure is precisely the
-//! case where OpenHuman does *not* know that. So this adapter branches on the
-//! **class**, not on `recoverable`, and only the three transient classes are
-//! called retryable.
-//!
-//! That is not a new policy invention — it is the split OpenHuman's own steering
-//! middleware already makes. `TinyAgents`' recoverable-failure headroom ladder
-//! (`middleware.rs`, issue #4463 part 4) gates on exactly
-//! `Timeout | ServiceUnavailable | ModelConnection` and lets everything else,
-//! `Unknown` included, fall through to the hard-failure path. Mapping `Unknown`
-//! to [`OutcomeClass::PermanentFailure`] keeps this seam consistent with that
-//! guard and matches the crate's own documented safe default
-//! (`ErrorFieldClassifier` classifies every error as permanent for the same
-//! side-effect reason).
-//!
-//! **2. `classify` wants a `timed_out` flag the runtime does not carry.**
-//! [`ToolResult`] has no "the executor stopped this at its deadline" bit, so the
-//! flag is derived the same way `TinyAgentsToolStatusMiddleware` derives it —
-//! sniffing `"timed out"` out of the combined failure text. Doing it identically
-//! is the point: the middleware and this classifier must not disagree about
-//! whether a call timed out.
-//!
-//! **3. Error text is canonical content.** [`ToolResult::content`] carries text
-//! and structured blocks while [`ToolResult::is_error`] says whether execution
-//! reported a failure. This adapter renders the canonical blocks, so a
-//! `[policy-denied]` marker is honoured wherever the tool put it and a user
-//! refusal can never be re-dispatched.
-//!
-//! **4. A timeout cannot be assumed safe to repeat.** `Timeout` is the one
-//! failure class where "the call failed" and "the call succeeded but the reply
-//! was lost" are indistinguishable from the outside. For a tool with an
-//! external effect — sending an email, moving money, running a shell command —
-//! re-dispatching a timed-out call can commit the effect a second time. The
-//! crate's `RetryableFailure` is an assertion that repeating is *acceptable*,
-//! so it may only be made about a tool the host has positively identified as
-//! side-effect free — declared through
-//! [`OpenHumanToolOutcomeClassifier::with_retry_safe_tools`] as an
-//! **allowlist**. An allowlist rather than the inverse, because
-//! `Tool::external_effect()` is arg-less: `ShellTool` and other raw
-//! tool classify their effect from *arguments* (`external_effect_with_args`)
-//! and leave the arg-less variant at the default `false`, so a denylist built
-//! from it would admit precisely the tools that must be excluded. Absent the
-//! allowlist, timeouts stay permanent — the safe direction, since a lost retry
-//! costs an iteration while a duplicated payment cannot be undone.
-//!
-//! The adapter is pure, as the trait requires: no I/O, no interior mutability,
-//! same answer for the same `(name, result)` every time.
+//! TinyAgents owns error extraction, classification, policy-marker precedence,
+//! and the mapping to [`OutcomeClass`]. OpenHuman supplies only the current
+//! host's allowlist of tool names that are safe to repeat after a timeout.
-use std::borrow::Cow;
use std::collections::HashSet;
use std::sync::Arc;
use tinyagents_harness::host::{OutcomeClass, ToolOutcomeClassifier, ToolStatusClassifier};
use tinytools::ToolResult;
-use tinytools::status::ToolFailureClass;
/// OpenHuman's [`ToolOutcomeClassifier`], backed by
/// [`tinytools::status::classify`].
@@ -97,9 +31,7 @@ pub struct OpenHumanToolOutcomeClassifier {
/// have called a timed-out shell write retryable. Anything not named here
/// is treated as potentially effectful.
///
- /// Only consulted for [`ToolFailureClass::Timeout`], where "the call failed"
- /// and "the reply was lost after the effect committed" are
- /// indistinguishable from the outside. See [`Self::class_of`].
+ /// Only consulted for timeouts, where repeating may duplicate an effect.
retry_safe_tools: Option<Arc<HashSet<String>>>,
}
@@ -128,16 +60,6 @@ impl OpenHumanToolOutcomeClassifier {
self
}
- /// Whether repeating `name` after a timeout is safe.
- ///
- /// Membership is the only way to be safe: an unlisted tool — unknown,
- /// arg-sensitive, or simply new — is treated as potentially effectful.
- fn timeout_is_retry_safe(&self, name: &str) -> bool {
- self.retry_safe_tools
- .as_deref()
- .is_some_and(|safe| safe.contains(name))
- }
-
}
impl ToolOutcomeClassifier for OpenHumanToolOutcomeClassifier {
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/tool_outcome_classifier_tests.rs b/crates/openhuman-core/src/agent/tinyagents/host/tool_outcome_classifier_tests.rs
index 06b6a5bb89..f347f51407 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/tool_outcome_classifier_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/tool_outcome_classifier_tests.rs
@@ -84,75 +84,6 @@ fn connection_failures_stay_retryable_for_external_effect_tools() {
}
}
-// ── class → OutcomeClass mapping (exhaustive) ─────────────────────────────
-
-#[test]
-fn every_failure_class_maps_as_documented() {
- use OutcomeClass::*;
- use ToolFailureClass::*;
- // `retry_safe = true` isolates the class mapping from the
- // external-effect policy, which has its own tests below.
- for (class, want) in [
- (Timeout, RetryableFailure),
- (ServiceUnavailable, RetryableFailure),
- (ModelConnection, RetryableFailure),
- (MissingPermission, PermanentFailure),
- (MissingApp, PermanentFailure),
- (BadCredentials, PermanentFailure),
- (ToolFailureClass::BlockedByPolicy, PermanentFailure),
- (Denied, PermanentFailure),
- (ApprovalExpired, PermanentFailure),
- (Unknown, PermanentFailure),
- ] {
- assert_eq!(
- OpenHumanToolOutcomeClassifier::class_of(class, true),
- want,
- "mapping {class:?}"
- );
- }
-}
-
-#[test]
-fn no_failure_class_ever_maps_to_success() {
- // `class_of` is only reached when `error` is set, so a mapping that
- // produced `Success` would erase a real failure from the transcript.
- for class in [
- ToolFailureClass::Timeout,
- ToolFailureClass::ServiceUnavailable,
- ToolFailureClass::ModelConnection,
- ToolFailureClass::MissingPermission,
- ToolFailureClass::MissingApp,
- ToolFailureClass::BadCredentials,
- ToolFailureClass::BlockedByPolicy,
- ToolFailureClass::Denied,
- ToolFailureClass::ApprovalExpired,
- ToolFailureClass::NotFound,
- ToolFailureClass::Unsupported,
- ToolFailureClass::Unknown,
- ] {
- assert!(
- OpenHumanToolOutcomeClassifier::class_of(class, true).is_failure(),
- "{class:?} must stay a failure"
- );
- }
-}
-
-#[test]
-fn recoverable_flag_is_deliberately_not_the_retry_signal() {
- // `Unknown` is `FailureCategory::Recoverable` in the domain, yet must be
- // permanent here — this divergence is the whole point of the adapter and
- // regressing to `if failure.recoverable` would resurrect it.
- let unknown = tinytools::status::describe(ToolFailureClass::Unknown);
- assert!(
- unknown.recoverable,
- "domain still calls Unknown recoverable"
- );
- assert_eq!(
- OpenHumanToolOutcomeClassifier::class_of(ToolFailureClass::Unknown, true),
- OutcomeClass::PermanentFailure
- );
-}
-
// ── end-to-end over real error text ───────────────────────────────────────
#[test]
@@ -227,7 +158,7 @@ fn an_expired_approval_is_permanent_despite_saying_timed_out() {
assert_eq!(outcome_of(&text), OutcomeClass::PermanentFailure);
}
-// ── failure-text assembly ─────────────────────────────────────────────────
+// ── owner classification and host policy ──────────────────────────────────
#[test]
fn markers_are_honoured_when_they_land_in_content_not_error() {
@@ -241,33 +172,6 @@ fn markers_are_honoured_when_they_land_in_content_not_error() {
);
}
-#[test]
-fn failure_text_preserves_single_and_combined_sources() {
- let only_error = result(Some("boom"), "");
- assert_eq!(
- OpenHumanToolOutcomeClassifier::failure_text(&only_error),
- "boom"
- );
-
- let duplicated = result(Some("boom"), "boom");
- assert_eq!(
- OpenHumanToolOutcomeClassifier::failure_text(&duplicated),
- "boom"
- );
-
- let only_content = result(Some(""), "boom");
- assert_eq!(
- OpenHumanToolOutcomeClassifier::failure_text(&only_content),
- "boom"
- );
-
- let both = result(Some("boom"), "context");
- assert_eq!(
- OpenHumanToolOutcomeClassifier::failure_text(&both),
- "context"
- );
-}
-
#[test]
fn an_error_present_but_empty_is_still_a_failure() {
// `Some("")` is a tool reporting failure without a message. Matching the