[codex] fix numeric grounding in agent prompts (#3678)

Co-authored-by: Sami Rusani <sr@samirusani>
This commit is contained in:
Sam
2026-06-15 17:04:26 -07:00
committed by GitHub
co-authored by Sami Rusani
parent eb6f563d84
commit a32f361b15
2 changed files with 23 additions and 0 deletions
+21
View File
@@ -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);
}
+2
View File
@@ -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\