Repository navigation
Description
Problem
The in-product agent doesn't know what day it is. When a user asks "bugünün en iyi promptu" / "what's the best prompt today" / "how did visibility change this week", the model fills the blank with its training-time notion of "now" — currently anywhere in 2024–2025 depending on what the LLM internally guessed. It then passes a wrong date_from to the time-aware tools (get_visibility_summary, get_visibility_trend, list_citations) and writes confident-sounding analysis on top of a stale or empty window.
The system prompt in web/src/lib/agent/system-prompt.ts is exported as a static string with no date interpolation:
export const AGENT_SYSTEM_PROMPT = `You are an Answer Engine Optimization (AEO) analyst ...`;And web/src/app/api/agent/chat/route.ts:98 hands it to streamText verbatim:
const result = streamText({
model: buildAgentModel(anthropicKey),
system: AGENT_SYSTEM_PROMPT,
...
});Ironic side effect — the prompt itself already has a rule about windows:
- Respect the user's window. If they ask about "this week," pass an explicit
date_fromto the time-aware tools; don't fall back to all-time.
The model can't follow that rule without knowing what week it is.
Fix
Inject today's date (UTC) into the system prompt at request time. Two-line change:
-
Convert
AGENT_SYSTEM_PROMPTinto abuildAgentSystemPrompt(now: Date)function that interpolates the date into a "Current context" section:## Current context Today's date: 2026-05-31 (UTC). When the user says "today" / "yesterday" / "this week" / "last 30 days", compute the date range from this anchor. Pass it as `date_from` (and `date_to` when relevant) to the time-aware tools. -
Call it from
chat/route.ts:system: buildAgentSystemPrompt(new Date()),
Optional follow-ups
- Pass the org's region / timezone alongside the date, once we have it on the request. UTC date is fine for v1 because the data tools also use UTC date ranges.
- Mirror the same date injection in the MCP standalone server's system message if it has one, so Claude Desktop / Cursor users get the same fix.
Acceptance criteria
-
buildAgentSystemPrompt(now)interpolates today's date inYYYY-MM-DDform -
chat/route.tscalls the builder per turn withnew Date() - Asking the agent "what was visibility this week" passes a
date_fromwithin 7 days of the real today, not 2024 / 2025 -
pnpm tsc --noEmitclean
Out of scope
- Localized date formatting in the prompt. The model receives an ISO date; how it renders the date to the user is up to the model.
- Persisting a "user timezone" field. UTC is enough for v1.
Activity
fix(agent): inject today's date into the system prompt so time-window…