Skip to content

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

feat(caps_host): surface agent turn stop reasons in run outcomes

Steven Enamakel57a1bd3a2e3f
diff --git a/crates/openhuman-core/src/flows/caps_host/agent.rs b/crates/openhuman-core/src/flows/caps_host/agent.rs
index 30f4da85f2..ce0865651b 100644
--- a/crates/openhuman-core/src/flows/caps_host/agent.rs
+++ b/crates/openhuman-core/src/flows/caps_host/agent.rs
@@ -83,6 +83,7 @@ pub(crate) struct AgentRunState {
pub(crate) events: Vec<tinyflows_bus::runs::AgentProgressEvent>,
pub(crate) outcome: Option<tinyflows_bus::runs::AgentRunOutcome>,
pub(crate) error: Option<String>,
+ pub(crate) turn_stop: Option<tinyagents_harness::turn_stop::TurnStop>,
pub(crate) done: bool,
}
@@ -130,7 +131,7 @@ fn max_parallel_harness_agents(raw: Option<&str>) -> usize {
}
impl OpenHumanAgentRunner {
- async fn prepare_agent_run(
+ pub(crate) async fn prepare_agent_run(
&self,
request: Value,
entry_model: Option<&str>,
diff --git a/crates/openhuman-core/src/flows/caps_host/ops_tests.rs b/crates/openhuman-core/src/flows/caps_host/ops_tests.rs
index 5536e7b8ad..7fa5dd7717 100644
--- a/crates/openhuman-core/src/flows/caps_host/ops_tests.rs
+++ b/crates/openhuman-core/src/flows/caps_host/ops_tests.rs
@@ -31,6 +31,17 @@ fn workflow_origin(job_id: &str, require_approval: bool) -> AgentTurnOrigin {
}
}
+fn agent_test_config(tmp: &tempfile::TempDir) -> Config {
+ let config = Config {
+ workspace_dir: tmp.path().join("workspace"),
+ action_dir: tmp.path().join("workspace"),
+ config_path: tmp.path().join("config.toml"),
+ ..Config::default()
+ };
+ std::fs::create_dir_all(&config.workspace_dir).unwrap();
+ config
+}
+
#[path = "ops_schema_and_structured_output_tests.rs"]
mod schema_and_structured_output_tests;
#[path = "ops_tier_gate_and_timeouts_tests.rs"]
diff --git a/crates/openhuman-core/src/flows/caps_host/ops_tier_gate_and_timeouts_tests.rs b/crates/openhuman-core/src/flows/caps_host/ops_tier_gate_and_timeouts_tests.rs
index 8afa323d80..ee4d22e1d3 100644
--- a/crates/openhuman-core/src/flows/caps_host/ops_tier_gate_and_timeouts_tests.rs
+++ b/crates/openhuman-core/src/flows/caps_host/ops_tier_gate_and_timeouts_tests.rs
@@ -1,6 +1,5 @@
use super::*;
use tinyagents_harness::tool::response_fields_from_schema;
-use tinyflows::nodes::integration::agent_prompt::scale_timeout_for_iteration_cap;
use tinytools::status::POLICY_BLOCKED_MARKER;
/// The tier gate an `http_request` (Network-class) node calls: BLOCKED under
@@ -374,10 +373,10 @@ fn nested_harness_does_not_escalate_without_an_origin() {
/// default (10). This mirrors the exact build step `run_via_harness` takes
/// before dispatching the turn (so it doesn't require a live model
/// provider to exercise).
-#[test]
-fn agent_node_runtime_resolves_to_the_definitions_effective_iteration_cap() {
+#[tokio::test]
+async fn agent_node_runtime_resolves_to_the_definitions_effective_iteration_cap() {
let tmp = tempfile::TempDir::new().unwrap();
- let config = resolver_test_config(&tmp);
+ let config = agent_test_config(&tmp);
assert_eq!(config.agent.max_tool_iterations, 10);
crate::agent::harness::host_definition::AgentDefinitionRegistry::init_global(
@@ -400,122 +399,18 @@ fn agent_node_runtime_resolves_to_the_definitions_effective_iteration_cap() {
.expect("build planner agent");
assert_eq!(agent.agent_config().max_tool_iterations, expected);
- // And the timeout scaling this cap feeds into actually widens the
- // default 240s bound for this node.
- let base_timeout = clamp_run_timeout_secs(None);
- assert_eq!(base_timeout, 240);
- let scaled =
- scale_timeout_for_iteration_cap(base_timeout, agent.agent_config().max_tool_iterations);
- assert_eq!(scaled, 600);
-}
-
-/// The resolver loads a saved flow's graph by its id — the by-`workflow_id`
-/// sub_workflow path resolves against the real flows store.
-#[tokio::test]
-async fn resolver_loads_saved_flow_graph_by_id() {
- let tmp = tempfile::TempDir::new().unwrap();
- let config = Arc::new(resolver_test_config(&tmp));
-
- let graph_json = serde_json::to_value(trigger_only_graph()).unwrap();
- let flow = flows::ops::flows_create(&config, "child".to_string(), graph_json, false)
- .await
- .expect("create flow");
- let flow_id = flow.value.id.clone();
-
- let resolver = OpenHumanWorkflowResolver {
- ctx: crate::core::runtime::DispatchCtx::ambient(),
- config: config.clone(),
- };
- let graph = resolver
- .resolve(&flow_id)
- .await
- .expect("resolver should load the saved flow graph");
- assert_eq!(graph.nodes.len(), 1);
- assert_eq!(graph.nodes[0].id, "t");
-}
-
-/// An unknown workflow_id surfaces a capability error naming the id, rather
-/// than silently resolving to nothing.
-#[tokio::test]
-async fn resolver_unknown_id_is_a_capability_error() {
- let tmp = tempfile::TempDir::new().unwrap();
- let config = Arc::new(resolver_test_config(&tmp));
- let resolver = OpenHumanWorkflowResolver {
- ctx: crate::core::runtime::DispatchCtx::ambient(),
- config,
+ let runner = OpenHumanAgentRunner {
+ config: Arc::new(config),
+ ctx: crate::core::runtime::DispatchCtx::unbound(),
+ approval: Default::default(),
+ progress: None,
};
-
- let err = resolver
- .resolve("does-not-exist")
+ let prepared = runner
+ .prepare_agent_run(json!({"prompt":"work"}), None, None, 50)
.await
- .expect_err("unknown workflow_id must error");
- match err {
- EngineError::Capability(msg) => assert!(
- msg.contains("does-not-exist"),
- "error should name the missing id: {msg}"
- ),
- other => panic!("expected a capability error, got: {other:?}"),
- }
-}
-
-#[tokio::test]
-async fn resolver_rejects_an_engine_incompatible_saved_graph() {
- let tmp = tempfile::TempDir::new().unwrap();
- let config = Arc::new(resolver_test_config(&tmp));
- let flow = flows::ops::flows_create(
- &config,
- "legacy child".to_string(),
- serde_json::to_value(trigger_only_graph()).unwrap(),
- false,
- )
- .await
- .unwrap()
- .value;
- let unsafe_graph = json!({
- "nodes": [
- { "id": "t", "kind": "trigger", "name": "Trigger" },
- { "id": "outer", "kind": "condition", "name": "Outer", "config": { "field": "outer" } },
- { "id": "inner", "kind": "condition", "name": "Inner", "config": { "field": "inner" } },
- { "id": "outer_else", "kind": "output_parser", "name": "Outer else" },
- { "id": "inner_else", "kind": "output_parser", "name": "Inner else" },
- { "id": "a", "kind": "output_parser", "name": "A" },
- { "id": "c", "kind": "output_parser", "name": "C" },
- { "id": "m", "kind": "merge", "name": "Merge" }
- ],
- "edges": [
- { "from_node": "t", "from_port": "main", "to_node": "outer" },
- { "from_node": "t", "from_port": "main", "to_node": "c" },
- { "from_node": "outer", "from_port": "true", "to_node": "inner" },
- { "from_node": "outer", "from_port": "false", "to_node": "outer_else" },
- { "from_node": "inner", "from_port": "true", "to_node": "a" },
- { "from_node": "inner", "from_port": "false", "to_node": "inner_else" },
- { "from_node": "a", "from_port": "main", "to_node": "m" },
- { "from_node": "c", "from_port": "main", "to_node": "m" }
- ]
- });
- // Stage a stored graph no save path would accept: written raw, under the
- // flow's id, as a legacy row would be.
- crate::flows::store::force_corrupt_graph_json_for_test(
- &config,
- &flow.id,
- &unsafe_graph.to_string(),
- )
- .unwrap();
-
- let error = OpenHumanWorkflowResolver {
- ctx: crate::core::runtime::DispatchCtx::ambient(),
- config,
- }
- .resolve(&flow.id)
- .await
- .expect_err("resolver must reject an incompatible legacy child");
- match error {
- EngineError::Capability(message) => assert!(
- message.contains("unsupported_nested_conditional_fan_in"),
- "{message}"
- ),
- other => panic!("expected a capability error, got: {other:?}"),
- }
+ .expect("module prepares agent timeout");
+ assert_eq!(prepared.base_timeout_secs, 240);
+ assert_eq!(prepared.timeout_secs, 600);
}
// ── response_fields_from_schema ─────────────────────────────────────────
diff --git a/crates/openhuman-core/src/flows/caps_host/ops_tier_live_config_tests.rs b/crates/openhuman-core/src/flows/caps_host/ops_tier_live_config_tests.rs
index c786002dc7..091c9bf0a4 100644
--- a/crates/openhuman-core/src/flows/caps_host/ops_tier_live_config_tests.rs
+++ b/crates/openhuman-core/src/flows/caps_host/ops_tier_live_config_tests.rs
@@ -307,7 +307,7 @@ async fn code_adapter_observes_file_backed_tier_changes_between_calls() {
let err = code
.run(
- tinyflows::caps::CodeLanguage::JavaScript,
+ tinyflows_bus::runs::CodeLanguage::JavaScript,
"return 1;",
json!([]),
)
diff --git a/crates/openhuman-core/src/flows/caps_host/service.rs b/crates/openhuman-core/src/flows/caps_host/service.rs
index b66137ec78..6330619918 100644
--- a/crates/openhuman-core/src/flows/caps_host/service.rs
+++ b/crates/openhuman-core/src/flows/caps_host/service.rs
@@ -29,6 +29,13 @@ impl CapsHostService {
let progress_state = Arc::clone(&state);
let progress = tokio::spawn(async move {
while let Some(event) = progress_rx.recv().await {
+ if let crate::agent::progress::AgentProgress::TurnCompleted {
+ stop: Some(stop),
+ ..
+ } = &event
+ {
+ progress_state.lock().await.turn_stop = Some(stop.clone());
+ }
let Some((kind, text)) = progress_event(event) else {
continue;
};
@@ -50,7 +57,11 @@ impl CapsHostService {
let mut config = request.config.clone();
if let (Some(model), Some(object)) = (
- request.model.model.as_ref(),
+ request
+ .model
+ .model
+ .as_ref()
+ .or(request.agent.model.as_ref()),
config.as_object_mut(),
) && object.get("model").and_then(Value::as_str).is_none()
{
@@ -77,6 +88,44 @@ impl CapsHostService {
state.done = true;
match result {
Ok(raw) => {
+ let turn_stop = state.turn_stop.clone();
+ let stop = match turn_stop.as_ref() {
+ None => runs::StopReason::Finished,
+ Some(stop)
+ if stop.kind
+ == tinyagents_harness::turn_stop::TurnStopKind::IterationCap =>
+ {
+ runs::StopReason::LimitStop {
+ limit: "max_steps".to_owned(),
+ }
+ }
+ Some(stop)
+ if stop.kind == tinyagents_harness::turn_stop::TurnStopKind::WindDown =>
+ {
+ runs::StopReason::Paused {
+ token: None,
+ reason: "wall_clock".to_owned(),
+ payload: json!({
+ "kind": stop.kind.as_str(),
+ "failure_class": stop.failure_class.as_ref().map(|class| class.as_str()),
+ "operation": stop.operation.as_deref(),
+ }),
+ }
+ }
+ Some(stop) => {
+ let class = stop
+ .failure_class
+ .as_ref()
+ .map(|class| class.as_str())
+ .unwrap_or("unknown");
+ let operation = stop.operation.as_deref().unwrap_or("unknown");
+ let error = format!(
+ "agent run stopped by classified failure ({class}, {operation})"
+ );
+ state.error = Some(error.clone());
+ return Err(error);
+ }
+ };
let text = raw
.as_str()
.map(str::to_owned)
@@ -94,7 +143,7 @@ impl CapsHostService {
})
.collect();
state.outcome = Some(runs::AgentRunOutcome {
- stop: runs::StopReason::Finished,
+ stop,
text,
json,
raw,