Citations

How Configent uses Anthropic's native citations API — search_result content blocks, inline citation markers, and the frontend-friendly segments format.


When the agent answers a question, it cites the exact document passages it drew from. The Anthropic API produces citations natively: the model marks the specific text it used, not the whole chunk.


How it works

Citations flow through three layers:

retrieved chunks
  └─ search_result content blocks   → sent to Claude via OpenRouter
        └─ citations in response    → extracted from API response
              └─ segments           → stored in DB + sent to frontend

1. search_result blocks

search_result is the Anthropic content type that enables citation tracking. The graph’s answer node puts the blocks directly in the user message, built by answer_request_kwargs(). See Answering.

The blocks are passed verbatim, never serialized to JSON. The API only enables citation tracking on the search_result content type, not on the same data JSON-stringified into a text block.

2. Anthropic generates citations

With search_result blocks in context, the model annotates its response text with citation markers that reference specific passages from those blocks. This is GA behavior on current Claude models, including the claude-haiku-4-5 model the shipped client runs, with no beta header required.

The attribution is the API’s, not ours. Each citation comes back with its source, title, and a cited_text field. The API decides which block and which span supports each run of the reply. We do no string matching.

One caveat: cited_text is the whole chunk. The API returns the entire matched chunk, often hundreds of tokens. excerpt() in agent/common.py trims it to a ~400-character, sentence-boundary preview before it reaches the frontend.

3. Segments extraction

collect_segments() turns the final response into a segments list, alternating text and cited passages, structured for the frontend:

[
  {
    "text": "That error means the container never listened on the port Cloud Run expects",
    "citations": [
      {
        "source": "corpus://gcp-platform-support/cloud-run-troubleshooting.md",
        "title": "Cloud Run troubleshooting",
        "cited_text": "Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable."
      }
    ]
  },
  {
    "text": ", so the startup probe gave up.",
    "citations": []
  }
]

Linkable sources

A citation’s source is the document’s URL when it has one, else the corpus:// identity. The URL is passed as the search_result source, and the API echoes it back, so there is no extra SSE field.

  • Where the URL comes from: url: in the file’s YAML front matter, else corpus.source_url_template ({stem} and {path}, the relative path without extension), else none.
  • Stored on the document (documents.url), carried on Hit, sent by _hit_dict and answer_request_kwargs. source_uri stays the stable identity that prune and the fingerprint key on.
  • The UI renders a source starting with http:// or https:// as a link (new tab, rel="noopener"), anything else as plain text.
  • The GCP corpus carries title: and url: in front matter, so DeployBot’s citations open the upstream Google Cloud page. The CC BY 4.0 attribution stays in the body.

Segments with empty citations are plain text. Segments with citations render with inline source links in the frontend.


Storage

The assistant message stores the reply in two columns of the messages table:

ColumnContents
contentThe reply text
citations{"segments": [...]}, the frontend-friendly segments list

Reloading a conversation renders straight from segments, with no post-processing.


Empty retrieval

The answering call never runs with zero passages. Both route functions require at least one before they choose answer, so an empty retrieval goes to Level 2, a conversational reply, or a ticket offer. There is no uncited answer to guard against.


Frontend rendering

Citations aren’t delivered whole in done. They stream. As the model emits each one, the answer node turns the API’s citations_delta into a citation SSE event, interleaved with the text deltas:

// citation event payload
{"index": 1, "source": "corpus://gcp-platform-support/cloud-run-troubleshooting.md",
 "title": "Cloud Run troubleshooting", "cited_text": "Container failed to start. Failed to start and then listen on the port..."}
SSE events:  text · text · citation#1 · text · citation#2 · text · done
                    └──────────── frontend folds ───────────┘     (usage only)
segments:    [ {text, citations:[]}, {text, citations:[#1]}, … ]

The frontend rebuilds {text, citations[]} segments from the interleaved stream and renders each inline, with a badge that expands to the source title and cited passage.

Where the segments come from differs by path:

PathSegment assembly
run_turn() (non-streaming)collect_segments() builds the full array in one shot
stream_turn() (SSE)The frontend rebuilds them from citation deltas

Either way, the collect_segments() list lands in the messages.citations column at commit. The done event carries no reply or segments.

See SSE Streaming for the full event contract.