#13510: Enable Dynamic Date Injection in System Resolve #12616
docker
agents
stale
Cluster:
System Prompt Enhancements
Summary
This PR updates the system prompt generation logic to include the current user date and time when provided. This ensures the agent has accurate temporal context without needing an additional tool call at the start of every session.
Motivation
Currently, the system prompt only includes the user's timezone but omits the actual date and time to improve prompt cache stability. However, this causes the agent to often guess the wrong date or day of the week, or requires it to run session_status immediately upon startup, which is inefficient.
By injecting the date into the ## Current Date & Time section, we eliminate this friction and ensure the agent always knows "when" it is.
Changes
src/agents/system-prompt.ts
:
Updated
buildTimeSection
to accept and render a userTime string (e.g., "Monday, January 5th, 2026").
Updated
buildAgentSystemPrompt
to pass userTime through to the time section builder.
src/agents/system-prompt.test.ts
:
Removed the test case that explicitly enforced exclusion of the date/time.
Added a new test case validating that userTime is correctly included in the generated prompt.
Verification
Run npx vitest src/agents/system-prompt.test.ts
Verified that the system prompt now contains the Date: line when userTime is provided.
All 30 tests passed.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR changes system prompt generation to optionally inject a user-provided date string into the `## Current Date & Time` section.
Key changes:
- `buildTimeSection` now accepts `userTime` and appends a `Date: ...` line when present (`src/agents/system-prompt.ts`).
- The system prompt tests were updated to assert that the injected date appears when `userTime` is provided, and the prior cache-stability test expectation was removed (`src/agents/system-prompt.test.ts`).
Main issues to address before merge:
- The tests/comments and in-prompt guidance still contain stale/contradictory rationale about *not* injecting date/time for caching, and the `session_status` hint may be wrong when a date is already injected.
- If prompt caching is still a requirement for some flows, there’s currently no guard/flag preventing per-session prompt variability when `userTime` is passed.
<h3>Confidence Score: 3/5</h3>
- This PR is moderately safe to merge, but has clear documentation/guidance contradictions that should be fixed first.
- Core change is small and tested, but it introduces prompt variability and leaves contradictory comments and `session_status` guidance that will cause confusion and likely regress intended caching behavior in flows that rely on stable prompts.
- src/agents/system-prompt.ts, src/agents/system-prompt.test.ts
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#23736: fix(system-prompt): improve prompt cache locality with unique agent ID
by mrx-arafat · 2026-02-22
77.0%
#10836: feat(session_status): include ISO-8601 and Unix timestamps for sche...
by jeanlucthumm · 2026-02-07
76.0%
#15148: auto-reply: add message_time and compact inbound metadata JSON
by detecti1 · 2026-02-13
74.7%
#17624: Fix memory flush YYYY-MM-DD placeholder resolution
by grunt3714-lgtm · 2026-02-16
73.2%
#6017: feat(hooks): add systemPrompt and tools to before_agent_start event
by yajatns · 2026-02-01
72.4%
#11921: feat(hooks): support systemPrompt injection in before_agent_start hook
by jungdaesuh · 2026-02-08
72.4%
#12871: fix: use bash and warn about shell injection (issue #12836)
by ambicuity · 2026-02-09
72.0%
#19716: fix: inject timestamp into channel message agent context (#16442)
by chi777 · 2026-02-18
71.8%
#14602: fix(plugins): hook systemPrompt gets collected then thrown away (#1...
by yinghaosang · 2026-02-12
71.6%
#22705: fix(agents): merge before_agent_start hook systemPrompt into sessio...
by mushuiyu422 · 2026-02-21
71.1%