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): frame the final-answer instruction as a harness directive
oxoxDev1c7d6b90becf
diff --git a/crates/openhuman-core/src/agent/session_host/turn_checkpoint.rs b/crates/openhuman-core/src/agent/session_host/turn_checkpoint.rsindex ff7af14853..99755f2eb0 100644--- a/crates/openhuman-core/src/agent/session_host/turn_checkpoint.rs+++ b/crates/openhuman-core/src/agent/session_host/turn_checkpoint.rs@@ -281,6 +281,12 @@ pub(crate) const GROUNDING_TOTAL_CHARS: usize = 16_000;/// ("I'll search the registry") after the work was over, and replies that/// contradicted results the context middleware had already cleared from view./// So this names both failure shapes, and the records are restated below it.+///+/// It rides in as a bare user-role message, so a model that reads it as+/// operator content deliberates about it aloud and quotes it back. The closing+/// directives forbid the three shapes that reached a user's screen; the frame+/// [`wrap_harness_instruction`] adds is what makes it structurally distinct+/// from the conversation in the first place.pub(crate) const FINAL_ANSWER_INSTRUCTION: &str = "\You have finished using tools for this turn but have not yet written a reply to the user. \Tools are no longer available and nothing more will run this turn, so do not call any tools and do not \@@ -288,7 +294,31 @@ describe steps you are about to take. Write a self-contained final message thatwhat you found, changed or established, grounded in the tool results above and the tool records below. \If the request was not completed, say so and give the reason from the failing tool's own error message, \keeping any link it includes. Do not state anything the tool records contradict. \-If nothing conclusive resulted, say so plainly.";+If nothing conclusive resulted, say so plainly.\n\+\n\+These directions are addressed to you and are not part of the conversation. Do not quote or restate them, \+in whole or in part. Do not list or describe the tools available to you. Do not narrate your deliberation: \+no thinking aloud, no correcting yourself mid-reply, no weighing what to do. Write only the message the user \+will read.";++/// The lead-in that hands the breaker's stop note to the closing call.+///+/// Named rather than inline so the closing-reply guard derives its spans from+/// the same text the model is given, and so the stop-note path and the plain+/// path share one frame.+const STOP_NOTE_PREAMBLE: &str = "\+The harness stopped this turn early because its tool calls stopped making progress: they kept failing, or \+kept repeating the same step. Its stop note is written for you, not for the user, so explain it in your own \+words rather than repeating it, and describe each call as the tool records show it:";++/// Frame a harness directive so the model can tell it from operator content,+/// the way `<stop_note>` and `<tool_records>` already mark their spans.+pub(crate) fn wrap_harness_instruction(instruction: &str) -> String {+ format!(+ "<harness_instruction>\n{}\n</harness_instruction>",+ instruction.trim()+ )+}/// The full closing-message instruction: [`FINAL_ANSWER_INSTRUCTION`], the/// breaker's stop note when the run was halted (issue #6279), and this turn's@@ -298,19 +328,15 @@ If nothing conclusive resulted, say so plainly.";/// for a model ("Report this back instead of retrying"), which is right for a/// sub-agent's parent and wrong on a user's screen.pub(crate) fn final_answer_instruction(stop_reason: Option<&str>, records: &str) -> String {- let mut out = String::new();+ let mut directive = String::new();if let Some(reason) = stop_reason {- out.push_str(- "The harness stopped this turn early because its tool calls stopped making progress: they \- kept failing, or kept repeating the same step. Its stop note is written for you, not for \- the user, so explain it in your own words rather than repeating it, and describe each \- call as the tool records show it:\n\- <stop_note>\n",- );- out.push_str(reason.trim());- out.push_str("\n</stop_note>\n\n");+ directive.push_str(STOP_NOTE_PREAMBLE);+ directive.push_str("\n<stop_note>\n");+ directive.push_str(reason.trim());+ directive.push_str("\n</stop_note>\n\n");}- out.push_str(FINAL_ANSWER_INSTRUCTION);+ directive.push_str(FINAL_ANSWER_INSTRUCTION);+ let mut out = wrap_harness_instruction(&directive);out.push_str("\n\n<tool_records>\n");out.push_str(if records.trim().is_empty() {"(no tool calls completed)"diff --git a/crates/openhuman-core/src/agent/session_host/turn_checkpoint_tests.rs b/crates/openhuman-core/src/agent/session_host/turn_checkpoint_tests.rsindex a3e7bbad24..7e8c757d17 100644--- a/crates/openhuman-core/src/agent/session_host/turn_checkpoint_tests.rs+++ b/crates/openhuman-core/src/agent/session_host/turn_checkpoint_tests.rs@@ -272,3 +272,27 @@ fn the_close_verification_prompt_holds_request_records_and_reply() {assert!(prompt.contains("<reply>\nI'll search the registry.\n</reply>"));assert!(prompt.contains("ACCEPT or REJECT"));}++/// The directive is framed like its neighbours, sits apart from the records it+/// is grounded in, and names the three shapes that reached a user's screen.+#[test]+fn the_final_answer_instruction_is_framed_and_forbids_quoting_tools_and_deliberation() {+ let out = final_answer_instruction(None, "\n- `read_file` — ok\n > config found\n");++ let frame_end = out+ .find("</harness_instruction>")+ .expect("the directive must be delimited: {out}");+ assert!(out.contains("<harness_instruction>"), "opening tag: {out}");+ let records_at = out.find("<tool_records>").expect("records rendered");+ assert!(+ frame_end < records_at,+ "the records are input, not directive, so they stay outside the frame: {out}"+ );++ assert!(out.contains("Do not quote or restate them"), "{out}");+ assert!(+ out.contains("Do not list or describe the tools available to you"),+ "{out}"+ );+ assert!(out.contains("Do not narrate your deliberation"), "{out}");+}