Skip to content

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

refactor(agent): use one requirements check for every task

Steven Enamakel642114217a94
diff --git a/crates/openhuman-core/src/agent/tinyagents/verify_before_finish.rs b/crates/openhuman-core/src/agent/tinyagents/verify_before_finish.rs
index f8415a7a6e..11afa5a300 100644
--- a/crates/openhuman-core/src/agent/tinyagents/verify_before_finish.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/verify_before_finish.rs
@@ -34,22 +34,19 @@ pub(super) const TODO_TOOL: &str = "todo";
/// Opening words of the check, also how tests recognise it on a transcript.
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.\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. \
+const CHECK_INSTRUCTION: &str = "Before finishing: re-read the original request and check \
+the final result against it.\n\
+1. Split the task statement into individual requirements. Include every constraint, \
+prohibited case, expected output or error, threshold, and case in parentheses.\n\
+2. For each requirement, name and perform an independent check using the exact examples, \
+inputs and conditions stated in the request. Verify the complete outcome, including \
+expected errors and side effects, and cite evidence from the final environment. Checks \
+count only if derived from the request, not from your own approach.\n\
+3. Where a sentence allows two readings, examine both against the surrounding requirements. \
+Apply the literal rule where it resolves the ambiguity; otherwise check both readings and \
+state any remaining uncertainty instead of treating a check of your guess as proof.\n\
+4. Find equivalent paths or workflows that perform the same action and verify that their \
+required outcomes, notifications and state changes are consistent.\n\n\
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.";
diff --git a/crates/openhuman-core/src/agent/tinyagents/verify_before_finish_tests.rs b/crates/openhuman-core/src/agent/tinyagents/verify_before_finish_tests.rs
index 34e19c6069..c472af077f 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
@@ -128,75 +128,82 @@ fn check_is_a_harness_instruction_that_names_the_spec_rules() {
for needle in [
"original request",
"literal rule",
- "derived from the spec",
+ "derived from the request",
"individual requirements",
- "negative constraint",
+ "prohibited case",
"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",
+ "exact examples, inputs and conditions",
+ "complete outcome",
+ "expected errors and side effects",
+ "check both readings",
+ "equivalent paths or workflows",
+ "outcomes, notifications and state changes",
"re-run the affected checks",
] {
assert!(check.contains(needle), "check must mention `{needle}`");
}
+ assert!(
+ !check.contains("coding task"),
+ "the check applies to any task"
+ );
}
-/// #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.
+/// #6990: the installed policy sends the same requirements check with coding
+/// and reporting requests, 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);
+async fn requirements_check_allows_a_fix_for_different_tasks() {
+ for task in [
+ "Reject variadic defaults with the exact error 'invalid default argument declaration'.",
+ "Report all active projects (including paused projects), and exclude archived projects.",
+ ] {
+ 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"
- );
+ let run = harness
+ .invoke_default(&(), vec![Message::user(task)])
+ .await
+ .expect("task 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]