Skip to content

Fix: calendar events#1004

Merged
senamakel merged 3 commits into
tinyhumansai:mainfrom
YellowSnnowmann:fix/calendar-events
Apr 29, 2026
Merged

Fix: calendar events#1004
senamakel merged 3 commits into
tinyhumansai:mainfrom
YellowSnnowmann:fix/calendar-events

Conversation

@YellowSnnowmann
Copy link
Copy Markdown
Contributor

@YellowSnnowmann YellowSnnowmann commented Apr 28, 2026

Summary

  • Grounded agents in current temporal context by including date/time in prompts.
  • Updated orchestrator, morning_briefing, and planner system prompts to include render_datetime.
  • Enhanced subagent_runner to inject current date/time into sub-agent user message context, preserving KV cache stability while providing temporal grounding.
  • Ensured host local timezone is respected.

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.

  • For main agents where KV cache stability is less critical than immediate grounding, the date/time is added to the system prompt.
  • For sub-agents (like 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

  • Unit tests — Added tests to orchestrator/prompt.rs and subagent_runner/ops_tests.rs.
  • E2E / integration — Added tests/calendar_grounding_e2e.rs covering both orchestrator and integrations_agent grounding.
  • Doc comments — Updated module headers where appropriate.

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

    • Agents now automatically include current date and time context in all prompts, enabling more accurate temporal awareness for scheduling and time-sensitive responses.
  • Tests

    • Added comprehensive test coverage to verify datetime context is properly integrated across all agent types and execution flows.

google-labs-jules Bot and others added 2 commits April 28, 2026 13:49
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>
@YellowSnnowmann YellowSnnowmann requested a review from a team April 28, 2026 15:14
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 28, 2026

📝 Walkthrough

Walkthrough

The PR injects current date/time context into multiple agent prompts and the subagent execution harness. Morning briefing, orchestrator, and planner prompts now invoke render_datetime(ctx) during assembly. The subagent runner additionally injects a formatted temporal string using chrono::Local::now(). New unit and e2e tests verify datetime context inclusion in generated prompts.

Changes

Cohort / File(s) Summary
Agent Prompt Builders
src/openhuman/agent/agents/morning_briefing/prompt.rs, src/openhuman/agent/agents/orchestrator/prompt.rs, src/openhuman/agent/agents/planner/prompt.rs
Import render_datetime(ctx) and conditionally append rendered datetime section (trimmed with double newline) into system prompt assembly. Orchestrator includes new unit test validating datetime presence.
Subagent Runner
src/openhuman/agent/harness/subagent_runner/ops.rs, src/openhuman/agent/harness/subagent_runner/ops_tests.rs
Inject always-present "Current Date & Time" temporal context into user messages using chrono::Local::now(). New test validates prompt composition includes datetime marker.
E2E Test Suite
tests/calendar_grounding_e2e.rs
New test file with mock calendar Provider/Tool implementations. Tests verify system/user prompts include "Current Date & Time" context; validates integrations_agent execution includes datetime context.

Possibly related issues

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hark! The datetime flows through prompts anew,
No more shall calendars miss what's true,
From dawn to dusk, each agent shall see—
The current time zone, wild and free! 🕐✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.38% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Fix: calendar events' is vague and generic; while it relates to the changeset, it does not clearly convey the specific nature of the fix (temporal grounding for correct date handling in calendar queries). Consider a more descriptive title such as 'Fix: add temporal grounding to agents for correct calendar queries' to better summarize the main change.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR addresses the core issue #987 by adding temporal grounding (current date/time) to agent system prompts and sub-agent user messages, with unit and E2E tests validating the implementation.
Out of Scope Changes check ✅ Passed All changes directly support the objective of fixing calendar event retrieval through temporal context; no unrelated modifications were introduced.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 & Time so 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1a25f5b and 3893b3f.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • src/openhuman/agent/agents/morning_briefing/prompt.rs
  • src/openhuman/agent/agents/orchestrator/prompt.rs
  • src/openhuman/agent/agents/planner/prompt.rs
  • src/openhuman/agent/harness/subagent_runner/ops.rs
  • src/openhuman/agent/harness/subagent_runner/ops_tests.rs
  • tests/calendar_grounding_e2e.rs

Comment on lines +565 to +570
let now = chrono::Local::now();
let now_str = format!(
"Current Date & Time: {} ({})",
now.format("%Y-%m-%d %H:%M:%S"),
now.format("%Z")
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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.

Suggested change
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.

@senamakel senamakel merged commit cf89552 into tinyhumansai:main Apr 29, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix calendar tool returning wrong month events for current-week queries

2 participants