Why citations matter
Including citations on AI responses provides:- Transparency: Users can verify claims and understand the basis for AI responses. This builds trust and allows users to fact-check information independently.
- Source exploration: Citations enable users to dive deeper into topics by accessing original sources. This is particularly valuable for research, learning, and decision-making workflows.
- Attribution: Proper attribution respects content creators and helps users understand which sources informed the AI’s response.
- Audit trails: For enterprise applications, citations provide explicit traceability between LLM responses and the information sources that were consulted when generating them.
How it works
Use message annotations to attach source metadata to AI response messages without modifying the response content:- The agent publishes an AI response as a single message, or builds it incrementally using message appends.
- The agent publishes one or more annotations to attach citations to the response message, each referencing the response message
serial. - Ably automatically aggregates annotations and generates summaries showing total counts and groupings (for example, by source domain name).
- Clients receive citation summaries automatically and can optionally subscribe to individual annotation events for detailed citation data as part of the realtime stream. Alternatively, clients can obtain annotations for a given message via the REST API.
Enable message annotations
Message append functionality requires “Message annotations, updates, deletes and appends” to be enabled in a channel rule associated with the channel. To enable the channel rule:- Go to the Ably dashboard and select your app.
- Navigate to the “Configuration” > “Rules” section from the left-hand navigation bar.
- Choose “Add new rule”.
- Enter a channel name or namespace pattern (for example,
aifor all channels starting withai:). - Select the “Message annotations, updates, deletes and appends” option from the list.
- Click “Create channel rule”.
ai: namespace prefix, which assumes you have configured the rule for ai.
Citation data model
Citations are implemented using message annotations. Each citation includes an annotationtype that determines how citations are aggregated into summaries, and a data payload containing the citation details.
Annotation type
Annotation types determine how annotations are processed and aggregated into summaries. The type is a string of the formatnamespace:summarization_method:
namespaceis a string that logically groups related annotations. For example, usecitationsfor AI response citations.summarization_methodspecifies how annotations are aggregated to produce summaries.
multiple.v1 summarization method for AI response citations. This is well suited for citations because:
- AI responses often reference the same source multiple times, and
multiple.v1counts each citation separately. - Citations can be grouped by source using the
namefield (for example, by domain name), so clients can display “3 citations from wikipedia.org, 2 from nasa.gov”.
citations:multiple.v1.
Annotation data
The annotationdata field can contain any structured data relevant to your citation use case. For example, a citation for a web search result might include:
In this example:
urlis the source URL.titleis the title of the web page.startOffsetis the character position in the response where this citation begins.endOffsetis the character position in the response where the citation ends.snippetis a short excerpt from the source content for preview displays.
Publish citations
Agents create citations by publishing message annotations that reference theserial of the response message:
Subscribe to summaries
Clients can display a summary of the citations attached to a response by using annotation summaries. Clients receive realtime updates to annotation summaries automatically when subscribing to a channel, which are delivered as messages with anaction of message.summary. When using multiple.v1 summarization, counts are grouped by the annotation name.
In the example below, the name is set to the domain name of the citation source, so summaries show counts per domain:
The multiple.v1 summary groups counts by the annotation name, with totals and per-client breakdowns for each group:
When agents publish citations with a clientId, summaries include a per-client count showing how many citations each agent contributed. Citations published by unidentified clients are counted in the totalUnidentified field.
Subscribe to individual citations
To access the full citation data, subscribe to individual annotation events: Each annotation event includes themessageSerial of the response message it is attached to, the name used for grouping in summaries, and the full citation data payload. This data can be used to render clickable source links or attach inline citation markers to specific portions of the response text:
