Skip to content

fix(agent): inject today's date into the system prompt - #137

Merged
gkhngyk merged 1 commit into
mainfrom
fix/agent-date-context
May 31, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/agent-date-context

Conversation

@gkhngyk

@gkhngyk gkhngyk commented May 31, 2026 •

Copy link
Copy Markdown
Contributor

Closes #136.

What

AGENT_SYSTEM_PROMPT is now a builder — buildAgentSystemPrompt(now: Date) — and the chat route calls it per turn with new Date(). The interpolated date lands in a new Current context section right after the persona block:

Today's date is YYYY-MM-DD (UTC). When the user says 'today' / 'yesterday' / 'this week' / 'last 30 days' / 'last month', compute the date range from this anchor and pass it as date_from (and date_to when relevant) to the time-aware tools. Never invent a different 'now'.

Why

The previous static prompt left the model to guess 'now' from its training data. claude-sonnet-4-6 typically picked something in 2024–2025, so any window-based question (e.g. "what's today's best prompt?", "how did the trend look last week?") ended up running against a wrong date_from. Rule 7 in the prompt explicitly asked the model to respect the user's window, but without a real anchor it couldn't.

Test plan

  1. Start a new conversation, ask "what was the brand's trend over the last 7 days?"
  2. Watch the get_visibility_trend tool call (expandable via the tool disclosure UI) — date_from should be ~7 days before today's actual date, not a 2024 / 2025 value
  3. Repeat with "today" — should anchor on today

Out of scope

  • Timezone awareness. UTC is enough for v1 because the time-aware tools also bucket in UTC.
  • MCP-server side (Claude Desktop / Cursor users) — separate system message there, separate fix if it ever needs the same treatment.

… queries resolve correctly

Closes #136.

The system prompt was a static const export, so the model had no idea
what 'today' actually was — it filled the blank with its training-time
notion of 'now' and passed wrong date_from values to the time-aware
tools whenever the user said 'this week' / 'last 30 days' / 'today'.

Convert AGENT_SYSTEM_PROMPT into buildAgentSystemPrompt(now: Date) so
the date is interpolated per request. Adds a 'Current context' section
right after the persona block:

  Today's date is **YYYY-MM-DD** (UTC). When the user says
  'today' / 'yesterday' / 'this week' / 'last 30 days' / 'last month',
  compute the date range from this anchor and pass it as date_from
  (and date_to when relevant) to the time-aware tools. Never invent a
  different 'now'.

Rule 7 ('Respect the user's window') was already in the prompt but
unreachable without an anchor; now it has one.

chat/route.ts calls the builder with new Date() per turn — the route
is already dynamic (no Cache Components / no 'use cache' anywhere
near agent paths) so freshness is free.
@gkhngyk
gkhngyk merged commit ddeaba7 into main May 31, 2026
3 checks passed
@gkhngyk
gkhngyk deleted the fix/agent-date-context branch May 31, 2026 15:57
gkhngyk added a commit that referenced this pull request Jun 22, 2026
The Site Audit recommendation prompt never told the model what 'today' is, so
for source-suggesting signals (outbound-authority-links, citation-density,
statistic-density) gemini-3 fell back to its training-data sense of 'now' and
proposed stale (e.g. 2024) references.

Inject today's date (derived from ctx.now) at the top of the prompt and tell the
model to prefer the most recent, currently-authoritative sources and not present
older material as current — plus an explicit 'never invent URLs or fabricate
statistics/dates' guard. Mirrors the date injection the Agent already does (#137).
Display/prompt-only change; signal scoring is untouched.

This branch was successfully deployed

1 active deployment
Preview — 7f5487db Deployed May 31, 2026 by vercel[bot]
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.

feat(agent): inject today's date into the system prompt so time-window questions resolve correctly

1 participant