Skip to content

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

Closed

Description

@gkhngyk

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:

  1. Respect the user's window. If they ask about "this week," pass an explicit date_from to 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:

  1. Convert AGENT_SYSTEM_PROMPT into a buildAgentSystemPrompt(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.
    
  2. 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 in YYYY-MM-DD form
  • chat/route.ts calls the builder per turn with new Date()
  • Asking the agent "what was visibility this week" passes a date_from within 7 days of the real today, not 2024 / 2025
  • pnpm tsc --noEmit clean

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

  1. added a commit that references this issue on May 31, 2026
    ddeaba7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions