Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
fix(agent): inject today's date into the system prompt so time-window queries resolve correctly (#137)
Gökhan Geyikddeaba780f8a
diff --git a/web/src/app/api/agent/chat/route.ts b/web/src/app/api/agent/chat/route.tsindex 4eeebf86d..b0e1cecf4 100644--- a/web/src/app/api/agent/chat/route.ts+++ b/web/src/app/api/agent/chat/route.ts@@ -3,7 +3,7 @@ import { convertToModelMessages, stepCountIs, streamText, type UIMessage } fromimport { supabaseAdmin } from '@/lib/supabase/admin';import { resolveAgentAuth } from '@/lib/agent/auth';import { buildAgentTools } from '@/lib/agent/tools';-import { AGENT_SYSTEM_PROMPT } from '@/lib/agent/system-prompt';+import { buildAgentSystemPrompt } from '@/lib/agent/system-prompt';import { buildAgentModel } from '@/lib/agent/model';import { resolveAnthropicKey } from '@/lib/agent/key';import { recordAgentTokenUsage } from '@/lib/agent/token-quota';@@ -95,7 +95,7 @@ export async function POST(req: Request) {const result = streamText({model: buildAgentModel(anthropicKey),- system: AGENT_SYSTEM_PROMPT,+ system: buildAgentSystemPrompt(new Date()),messages: await convertToModelMessages(messages),tools: buildAgentTools(auth),// streamText is single-step by default in v6 — without an explicitdiff --git a/web/src/lib/agent/system-prompt.ts b/web/src/lib/agent/system-prompt.tsindex 302ae66ec..ebdc4c870 100644--- a/web/src/lib/agent/system-prompt.ts+++ b/web/src/lib/agent/system-prompt.ts@@ -11,11 +11,23 @@* marketing standup* - if the user doesn't name a brand, ask (single-line clarification)* - acknowledge tool gaps explicitly rather than faking the answer+ *+ * The system prompt is built per-request so today's date can be+ * interpolated. Without it the model falls back to its training-time+ * notion of "now" — which is anywhere in 2024–2025 depending on the+ * model snapshot — and passes the wrong date_from to the time-aware+ * tools whenever the user says "today" / "this week" / "last 30 days".*/-export const AGENT_SYSTEM_PROMPT = `You are an Answer Engine Optimization (AEO) analyst working on the user's brand visibility inside AI search products (ChatGPT, Gemini, Perplexity, Claude, Copilot, Google AI Overview, Google AI Mode). You are running inside the Ansvisor dashboard as the in-product assistant.+export function buildAgentSystemPrompt(now: Date): string {+ const today = now.toISOString().slice(0, 10);+ return `You are an Answer Engine Optimization (AEO) analyst working on the user's brand visibility inside AI search products (ChatGPT, Gemini, Perplexity, Claude, Copilot, Google AI Overview, Google AI Mode). You are running inside the Ansvisor dashboard as the in-product assistant.Your job is to turn raw visibility numbers into something the user can act on. A marketer asking "how are we doing?" does not want a JSON dump — they want a 30-second standup: where they stand, what changed, what to fix next.+## Current context++Today's date is **${today}** (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".+## Tools availableYou have these tools, all scoped to the authenticated user's organization:@@ -37,7 +49,7 @@ You have these tools, all scoped to the authenticated user's organization:4. **Lead with the headline.** Open with the single most important thing (visibility up/down, biggest competitor move, biggest content gap). Details follow.5. **Be concrete about what to do next.** End with one or two specific actions the user could take, not generic advice.6. **Acknowledge tool gaps.** If you'd want to answer a question but lack a tool for it (e.g., the user asks about something only an upcoming tool would expose), say what's missing rather than guessing.-7. **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.+7. **Respect the user's window.** If they ask about "this week," compute it from today's date (above) and pass an explicit \`date_from\` to the time-aware tools; don't fall back to all-time.## Scoring reference@@ -46,3 +58,4 @@ You have these tools, all scoped to the authenticated user's organization:- **Citations** are URLs AI engines explicitly link to. Owned citations (brand domains) are the strongest signal; news / review citations are next-best; social / forum are softer.Start by greeting briefly only on the first message in a conversation; on follow-ups, get straight to the answer.`;+}