Skip to content

feat(agent): use Site Audit from the in-product assistant - #307

Merged
gkhngyk merged 1 commit into
mainfrom
feature/agent-site-audit
Jun 27, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feature/agent-site-audit

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Lets the in-product AI assistant (/dashboard/agent) run and read Site Audits in chat — e.g. "audit my homepage" → it triggers an audit, polls for completion, then summarizes the score, weak categories, and the top AI-written fixes.

Pure wiring: the agent keeps its own tool registry (buildAgentTools in web/src/lib/agent/tools.ts) that wraps the shared web/src/lib/mcp/data.ts functions, with names matching the MCP tool ids. This PR reuses the site-audit data functions landed in #269/#270 (runSiteAuditFor, getSiteAuditFor, listSiteAuditsFor) the same way the agent already reuses getVisibilitySummaryFor — no aggregation logic is duplicated, and ownership/quota stay server-side.

Changes

  • web/src/lib/agent/tools.ts — register three tools:
    • run_site_audit (brand_id, url) — write: triggers an audit, returns status: "running". Consumes one of the org's monthly Site Audit credits (shared pool with the dashboard).
    • get_site_audit (audit_id) — read: status + total/category scores + signals + AI recommendations.
    • list_site_audits (brand_id) — read: recent audits to find one by url/date.
  • web/src/lib/agent/system-prompt.ts — add the three tools to the "Tools available" list, plus a rule that run_site_audit is a credit-spending write: only fire on explicit user intent, then poll get_site_audit until completed and summarize score / weak categories / top fixes; relay the quota-limit message instead of retrying. (The chat loop already multi-steps via stepCountIs(20), so trigger → poll → summarize completes in one turn.)

Related issue

Closes #271

Type of change

  • feat — New feature

How to test

In the dashboard chat (/dashboard/agent):

  1. "Audit https://example.com/page for " → the assistant calls run_site_audit, polls get_site_audit, and reports the total score, weakest categories, and top AI fixes.
  2. It does not audit unprompted during exploratory questions (e.g. "how is my brand doing?" uses only the read tools).
  3. When the monthly audit credits are exhausted, the assistant relays the limit/upgrade message rather than retrying.
  4. "Show my recent audits for " → list_site_audits, no credit consumed.

Checklist

  • Branch follows the naming convention (feature/)
  • Commits follow Conventional Commits
  • yarn typecheck, eslint, prettier --check pass on changed files
  • Changes are focused — one concern per PR

Wire the three site-audit data functions (from #269/#270) into the in-product
agent's tool registry so the chat can run and read audits:

- run_site_audit (write — spends a monthly Site Audit credit), get_site_audit
  and list_site_audits (reads) added to buildAgentTools, reusing
  runSiteAuditFor / getSiteAuditFor / listSiteAuditsFor with the same
  McpAuthContext scoping as the other agent tools.
- system-prompt: list the three tools and add a rule that run_site_audit is a
  credit-spending write — only fire on explicit user intent, then poll
  get_site_audit until completed and summarize score / weak categories / top
  fixes; relay the quota-limit message instead of retrying.

Closes #271
@gkhngyk
gkhngyk merged commit 757d9ed into main Jun 27, 2026
4 checks passed
@gkhngyk
gkhngyk deleted the feature/agent-site-audit branch June 27, 2026 12:04
@gkhngyk gkhngyk mentioned this pull request Jul 6, 2026
5 tasks done
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): use Site Audit from the in-product assistant

1 participant