fix(agent): ground time-relative statements in the live clock (#3602) (#3752)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
sanil-23
2026-06-18 12:54:03 +05:30
committed by GitHub
co-authored by Claude
parent 3cf3c5443b
commit 975a478eda
12 changed files with 238 additions and 96 deletions
+5 -1
View File
@@ -466,11 +466,15 @@ async fn builder_dedupes_visible_native_tools_and_seed_resume_bounds_history() -
.messages
.iter()
.any(|msg| msg.role == "user" && msg.content == "falls back to user"));
// The live turn's user message is stamped with the per-turn
// `Current Date & Time:` line (#3602), so match by suffix rather than
// exact equality — the dedup contract (exactly one "current message"
// user turn after resume) still holds.
assert_eq!(
requests[0]
.messages
.iter()
.filter(|msg| msg.role == "user" && msg.content == "current message")
.filter(|msg| msg.role == "user" && msg.content.ends_with("current message"))
.count(),
1
);
+23 -3
View File
@@ -121,12 +121,32 @@ async fn test_orchestrator_has_current_date_context() -> Result<()> {
let _ = agent.turn("what is on my calendar this week?").await?;
let messages = captured_messages.lock();
let system_prompt = messages
// The system prompt carries the static grounding *rule* (#3602) — the
// concrete clock no longer lives here, it rides the per-turn user message
// so a long-lived session can't go stale.
messages
.iter()
.find(|m| m.role == "system" && m.content.contains("## Current Date & Time"))
.expect("System prompt should contain Current Date & Time");
.expect("System prompt should carry the Current Date & Time grounding rule");
assert!(system_prompt.content.contains("202"));
// The live date/time is injected on the user message every turn. Assert it
// carries the stamp and a concrete year token.
let user_msg = messages
.iter()
.find(|m| m.role == "user" && m.content.contains("Current Date & Time:"))
.expect("User message should carry the per-turn Current Date & Time stamp");
// Assert a concrete `YYYY-MM-DD HH:MM:SS` shape rather than a decade token
// (which would rot as years advance).
let after = user_msg
.content
.split("Current Date & Time: ")
.nth(1)
.expect("stamp must follow the canonical prefix");
let dt = after
.get(0..19)
.expect("stamp must include YYYY-MM-DD HH:MM:SS");
chrono::NaiveDateTime::parse_from_str(dt, "%Y-%m-%d %H:%M:%S")
.expect("user message stamp must include a parseable YYYY-MM-DD HH:MM:SS");
Ok(())
}