From a32f361b15020e06450667d9229a4790fd71a56d Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 16 Jun 2026 02:04:26 +0200 Subject: [PATCH] [codex] fix numeric grounding in agent prompts (#3678) Co-authored-by: Sami Rusani --- src/openhuman/agent/prompts/mod_tests.rs | 21 +++++++++++++++++++++ src/openhuman/agent/prompts/sections.rs | 2 ++ 2 files changed, 23 insertions(+) diff --git a/src/openhuman/agent/prompts/mod_tests.rs b/src/openhuman/agent/prompts/mod_tests.rs index 8ec6da7fc..7fca8501c 100644 --- a/src/openhuman/agent/prompts/mod_tests.rs +++ b/src/openhuman/agent/prompts/mod_tests.rs @@ -146,6 +146,26 @@ fn grounding_contract_appended_to_every_build_path() { assert!(g < s, "grounding should precede the output-style suffix"); } +#[test] +fn grounding_contract_requires_exact_numeric_evidence() { + let ctx = ctx_with_identity(None); + let rendered = SystemPromptBuilder::from_final_body("## Custom Agent\n\nBody.".into()) + .build(&ctx) + .unwrap(); + + assert!(rendered.contains("Preserve numeric evidence exactly")); + assert!(rendered.contains( + "numbers, counts, sizes, dates, timestamps, durations, currencies, percentages, quotas, and ids" + )); + assert!(rendered.contains( + "copy the exact value from the observed tool result, user message, or cited memory" + )); + assert!(rendered.contains("Do not round, convert units, rewrite relative times")); + assert!(rendered.contains( + "If sources disagree, name the discrepancy instead of choosing a plausible value" + )); +} + #[test] fn identity_section_creates_missing_workspace_files() { let workspace = @@ -656,6 +676,7 @@ fn render_subagent_system_prompt_renders_workspace_tail() { // `GroundingSection` / the central `build()` append. assert!(rendered.contains("## Grounding and tool use")); assert!(rendered.contains("Your tools are exactly the ones listed in this prompt")); + assert!(rendered.contains("Preserve numeric evidence exactly")); let _ = std::fs::remove_dir_all(workspace); } diff --git a/src/openhuman/agent/prompts/sections.rs b/src/openhuman/agent/prompts/sections.rs index 47097c95e..658d15743 100644 --- a/src/openhuman/agent/prompts/sections.rs +++ b/src/openhuman/agent/prompts/sections.rs @@ -422,6 +422,8 @@ impl PromptSection for SafetySection { pub const GROUNDING_BODY: &str = "## Grounding and tool use\n\n\ - Your tools are exactly the ones listed in this prompt. You can only act through them. If a capability is not one of your tools, say so plainly rather than pretending it exists.\n\ - Never invent tool names, arguments, ids, slugs, file paths, URLs, chain ids, addresses, quotes, metrics, or any other value. If you do not have it from a tool result or the user, ask for it or look it up with a tool.\n\ + - Preserve numeric evidence exactly. For numbers, counts, sizes, dates, timestamps, durations, currencies, percentages, quotas, and ids, copy the exact value from the observed tool result, user message, or cited memory into your answer.\n\ + - Do not round, convert units, rewrite relative times, or recalculate numeric values unless the user asks and you show the calculation from observed values. If sources disagree, name the discrepancy instead of choosing a plausible value.\n\ - Use your tools to act. Do not just describe what you would do and stop, and never end a turn with a promise of future action: do it now, or hand back a concrete result.\n\ - Never substitute plausible looking but fabricated output (made up data, invented file contents, synthesised tool or API responses) for results you could not actually produce. If a step failed, say it failed.\n\ - Ground every factual claim in evidence you actually observed: a tool result, the user's message, or cited memory. If the evidence is missing, partial, or truncated, say so or fetch more instead of guessing.\n\