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): check exact coding requirements before finishing
Steven Enamakel1fb593d9f42a
diff --git a/crates/openhuman-core/src/agent/tinyagents/verify_before_finish.rs b/crates/openhuman-core/src/agent/tinyagents/verify_before_finish.rsindex d266b6effd..f8415a7a6e 100644--- a/crates/openhuman-core/src/agent/tinyagents/verify_before_finish.rs+++ b/crates/openhuman-core/src/agent/tinyagents/verify_before_finish.rs@@ -1,5 +1,5 @@-//! Issue #6952: one spec check before a root orchestrator turn's first final-//! answer stands.+//! Issues #6952 and #6990: one requirements check before a root orchestrator+//! turn's first final answer stands.//!//! The mechanism is the generic//! [`VerifyBeforeFinishMiddleware`](tinyagents_harness::middleware::VerifyBeforeFinishMiddleware)@@ -37,9 +37,21 @@ pub(super) const CHECK_MARKER: &str = "Before finishing";const CHECK_INSTRUCTION: &str = "Before finishing: re-read the original request. For each \explicit requirement, filter, rule or threshold it states, cite evidence from the final \environment that it holds. Tests count only if derived from the spec, not from your \-implementation. If you flagged an interpretation that contradicts a stated rule, apply the \-literal rule. Fix anything that fails; if all holds, give your final answer in full, since it \-replaces your previous reply.";+implementation.\n\n\+For a coding task:\n\+1. Split the task statement into individual requirements. Include every negative constraint \+(such as 'cannot' or 'must be rejected'), exact error, return value, and case in parentheses.\n\+2. For each requirement, name and run a check that exercises the exact syntax, input or \+API call stated in the task. Check rejection errors as well as rejection itself, and the \+whole return value as well as its fields.\n\+3. Where a sentence allows two readings, examine both against the surrounding contract. \+Use the literal rule where it resolves the ambiguity; otherwise exercise both readings \+and state any remaining uncertainty instead of treating a check of your guess as proof.\n\+4. Find every code path that performs the same action and check that required side effects \+(callbacks, events and state changes) are consistent across those paths.\n\n\+If you flagged an interpretation that contradicts a stated rule, apply the literal rule. \+Fix anything that fails and re-run the affected checks. If all holds, give your final \+answer in full, since it replaces your previous reply.";/// Whether a turn gets the check: root (not delegated) orchestrator turns only./// A sub-agent's answer goes back to its parent, which gets the check on its owndiff --git a/crates/openhuman-core/src/agent/tinyagents/verify_before_finish_tests.rs b/crates/openhuman-core/src/agent/tinyagents/verify_before_finish_tests.rsindex 6199e16b76..34e19c6069 100644--- a/crates/openhuman-core/src/agent/tinyagents/verify_before_finish_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/verify_before_finish_tests.rs@@ -125,11 +125,80 @@ fn check_is_a_harness_instruction_that_names_the_spec_rules() {let check = check_message();assert!(check.starts_with("<harness_instruction>"));assert!(check.contains(CHECK_MARKER));- for needle in ["original request", "literal rule", "derived from the spec"] {+ for needle in [+ "original request",+ "literal rule",+ "derived from the spec",+ "individual requirements",+ "negative constraint",+ "case in parentheses",+ "exact syntax, input or API call",+ "rejection errors as well as rejection itself",+ "whole return value as well as its fields",+ "exercise both readings",+ "every code path",+ "callbacks, events and state changes",+ "re-run the affected checks",+ ] {assert!(check.contains(needle), "check must mention `{needle}`");}}+/// #6990: the installed policy sends the requirements check with the original+/// coding request, permits corrective tool calls, then accepts the new answer+/// without injecting a second check.+#[tokio::test]+async fn coding_requirements_check_allows_a_fix_and_fires_once() {+ let task =+ "Reject variadic defaults with the exact error 'invalid default argument declaration'.";+ let mut responses: Vec<_> = (0..MIN_TOOL_ROUNDS)+ .map(|i| tool_round(&format!("c{i}"), "lookup"))+ .collect();+ responses.extend([+ ModelResponse::assistant("draft: my checks passed".to_string()),+ tool_round("fix", "lookup"),+ ModelResponse::assistant("fixed and checked against the requirements".to_string()),+ ModelResponse::assistant("must not be reached".to_string()),+ ]);+ let model = Arc::new(ScriptedModel::new(responses));+ let mut harness: AgentHarness<()> = AgentHarness::new();+ harness.register_model("mock", model.clone());+ harness.register_tool(Arc::new(FakeTool::returning("lookup", "ok")));+ harness.with_policy(RunPolicy {+ limits: RunLimits::default().with_max_model_calls(50),+ ..RunPolicy::default()+ });+ install(&mut harness, false, Some("orchestrator"), &None);++ let run = harness+ .invoke_default(&(), vec![Message::user(task)])+ .await+ .expect("coding run succeeds");+ assert_eq!(+ run.text().as_deref(),+ Some("fixed and checked against the requirements")+ );+ assert_eq!(run.model_calls, MIN_TOOL_ROUNDS + 3);+ let requests = model.requests();+ let verification = &requests[MIN_TOOL_ROUNDS + 1];+ assert_eq!(+ verification.messages.first().map(Message::text).as_deref(),+ Some(task)+ );+ assert_eq!(+ verification.messages.last().map(Message::text),+ Some(check_message())+ );+ assert_eq!(+ run.messages+ .iter()+ .filter(|message| message.text() == check_message())+ .count(),+ 1,+ "corrective tool calls must not reset the check"+ );+}+#[tokio::test]async fn installed_root_orchestrator_turn_checks_once_after_five_rounds() {let (checks, text) = drive(MIN_TOOL_ROUNDS, "lookup", false, Some("orchestrator")).await;