The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(agent): give a rejected tool argument its own recovery budget
killbilla1d7dbbbe2fa
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rsindex b36d82d4da..ad2f7aa505 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs@@ -254,6 +254,25 @@ pub(super) fn recovery_policy(Some((class, budget))}+/// Recovery budget for a tool rejecting its own arguments against its schema.+///+/// This is the most recoverable failure in the table: nothing ran, so there is+/// no side effect to reconcile, and the refusal hands the model the complete+/// expected schema (`tinyagents` `agent_loop/tools.rs`: "invalid arguments for+/// tool `X`: {detail}; expected schema: {…}"). It is a typo in one call, not a+/// broken world — unlike `not_found` or `unavailable`, which need the world to+/// change, and unlike a remote service's 400/422, which rejects a request the+/// model may have had every reason to send.+///+/// At a budget of 1 it ended terminal-bench 4.0 `vf2-speedup-networkx` at+/// 51/60 tests: the model omitted `edits[0].path` on two consecutive+/// `apply_patch` calls, while five others in the same run carried all three+/// fields — one of them 16,370 characters, seventeen times the size of the one+/// that failed. The omission was intermittent, not a size limit, so a further+/// attempt would most likely have landed. Three keeps it bounded; a call+/// repeated unchanged is still caught by the generic no-progress ladder.+const ARGUMENT_SCHEMA_RECOVERY: usize = 3;+/// Prefix of `tinytools::render_command_failure`, the one renderer every/// shell-family tool uses for a command that ran and did not exit 0: an/// exit-code (or signal) line, then the program's own stdout and stderr.@@ -376,11 +395,16 @@ fn classified_recovery_policy(Class::Timeout if tool == "shell" => ("uncertain_side_effect", 1),Class::Timeout => ("uncertain_side_effect", 0),Class::Unknown if is_recoverable_tool_failure(error) => ("transient", 2),+ // Its own class, not the `validation` bucket: the ledger keys on+ // (class, operation, scope), so pooling this with `unknown tool` and+ // `validate_workflow`'s invalid graphs would hand those a budget they+ // should not have. A wrong tool name does not become right, and a graph+ // the model cannot fix should still stop.Class::Unknownif error.to_ascii_lowercase().contains("schema validation")|| error.to_ascii_lowercase().contains("invalid arguments") =>{- ("validation", 1)+ ("invalid_arguments", ARGUMENT_SCHEMA_RECOVERY)}Class::Unknown => return None,})diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rsindex 832fb017e2..c60bab860b 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rs@@ -31,11 +31,15 @@ async fn varied_queries_against_one_forbidden_endpoint_stop_on_first_failure() {}#[tokio::test]-async fn schema_repair_gets_one_attempt_even_when_arguments_change() {+async fn schema_repair_gets_three_attempts_before_stopping() {+ // A tool rejecting its own arguments is a typo the refusal already explains,+ // so it is not held to the one retry the `validation` bucket allows: two+ // consecutive `apply_patch` arguments without `edits[0].path` ended+ // terminal-bench 4.0 `vf2-speedup-networkx` at 51/60 tests.let handle = SteeringHandle::allow_all();let slot = std::sync::Arc::new(std::sync::Mutex::new(None));- let mw = RepeatedToolFailureMiddleware::new(handle.clone(), 3, slot.clone());- for (id, value) in [("schema-1", 1), ("schema-2", 2)] {+ let mw = RepeatedToolFailureMiddleware::new(handle.clone(), 8, slot.clone());+ for (id, value) in [("schema-1", 1), ("schema-2", 2), ("schema-3", 3)] {let mut call = TaToolCall::new(id,"search",@@ -48,10 +52,73 @@ async fn schema_repair_gets_one_attempt_even_when_arguments_change() {.await.unwrap();}- assert_eq!(drain_pause_count(&handle), 1);+ assert_eq!(+ drain_pause_count(&handle),+ 0,+ "three schema rejections stay inside the budget"+ );+ assert!(slot.lock().unwrap().is_none(), "no halt summary yet");++ let mut call = TaToolCall::new(+ "schema-4",+ "search",+ serde_json::json!({"query": 4, "endpoint": "catalog"}),+ );+ mw.before_tool(&mut ctx(), &(), &mut call).await.unwrap();+ let mut result = failing_result("search", "schema validation failed: query must be a string");+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("schema-4", "search"),+ &mut result,+ )+ .await+ .unwrap();+ assert_eq!(drain_pause_count(&handle), 1, "the fourth stops");let summary = slot.lock().unwrap().clone().unwrap();- assert!(summary.contains("validation"), "{summary}");- assert!(summary.contains("2 attempt(s)"), "{summary}");+ assert!(summary.contains("invalid_arguments"), "{summary}");+ assert!(summary.contains("4 attempt(s)"), "{summary}");+}++#[test]+fn a_rejected_tool_argument_is_its_own_class_with_a_larger_budget() {+ // The message `tinyagents` renders for a schema rejection (agent_loop/tools.rs).+ assert_eq!(+ super::super::repeated_failure::recovery_policy(+ "apply_patch",+ "invalid arguments for tool `apply_patch`: validation error: tool `apply_patch` \+ arguments.edits[0].path is required; expected schema: {\"properties\":{}}",+ false+ ),+ Some(("invalid_arguments", 3))+ );+ // The classes it must NOT be pooled with: a wrong tool name does not become+ // right, a remote service's rejection is not the model's schema mistake,+ // and an invalid workflow graph should still stop.+ assert_eq!(+ super::super::repeated_failure::recovery_policy(+ "forbidden_tool",+ "unknown tool `ranges` (arguments: {}); valid tools: [file_write]",+ false+ ),+ Some(("validation", 1))+ );+ assert_eq!(+ super::super::repeated_failure::recovery_policy(+ "search",+ r#"{"error":{"code":"INVALID_ARGUMENT"}}"#,+ false+ ),+ Some(("validation", 1))+ );+ assert_eq!(+ super::super::repeated_failure::recovery_policy(+ "validate_workflow",+ "{\"ok\":false}",+ true+ ),+ Some(("validation", 1))+ );}#[tokio::test]