Skip to content

fix: inject date/time context into all agent prompts#701

Closed
glifocat wants to merge 1 commit into
nanocoai:mainfrom
glifocat:upstream/fix-dateprefix
Closed

fix: inject date/time context into all agent prompts#701
glifocat wants to merge 1 commit into
nanocoai:mainfrom
glifocat:upstream/fix-dateprefix

Conversation

@glifocat
Copy link
Copy Markdown
Collaborator

@glifocat glifocat commented Mar 4, 2026

Type of Change

  • Skill - adds a new skill in .claude/skills/
  • Fix - bug fix or security fix to source code
  • Simplification - reduces or simplifies source code

Description

Fixes #698

Prepends [Current date and time: YYYY-MM-DDTHH:MM:SS (DayOfWeek)] to every agent prompt via a datePrefix() helper. LLMs cannot reliably calculate day of week from ISO timestamps alone, causing incorrect answers to time-sensitive questions.

@thinklikeadesigner
Copy link
Copy Markdown

good idea

Copy link
Copy Markdown
Collaborator

@gavrielc gavrielc left a comment

Choose a reason for hiding this comment

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

Small readability nit below.

Comment thread src/index.ts
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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:

  1. 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"

  1. 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

  2. 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

  3. 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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@gavrielc Thanks! I've commited the changes based on your feeback.

Copy link
Copy Markdown
Collaborator

@gavrielc gavrielc left a comment

Choose a reason for hiding this comment

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

@glifocat Thanks for another great contribution. The fix to add time context to scheduled tasks is needed. Changes to src/index should be reverted as explained in the comment.

@TomGranot
Copy link
Copy Markdown
Collaborator

This relates to #698. If you update based on the review feedback, please add Closes #698 to the description.

@Andy-NanoClaw-AI Andy-NanoClaw-AI added PR: Fix Bug fix Status: Blocked Blocked by merge conflicts or dependencies labels Mar 5, 2026
@glifocat
Copy link
Copy Markdown
Collaborator Author

glifocat commented Mar 5, 2026

Thank you both @TomGranot @gavrielc ! I've replied with why I think we should leave day of the week in. Hope it makes sense!

klapom added a commit to klapom/nanoclaw that referenced this pull request Mar 5, 2026
…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>
@glifocat glifocat force-pushed the upstream/fix-dateprefix branch from 6ab9e9a to 8f45922 Compare March 6, 2026 13:44
@glifocat glifocat force-pushed the upstream/fix-dateprefix branch from 8f45922 to f623e0b Compare March 7, 2026 17:31
@Andy-NanoClaw-AI
Copy link
Copy Markdown

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! 🙌

@Andy-NanoClaw-AI Andy-NanoClaw-AI added the Status: Pending Closure PR flagged for closure during triage label Mar 7, 2026
@glifocat glifocat force-pushed the upstream/fix-dateprefix branch from f623e0b to 7c838da Compare March 8, 2026 03:43
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>
@glifocat glifocat force-pushed the upstream/fix-dateprefix branch from 7c838da to a7beb59 Compare March 8, 2026 04:38
@glifocat
Copy link
Copy Markdown
Collaborator Author

glifocat commented Mar 8, 2026

Simplified per feedback — replaced the datePrefix() injection with a one-line change: added weekday: 'short' to the existing formatLocalTime() in src/timezone.ts.

Now timestamps in messages show day of week automatically (e.g. Mon, Jan 1, 2024, 12:00 AM instead of Jan 1, 2024, 12:00 AM). No changes to src/index.ts or src/task-scheduler.ts.

Updated formatting test accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Fix Bug fix Status: Blocked Blocked by merge conflicts or dependencies Status: Pending Closure PR flagged for closure during triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent cannot determine current day of week from ISO timestamps

5 participants