Fix: calendar events#1004
Conversation
Included current date and time in main agent system prompts and injected temporal context into sub-agent user messages. This ensures that agents can correctly resolve relative date queries (e.g., "this week") to accurate date ranges when calling the calendar tool. Respects the local timezone of the host device. Closes: tinyhumansai#987 Co-authored-by: YellowSnnowmann <167776381+YellowSnnowmann@users.noreply.github.com>
- Include current date and time in main agent system prompts (orchestrator, morning_briefing, planner). - Inject temporal context into sub-agent user messages to preserve KV cache stability. - Add unit tests for prompt building and sub-agent grounding. - Add E2E test verifying date grounding in agent tool calls. - Fix formatting issues. Closes: tinyhumansai#987 Co-authored-by: YellowSnnowmann <167776381+YellowSnnowmann@users.noreply.github.com>
📝 WalkthroughWalkthroughThe PR injects current date/time context into multiple agent prompts and the subagent execution harness. Morning briefing, orchestrator, and planner prompts now invoke Changes
Possibly related issues
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
src/openhuman/agent/agents/morning_briefing/prompt.rs (1)
53-73: Strengthen morning briefing prompt test for datetime grounding.Please add a targeted assertion for
## Current Date & Time(not just non-empty output) to protect this specific behavior.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openhuman/agent/agents/morning_briefing/prompt.rs` around lines 53 - 73, Update the test build_returns_nonempty_body in prompt.rs to assert the prompt includes the datetime grounding header: after calling build(&ctx).unwrap(), add an assertion that the returned body contains the literal "## Current Date & Time" (or exact header used by build). This targets the build function's datetime grounding behavior (referencing build and PromptContext) so the test fails if that section is removed or renamed.src/openhuman/agent/agents/planner/prompt.rs (1)
53-73: Add a dedicated datetime assertion test for planner prompt.Right now the test only checks non-empty output. Please add a focused check that the built prompt includes
## Current Date & Timeso this grounding doesn’t regress silently.Suggested test addition
#[test] fn build_returns_nonempty_body() { @@ let body = build(&ctx).unwrap(); assert!(!body.is_empty()); } + +#[test] +fn build_includes_datetime() { + let visible: HashSet<String> = HashSet::new(); + let ctx = PromptContext { + workspace_dir: std::path::Path::new("."), + model_name: "test", + agent_id: "planner", + tools: &[], + skills: &[], + dispatcher_instructions: "", + learned: LearnedContextData::default(), + visible_tool_names: &visible, + tool_call_format: ToolCallFormat::PFormat, + connected_integrations: &[], + connected_identities_md: String::new(), + include_profile: false, + include_memory_md: false, + }; + let body = build(&ctx).unwrap(); + assert!(body.contains("## Current Date & Time")); +}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openhuman/agent/agents/planner/prompt.rs` around lines 53 - 73, Update the planner prompt tests to assert the prompt includes the current-datetime heading: modify the existing test build_returns_nonempty_body (or add a new test) that constructs a PromptContext and calls build(&ctx).unwrap(), and add an assertion that the returned body contains the literal "## Current Date & Time" (e.g., assert!(body.contains("## Current Date & Time"))); reference the PromptContext construction and build function to locate where to add this check so the prompt’s datetime grounding cannot regress.tests/calendar_grounding_e2e.rs (1)
52-53: Current E2E assertions are too weak to prove date-grounding correctness.The test currently passes on marker presence and a broad
"202"check, while the mocked tool-call range is hard-coded. This won’t catch regressions in relative date grounding (current week/next week/month boundary/timezone-sensitive behavior). Please assert against runtime-derived expected date context and timezone shape.Also applies to: 126-127, 188-191
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/calendar_grounding_e2e.rs` around lines 52 - 53, The assertions in calendar_grounding_e2e.rs that only check marker presence and a broad "202" substring are too weak; update the test to compute expected timeMin/timeMax at runtime (using chrono::Utc or Local to derive the start/end of the relevant period, e.g., start of current week and start of next week or month depending on the scenario) and assert the mocked tool-call payload's "timeMin"/"timeMax" equal the RFC3339-formatted values (or are within a small tolerance) instead of substring checks; apply the same fix for the other occurrences noted (the assertions around lines ~126-127 and ~188-191) so tests validate correct date grounding and timezone shape rather than static hard-coded ranges.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/openhuman/agent/harness/subagent_runner/ops.rs`:
- Around line 565-570: The injected temporal string currently uses only the
timezone abbreviation via now.format("%Z"), which can be ambiguous or empty;
change the formatting in the creation of now_str (the code around
chrono::Local::now() and now_str) to include the numeric UTC offset (e.g., use
format specifier %:z or %z) — for example combine now.format("%Y-%m-%d
%H:%M:%S"), now.format("%Z"), and now.format("%:z") so the string contains both
the abbreviation and an explicit numeric offset.
---
Nitpick comments:
In `@src/openhuman/agent/agents/morning_briefing/prompt.rs`:
- Around line 53-73: Update the test build_returns_nonempty_body in prompt.rs to
assert the prompt includes the datetime grounding header: after calling
build(&ctx).unwrap(), add an assertion that the returned body contains the
literal "## Current Date & Time" (or exact header used by build). This targets
the build function's datetime grounding behavior (referencing build and
PromptContext) so the test fails if that section is removed or renamed.
In `@src/openhuman/agent/agents/planner/prompt.rs`:
- Around line 53-73: Update the planner prompt tests to assert the prompt
includes the current-datetime heading: modify the existing test
build_returns_nonempty_body (or add a new test) that constructs a PromptContext
and calls build(&ctx).unwrap(), and add an assertion that the returned body
contains the literal "## Current Date & Time" (e.g., assert!(body.contains("##
Current Date & Time"))); reference the PromptContext construction and build
function to locate where to add this check so the prompt’s datetime grounding
cannot regress.
In `@tests/calendar_grounding_e2e.rs`:
- Around line 52-53: The assertions in calendar_grounding_e2e.rs that only check
marker presence and a broad "202" substring are too weak; update the test to
compute expected timeMin/timeMax at runtime (using chrono::Utc or Local to
derive the start/end of the relevant period, e.g., start of current week and
start of next week or month depending on the scenario) and assert the mocked
tool-call payload's "timeMin"/"timeMax" equal the RFC3339-formatted values (or
are within a small tolerance) instead of substring checks; apply the same fix
for the other occurrences noted (the assertions around lines ~126-127 and
~188-191) so tests validate correct date grounding and timezone shape rather
than static hard-coded ranges.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: bac4c99d-72d3-4728-acbd-f8b3321cecd0
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (6)
src/openhuman/agent/agents/morning_briefing/prompt.rssrc/openhuman/agent/agents/orchestrator/prompt.rssrc/openhuman/agent/agents/planner/prompt.rssrc/openhuman/agent/harness/subagent_runner/ops.rssrc/openhuman/agent/harness/subagent_runner/ops_tests.rstests/calendar_grounding_e2e.rs
| let now = chrono::Local::now(); | ||
| let now_str = format!( | ||
| "Current Date & Time: {} ({})", | ||
| now.format("%Y-%m-%d %H:%M:%S"), | ||
| now.format("%Z") | ||
| ); |
There was a problem hiding this comment.
Include numeric UTC offset in the injected temporal context.
Line [567] currently carries only timezone abbreviation, which can be ambiguous (and occasionally empty on some hosts). For timezone-sensitive calendar queries, include an explicit offset in the injected string.
Suggested update
let now = chrono::Local::now();
let now_str = format!(
- "Current Date & Time: {} ({})",
+ "Current Date & Time: {} ({} / UTC{:+03}:{:02})",
now.format("%Y-%m-%d %H:%M:%S"),
- now.format("%Z")
+ now.format("%Z"),
+ now.offset().local_minus_utc() / 3600,
+ (now.offset().local_minus_utc().abs() % 3600) / 60
);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| let now = chrono::Local::now(); | |
| let now_str = format!( | |
| "Current Date & Time: {} ({})", | |
| now.format("%Y-%m-%d %H:%M:%S"), | |
| now.format("%Z") | |
| ); | |
| let now = chrono::Local::now(); | |
| let now_str = format!( | |
| "Current Date & Time: {} ({} / UTC{:+03}:{:02})", | |
| now.format("%Y-%m-%d %H:%M:%S"), | |
| now.format("%Z"), | |
| now.offset().local_minus_utc() / 3600, | |
| (now.offset().local_minus_utc().abs() % 3600) / 60 | |
| ); |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/openhuman/agent/harness/subagent_runner/ops.rs` around lines 565 - 570,
The injected temporal string currently uses only the timezone abbreviation via
now.format("%Z"), which can be ambiguous or empty; change the formatting in the
creation of now_str (the code around chrono::Local::now() and now_str) to
include the numeric UTC offset (e.g., use format specifier %:z or %z) — for
example combine now.format("%Y-%m-%d %H:%M:%S"), now.format("%Z"), and
now.format("%:z") so the string contains both the abbreviation and an explicit
numeric offset.
Summary
orchestrator,morning_briefing, andplannersystem prompts to includerender_datetime.subagent_runnerto inject current date/time into sub-agent user message context, preserving KV cache stability while providing temporal grounding.Problem
When users asked relative calendar queries (e.g., "can you list out how my week looks"), the agent would often pull events from January or other incorrect months because it lacked knowledge of the current date and time.
Solution
The fix provides explicit temporal context to the agents.
integrations_agent), which are frequently spawned and benefit from prefix caching, the date/time is injected into the initial user message. This allows the system prompt to remain byte-stable across spawns while still giving the agent the necessary grounding.Submission Checklist
orchestrator/prompt.rsandsubagent_runner/ops_tests.rs.tests/calendar_grounding_e2e.rscovering both orchestrator and integrations_agent grounding.Impact
Improves the reliability of calendar and scheduling tasks by ensuring the agent accurately interprets relative time expressions.
Related
Summary by CodeRabbit
Release Notes
New Features
Tests