Skip to content

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

feat(tinyagents): add classified cause to turn execution flow

Steven Enamakel16a425d5da08
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs b/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
index 8483c5f23e..72c94c6325 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
@@ -500,6 +500,7 @@ async fn drive_turn(
let candidate_names = prepared.tools().plan.candidates.clone();
let TurnWiring {
halt_summary,
+ classified_cause,
wrap_up_fired,
compression_mw,
prompt_cache_guard,
@@ -685,6 +686,7 @@ async fn drive_turn(
Some(bridge),
early_exit,
&halt_summary,
+ classified_cause(),
&wrap_up_fired,
run_instance_id,
&tool_outcome_sink,
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs b/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs
index c4cfd879cd..6389878c24 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs
@@ -101,6 +101,11 @@ pub(super) struct TurnMiddlewareInputs {
pub(super) struct TurnWiring {
/// Root-cause summary recorded by the repeated-tool-failure breaker.
pub(super) halt_summary: HaltSummarySlot,
+ /// Reads the repeated-failure latch's typed cause while it still owns the
+ /// halt summary. `AgentRun.failure_cause` covers the harness guard path.
+ pub(super) classified_cause: Arc<
+ dyn Fn() -> Option<tinyagents_harness::no_progress::ClassifiedStopCause> + Send + Sync,
+ >,
/// Set by `FinalCallWrapUpMiddleware` when it turned the last permitted
/// model call into the turn's conclusion (issue #6014). `None` when the
/// middleware is not installed (a run that does not pause at its cap).
@@ -591,8 +596,12 @@ pub(super) fn install_turn_middleware(
// compacted, trimmed or persisted (`memory::lifecycle::prefetch::pre_turn`).
harness.push_middleware(Arc::new(middleware::memory_pack::memory_pack_middleware()));
+ let classified_cause = repeated_failure
+ .map(|mw| Arc::new(move || mw.current_classified_cause()) as _)
+ .unwrap_or_else(|| Arc::new(|| None));
TurnWiring {
halt_summary,
+ classified_cause,
wrap_up_fired,
compression_mw,
prompt_cache_guard,
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_run_finalize.rs b/crates/openhuman-core/src/agent/tinyagents/turn_run_finalize.rs
index 7e880d58e3..a274f4aace 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_run_finalize.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_run_finalize.rs
@@ -41,6 +41,7 @@ pub(super) async fn finalize_turn_outcome(
bridge: Option<Arc<OpenhumanEventBridge>>,
early_exit: Option<tinyagents_harness::tool::EarlyExit>,
halt_summary: &HaltSummarySlot,
+ classified_cause: Option<tinyagents_harness::no_progress::ClassifiedStopCause>,
wrap_up_fired: &Option<Arc<tinyagents_harness::middleware::FinalCallWrapUpMiddleware>>,
run_instance_id: u64,
tool_outcome_sink: &ToolOutcomeSink,
@@ -163,7 +164,7 @@ pub(super) async fn finalize_turn_outcome(
// A run the harness stopped (breaker / cap) is traced as stopped, not as a
// clean completion. No deadline wind-down on this path: only the session
// turn carries one, and it records the stop through its sidecar.
- let failure_cause = run.failure_cause.clone();
+ let failure_cause = run.failure_cause.clone().or(classified_cause);
let stop = crate::agent::turn_projection::classify_stop_with_cause(
breaker_halt.as_deref(),
failure_cause.clone(),