Repository navigation
feat(agent): add source_filter to list_citations so the assistant can isolate owned/competitor citations - #311
Merged
Conversation
…ternal) The assistant could not isolate a brand's own cited URLs — list_citations classified each citation by source but exposed no way to filter on it, so 'which of OUR URLs did AI cite?' returned a mixed report. Add a source_filter param (all | owned | competitor | external) resolved against the category listCitationsFor already computes, before aggregation. totals / source_type_breakdown / top_domains / top_urls are recomputed over the filtered set. 'all' is the default and takes the original code path, so its output is byte-identical (no regression). Wired through the agent tool, the MCP tool, and the REST parity route; the system prompt nudges the agent to pass source_filter='owned' for owned-URL questions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The in-product assistant couldn't isolate a brand's own cited URLs.
list_citationsalready classifies every citation by source (you/competitor/ editorial / forum / social / review / …) but exposed no parameter to filter on that classification, sotop_domains/top_urlscame back mixed and the model had no clean way to answer "which of our URLs did AI cite?".Change — add a
source_filterparameter tolist_citations:owned— only citations on the brand's own domains (categoryyou)competitor— only tracked-competitor domainsexternal— everything else (editorial / forum / social / review / institutional / other)all— no filter (default, backward compatible)The filter is applied inside
listCitationsFor()against thecategoryit already computes — no new query or classification logic.totals,source_type_breakdown,top_domains, andtop_urlsare recomputed over the filtered set, andresults_with_citationsonly counts results that contribute a matching citation. Theallpath skips the matcher entirely and takes the original code path, so its output is byte-identical to before.Surfaces wired (kept in parity):
web/src/lib/agent/tools.ts— agent tool schema + descriptionweb/src/lib/mcp/server.ts— MCPlist_citationstoolweb/src/lib/mcp/data.ts—listCitationsFor()filtering +CitationSourceFiltertypeweb/src/app/api/mcp/citations/route.ts— REST parity (?source_filter=, validated)web/src/lib/agent/system-prompt.ts— nudges the agent to passsource_filter: "owned"for owned-URL questionsRelated issue
Closes #297
Type of change
feat— New featureHow to test
list_citationswithsource_filter: "owned"and the response lists only owned-domain URLs.source_filter: "competitor"returns only competitor-domain citations;"external"returns neither.source_filter(or"all") reproduces today's output exactly.top_urlsinstead of a generic list.GET /api/mcp/citations?brand_id=…&source_filter=owned; an invalid value returns400.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)