Skip to content

feat(agents): include current date and day-of-week in system prompt#43304

Open
chengjialu8888 wants to merge 3 commits intoopenclaw:mainfrom
chengjialu8888:feat/system-prompt-current-date
Open

feat(agents): include current date and day-of-week in system prompt#43304
chengjialu8888 wants to merge 3 commits intoopenclaw:mainfrom
chengjialu8888:feat/system-prompt-current-date

Conversation

@chengjialu8888
Copy link
Copy Markdown

Fixes #9899

Summary

  • Problem: Agents frequently get the day of week and date wrong during calendar/scheduling tasks because the system prompt only contains the timezone, not the actual date.
  • Why it matters: Users rely on agents for scheduling, and wrong day-of-week responses erode trust. This is the most upvoted time-related issue with 14 comments.
  • What changed: Added a cache-stable currentDate field (e.g., "Wednesday, March 12, 2026") to the system prompt, computed via Intl.DateTimeFormat in the user's timezone.

Cache Stability

Previous PRs (#32586, #40199) were rejected because injecting time into the system prompt breaks prefix caching. This PR only injects the date (no time component), which changes once per calendar day — preserving ~24h cache windows while solving the day-of-week problem.

Approach Changes every Cache impact
Current (timezone only) Never None
PR #32586 (full time) Every minute Cache destroyed
This PR (date only) Once per day Minimal

Changes

  • src/agents/system-prompt-params.ts — Added currentDate field using Intl.DateTimeFormat with weekday+date (no time)
  • src/agents/system-prompt.ts — Updated buildTimeSection() to render currentDate above the timezone line

Output

## Current Date & Time
Wednesday, March 12, 2026
Time zone: America/New_York

Testing

  • Backward compatible: currentDate is optional; omitting it produces identical output to before
  • Intl.DateTimeFormat is stable across Node.js versions
  • Date changes only at midnight in the user's timezone

Changelog

Updated.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 11, 2026

Greptile Summary

This PR attempts to inject the current date (with weekday) into the agent system prompt to fix incorrect day-of-week responses during scheduling tasks. The approach — computing a date string via Intl.DateTimeFormat and inserting it into buildTimeSection — is well-designed and cache-friendly. However, there is a critical wiring bug that makes the feature a no-op in its current state.

Key issues found:

  • Critical — feature never activates: buildAgentSystemPrompt's parameter type (lines 195–242 of system-prompt.ts) was not extended with a currentDate field. The expression params.currentDate at line 573 therefore always resolves to undefined, meaning buildTimeSection never receives the date string and the rendered prompt is identical to before. In strict TypeScript this would be a compile error.
  • Stale hint creates redundant tool calls: The instruction on line 513–515 telling agents to call session_status for the current date/day-of-week should be conditioned on currentDate being absent; otherwise agents will make an unnecessary tool call for information already present in the prompt.

Confidence Score: 2/5

  • Not safe to merge — the core feature is wired incorrectly and will silently do nothing.
  • The currentDate computation in system-prompt-params.ts is correct, but the value is never plumbed into buildAgentSystemPrompt because the function's parameter type was not updated to include the field. As a result the PR ships no functional change. The secondary issue (stale session_status hint) is a usability concern once the wiring is fixed.
  • src/agents/system-prompt.ts — buildAgentSystemPrompt parameter type must be extended with currentDate?: string

Comments Outside Diff (1)

  1. src/agents/system-prompt.ts, line 513-515 (link)

    Stale session_status hint contradicts the new behaviour

    This line tells the agent to call session_status whenever it needs the current date or day of week — but the whole purpose of this PR is to supply that information directly in the system prompt. Once currentDate is properly forwarded (see the other comment), retaining this hint will cause agents to make an unnecessary tool call for information they already have.

    Consider guarding the hint so it only appears when currentDate is not present:

    This keeps backward compatibility for callers that don't supply currentDate while avoiding the redundant instruction when the date is already injected.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/agents/system-prompt.ts
    Line: 513-515
    
    Comment:
    **Stale `session_status` hint contradicts the new behaviour**
    
    This line tells the agent to call `session_status` whenever it needs the current date or day of week — but the whole purpose of this PR is to supply that information directly in the system prompt. Once `currentDate` is properly forwarded (see the other comment), retaining this hint will cause agents to make an unnecessary tool call for information they already have.
    
    Consider guarding the hint so it only appears when `currentDate` is *not* present:
    
    
    
    This keeps backward compatibility for callers that don't supply `currentDate` while avoiding the redundant instruction when the date is already injected.
    
    How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: 1a0ca55

Comment on lines 570 to 574
...buildUserIdentitySection(ownerLine, isMinimal),
...buildTimeSection({
userTimezone,
currentDate: params.currentDate,
}),
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.

currentDate never forwarded — feature is silently broken

buildAgentSystemPrompt's parameter type (lines 195–242) does not declare a currentDate field. Accessing params.currentDate here will always yield undefined (or a TypeScript compile error in strict mode), so buildTimeSection will never receive the date string and the output will be identical to the pre-PR behavior.

The param type needs to be extended:

Suggested change
...buildUserIdentitySection(ownerLine, isMinimal),
...buildTimeSection({
userTimezone,
currentDate: params.currentDate,
}),
...buildTimeSection({
userTimezone,
currentDate: params.currentDate,
}),

And the function signature must also include the new field, for example:

export function buildAgentSystemPrompt(params: {
  // ... existing fields ...
  currentDate?: string;
  // ...
}) {

Without this, the entire feature is a no-op.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/system-prompt.ts
Line: 570-574

Comment:
**`currentDate` never forwarded — feature is silently broken**

`buildAgentSystemPrompt`'s parameter type (lines 195–242) does not declare a `currentDate` field. Accessing `params.currentDate` here will always yield `undefined` (or a TypeScript compile error in strict mode), so `buildTimeSection` will never receive the date string and the output will be identical to the pre-PR behavior.

The param type needs to be extended:

```suggestion
    ...buildTimeSection({
      userTimezone,
      currentDate: params.currentDate,
    }),
```

And the function signature must also include the new field, for example:

```ts
export function buildAgentSystemPrompt(params: {
  // ... existing fields ...
  currentDate?: string;
  // ...
}) {
```

Without this, the entire feature is a no-op.

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1a0ca55afe

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

userTimezone,
userTime,
userTimeFormat,
currentDate,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Thread currentDate through system prompt builders

currentDate is computed and returned here, but it is never propagated in the main prompt construction paths, so the new date/day-of-week line never appears at runtime. In all buildSystemPromptParams consumers, the destructuring still omits this field (src/auto-reply/reply/commands-system-prompt.ts:85, src/agents/cli-runner/helpers.ts:60, src/agents/pi-embedded-runner/run/attempt.ts:975), which leaves params.currentDate undefined when buildTimeSection renders the prompt. This makes the fix effectively a no-op for users relying on scheduling/date context.

Useful? React with 👍 / 👎.

@openclaw-barnacle openclaw-barnacle bot added agents Agent runtime and tooling size: XS labels Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Include day of week in system prompt date/time injection

1 participant