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
feat(agent): use Site Audit from the in-product assistant (#307)
Gökhan Geyik757d9edf15d5
diff --git a/web/src/lib/agent/system-prompt.ts b/web/src/lib/agent/system-prompt.tsindex 9a9cf6324..2bac2e330 100644--- a/web/src/lib/agent/system-prompt.ts+++ b/web/src/lib/agent/system-prompt.ts@@ -41,6 +41,9 @@ You have these tools, all scoped to the authenticated user's organization:- **list_prompts** — prompts being tracked for a brand. Use when the user asks what is being tracked or wants to drill into a specific topic.- **get_prompt_performance** — aggregates performance (average visibility, total mentions, citations, appearances, and competitor score) grouped by prompt over a date range. Use to answer questions like "what is the best-performing prompt today?" or "which prompts dropped this week?".- **list_content_opportunities** — content gaps for a brand sorted by opportunity score. Use for "what should I write?" questions.+- **run_site_audit** — run a Site Audit (AEO/GEO page score + AI fix recommendations) for a URL under a brand. Returns immediately with status "running"; poll get_site_audit for the result. **This is a write that spends one of the org's monthly Site Audit credits** — only run it when the user explicitly asks to audit a page.+- **get_site_audit** — read a Site Audit's result (status, total + per-category scores, signals, AI fix recommendations) by id. No credit consumed.+- **list_site_audits** — list a brand's recent audits (id, url, status, score, date) to find a past one by url/date. No credit consumed.- **render_chart** — render a chart inline in the chat (line / bar / pie). Call this *after* a data tool when the answer is meaningfully easier to read as a chart than as a sentence. See "Visualization" below.## Visualization (render_chart)@@ -66,6 +69,7 @@ Hard rules: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," 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.+8. **run_site_audit spends a credit — only on explicit intent.** Treat \`run_site_audit\` as a write: call it only when the user explicitly asks to audit a specific page/URL, never as part of exploratory analysis or unprompted. To audit, call \`run_site_audit\`, then poll \`get_site_audit\` with the returned id until status is "completed", then summarize the total score, the weakest categories, and the top AI-written fixes. If the run returns a quota/limit message (monthly audit credits exhausted), relay that message to the user instead of retrying.## Scoring referencediff --git a/web/src/lib/agent/tools.ts b/web/src/lib/agent/tools.tsindex ce1de53e4..4c4eadb20 100644--- a/web/src/lib/agent/tools.ts+++ b/web/src/lib/agent/tools.ts@@ -12,6 +12,9 @@ import {listPromptsFor,listTopicsFor,getPromptPerformanceFor,+ runSiteAuditFor,+ getSiteAuditFor,+ listSiteAuditsFor,} from '@/lib/mcp/data';/**@@ -198,6 +201,34 @@ export function buildAgentTools(auth: McpAuthContext) {}),}),+ run_site_audit: tool({+ description:+ 'Run a Site Audit (AEO/GEO page score + AI fix recommendations) for a page URL under a brand. WARNING: this consumes one of the org\'s monthly Site Audit credits (shared with the dashboard) and runs asynchronously (~30s). It returns the new audit id with status "running" — then call get_site_audit with that id until status is "completed" (or "failed") to read the result. Only run on explicit user intent to audit a specific URL; never audit unprompted.',+ inputSchema: z.object({+ brand_id: z.string().uuid(),+ url: z.string().url(),+ }),+ execute: async (args) => runSiteAuditFor(auth, args.brand_id, args.url),+ }),++ get_site_audit: tool({+ description:+ 'Fetch a Site Audit by id — status, total score, per-category scores, evaluated signals, and AI fix recommendations. Use after run_site_audit to poll for the result: while status is "running" the scores are not yet populated; once "completed" (or "failed") the full result is available. Read — no credit consumed.',+ inputSchema: z.object({+ audit_id: z.string().uuid(),+ }),+ execute: async (args) => getSiteAuditFor(auth, args.audit_id),+ }),++ list_site_audits: tool({+ description:+ "List a brand's recent Site Audits (newest first) — id, url, status, total score, signals, and created date. Use to find a past audit by url/date (then read it with get_site_audit) without needing the id. Read — no credit consumed.",+ inputSchema: z.object({+ brand_id: z.string().uuid(),+ }),+ execute: async (args) => listSiteAuditsFor(auth, args.brand_id),+ }),+render_chart: tool({description:'Render a chart inline in the chat. Call this AFTER you have the data from another tool (e.g. get_visibility_trend, get_competitor_comparison, list_citations) and you want to visualize it. Pick the chart type: "line" for time series (trends over dates), "bar" for cross-entity comparisons (brand vs competitors, source-type breakdown), "pie" for share-of-X distributions. Pass the data array straight from the previous tool result — never invent or reformat numbers. The tool just echoes the spec back; the UI renders the chart.',