fix: inject date/time context into all agent prompts#701
Conversation
|
good idea |
gavrielc
left a comment
There was a problem hiding this comment.
Small readability nit below.
There was a problem hiding this comment.
We can drop the changes to this file. The agent already gets the date and time in the message timestamps. Currently, those timestamps are in UTC, but that is a bug that is being fixed. We won't have the day of week, but that's an enhancement that might not be necessary, and if it is, can be added to the message timestamps.
There was a problem hiding this comment.
I understand the concern about redundancy, but in practice, the day of the week provides critical semantic context that timestamps alone don't convey effectively to LLMs - and this affects all interactions, not just scheduled tasks.
Real-world examples from my deployment:
- Daily briefing (scheduled task):
The agent generates a morning briefing that includes relevant reminders. Without day-of-week:
• Timestamp: 2026-03-05T08:15:00
• Agent has to calculate: "Is this Tuesday? Does Kid 1 have music class today?"
With day-of-week:
• [Thursday, March 5, 2026, 08:15]
• Agent instantly knows: "Thursday = no music class, mention at-home activities instead"
-
Normal conversation context:
User asks: "What's for dinner today?"
• Without day-of-week: Agent reads timestamp 2026-03-04T19:30:00 , calculates "Wednesday", then looks up Wednesday menu
• With day-of-week: Agent sees "Wednesday" and immediately looks up the correct day in the weekly menu -
Work scheduling context:
User: "Can you help me plan my day?"
• Without day-of-week: Agent parses timestamp, calculates "Wednesday", then knows: no meetings day = more scheduling flexibility
• With day-of-week: Agent sees "Wednesday" and immediately understands the work context -
Autonomous learning tasks:
I have a task that runs daily at 22:00: "Determine today's day of week and execute the corresponding task" (Monday = groceries, Wednesday = activities for 4yo, etc.)
• Without day-of-week: Parse 2026-03-05T22:00:00 → calculate → Thursday → execute task
• With day-of-week: See "Thursday" → execute task
Why this matters:
Day-of-week is semantic information that LLMs naturally understand (weekday routines, business hours, weekend activities, school schedules, meeting-free days). Making them calculate it from timestamps is asking them to do arithmetic when they're optimized for semantic reasoning.
The timestamp fixes you mentioned solve the UTC bug, but they don't solve the semantic clarity problem. Both improvements serve different purposes:
• Accurate timestamps → correct time calculations
• Day of week → semantic understanding of temporal context for every interaction
Proposal: Keep the day-of-week enhancement while your UTC fix proceeds independently. They're complementary, not redundant. The semantic clarity benefits every conversation, not just edge cases.
There was a problem hiding this comment.
Makes sense. Can you take a look at formatting the timestamps already in in the messages to include day of week? This can probably be a one like fix to the existing formatting
There was a problem hiding this comment.
@gavrielc Thanks! I've commited the changes based on your feeback.
|
This relates to #698. If you update based on the review feedback, please add |
|
Thank you both @TomGranot @gavrielc ! I've replied with why I think we should leave day of the week in. Hope it makes sense! |
…res) Bug fixes applied: - nanocoai#636: task-scheduler recalculates next_run before enqueue - nanocoai#655: LIMIT 200 on message queries to prevent OOM - nanocoai#670: rateLimitResetAt field in ContainerOutput interface - nanocoai#694: ANTHROPIC_MODEL passthrough to container env - nanocoai#700: session rotation at 5MB JSONL threshold - nanocoai#701: session retry on corrupted resume (clear + retry) - nanocoai#708: update_task MCP tool in ipc-mcp-stdio - nanocoai#719: outputChain .catch() to prevent group hang - nanocoai#729: fix send_message description (remove incorrect scheduled-task note) - nanocoai#735: datePrefix() injects current date/time into all agent prompts - nanocoai#738: ANTHROPIC_MODEL from .env passed to agent container - nanocoai#746: systemd OnFailure restart prevention logic (container hardening) - nanocoai#751: DM-with-bot JID normalization - nanocoai#754: setOnPipeCallback to reset idle timer on piped messages - nanocoai#756: cursorBeforePipe rollback on container crash Features added: - nanocoai#723: streaming infrastructure (STREAM_TEXT markers, onStreamDelta) - nanocoai#742: container hardening (entrypoint.sh privilege drop, env sanitize) - nanocoai#680: add-cli skill (CLI send binary) - nanocoai#727: add-memory skill extracted to .claude/skills/add-memory/ - nanocoai#744: add-s3-storage skill extracted to .claude/skills/add-s3-storage/ Test fixes: - Mock fs.promises in container-runner.test.ts to prevent real I/O - Add ANTHROPIC_MODEL to config mock - Fix cpSync expectation: { recursive: true, force: true } - Fix isActive() to use state.active instead of state.process - Fix container-runtime error message: Docker → Container runtime Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
6ab9e9a to
8f45922
Compare
8f45922 to
f623e0b
Compare
|
Hey @glifocat 👋 Thank you for this fix — injecting date/time context into agent prompts is genuinely important for correctness! This was already implemented and merged in #691 (timezone-aware context injection), which solved the same problem. There's also a follow-up PR (#799) that further improves timezone handling. We're adding Status: Pending Closure. The spirit of this fix is very much alive in the codebase — thanks for pushing on this! 🙌 |
f623e0b to
7c838da
Compare
Add weekday: 'short' to formatLocalTime() so the agent sees which day messages were sent (e.g. "Mon, Jan 1, 2024, 12:00 AM" instead of "Jan 1, 2024, 12:00 AM"). This replaces the previous datePrefix() approach per reviewer feedback. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
7c838da to
a7beb59
Compare
|
Simplified per feedback — replaced the Now timestamps in messages show day of week automatically (e.g. Updated formatting test accordingly. |
Type of Change
.claude/skills/Description
Fixes #698
Prepends
[Current date and time: YYYY-MM-DDTHH:MM:SS (DayOfWeek)]to every agent prompt via adatePrefix()helper. LLMs cannot reliably calculate day of week from ISO timestamps alone, causing incorrect answers to time-sensitive questions.