chat(citations=True): cite answers with the server's cited_answer prompt - #496
Merged
Conversation
…hat's format chat(citations=True) makes the answer cite every claim the way PageIndex chat does: <cite doc= page=/> tags, block= added where the cloud document has blocks. Own-model chat over cloud documents fetches the MCP server's cited_answer prompt (format=cite) over the tools' bridge session and folds it into the system prompt after the managed prompt and before the caller's instructions, on all three lanes; the managed chat gets its own enable_citations; local documents get a frozen copy of the same prompt (pages only, local page content carries no blocks), pinned to the live text by a key-gated parity test. client.citation_prompt(format=) exposes the same text for framework-built agents: cite by default, markdown / footnote for hosts that strip tags. Stacks on #494 (bridge prompts/get). Verified live: block documents cite block ids, legacy and local documents cite pages, on the answer lane and both protocol lanes. Claude-Session: https://claude.ai/code/session_01Ex6uKLsDrQjZkqypjSyPwA
The refusal's only exit was dropping the chat model; own-model chat now cites through chat(citations=True), so name it. Also drop an unused return in the citation test helper. Claude-Session: https://claude.ai/code/session_01Ex6uKLsDrQjZkqypjSyPwA
A format name passed as citations= was truthy and silently meant cite; it now raises and names citation_prompt(format=) + instructions=. citation_prompt(format="") returned the server's markdown default while the getter's own default is cite; "" is unset, so it is cite too. That left fetch_citation_prompt's unset fallbacks without a caller, so it now takes the format it is given. The enable_citations refusal's keyless arm still said local mode could not cite; both arms now point at chat(citations=True). The docstrings that route other formats through instructions= say own-model chat only. Claude-Session: https://claude.ai/code/session_01RWo3vKJs6MVMxrfPxEVaxd
…comment chat() reached the citation text through a lazy import of the private fetch_citation_prompt(self, "cite") when the public citation_prompt() getter beside it is exactly that call, so the "cite" default was spelled in two places. chat() now uses the getter; the default lives in its signature only. The comment above LOCAL_CITATION_PROMPTS named the private chat repo and its server-side prompt file. That file ships to PyPI with the package and public code carries only the contract, so the comment keeps what the copy is and why its block rules stay dormant locally. Claude-Session: https://claude.ai/code/session_01XGBdRF2qoTcLNpRahj6QHx
Member
Author
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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.
chat(citations=True)makes the answer cite every claim the way PageIndex chat does:<cite doc="…" page="…"/>tags,block="…"added where the cloud document has blocks. Stacks on #494 (bridgeprompts/get); this PR's diff is the four files on top of it.How it works
cited_answerprompt (format=cite, the rulescitation-contract.tsalso feeds PageIndex chat) over the same bridge session as the tools, and folds it into the system prompt after the managed prompt and before the caller'sinstructions. All three lanes (answer lane,protocol="responses",protocol="messages") via the existing instructions plumbing;local_chat.pyuntouched.citations=Truepassesenable_citations=Trueto the endpoint.LOCAL_CITATION_PROMPTS, generated from the live text minus the one bullet naming the cloud-onlyget_document_image()tool). Local page content carries no blocks, so citations resolve to pages.client.citation_prompt(format="cite")exposes the same text for framework-built agents;markdown/footnoteare the MCP prompt's variants for hosts that strip tags.Verified
<cite doc="document_5.pdf" page="1" block="p1_text_1"/>; legacy document →<cite doc="1706.03762_24.pdf" page="1"/>; locally indexed PDF →<cite doc="q1-fy25-earnings.pdf" page="3"/>; managedcitations=Truenon-stream and stream.Not in this PR
agents.mdx,chat.mdx's hand-written<cite>system message becomescitations=) and a release-notes line, with the release.p1_text_001that the model echoes on legacy documents (resolved citations then carry ablock_idwith nobbox); and agranularityargument oncited_answerwould let the SDK offer page-only citations on block documents.https://claude.ai/code/session_01Ex6uKLsDrQjZkqypjSyPwA