Repository navigation
Python: fix citation issue - #9436
sophia-ramsey wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Citation offsets can be shifted incorrectly, and ordinary streaming introduces quadratic text copying.
2 open findings
What changed in this PR
Preserves citation metadata across the Python hosting boundary so downstream clients can render clickable citations, addressing #9434.
Changes:
- Converts framework citations into Responses annotations.
- Includes annotations in streaming and non-streaming output.
- Adds conversion and response regression tests.
| File | Description |
|---|---|
| python/packages/foundry_hosting/tests/test_responses.py | Tests citation conversion, edge cases, and response consistency. |
| python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py | Converts and propagates citation annotations. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Code coverage overviewLanguages: Python Python / code-coverage/python
View coverage of the 2 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (1 commit(s)): 0da89b5958e8
Model: gpt-5.6-sol
Overview
The review found 3 verified inline finding(s).
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
3 verified findings remained after source verification (3 medium) across 1 file. Details are attached to the affected lines below.
Affected areas: python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py
| cit["snippet"] = citation.cited_text | ||
| if citation.file_id: | ||
| cit["file_id"] = citation.file_id | ||
| cit.setdefault("annotated_regions", []) |
There was a problem hiding this comment.
Just for my own ignorance, why aren't we mapping annotated_regions anymore here?
There was a problem hiding this comment.
In the current code, annotated_regions refers to the information location in the source document, but downstream was being interpreted as the positions in the generated response, so I took it out so it would not be forwarded to the citation. The source locations are still in raw_representation.
There was a problem hiding this comment.
This seems strange to me as well, annotations should be about locations in source documents IIRC, and relying on raw_representation is also not ideal, since those do not survive (de)ser. I also don't know why this change is related to the Foundry Hosting, was the original issue about using Anthropic within FHA?
There was a problem hiding this comment.
I updated the PR to preserve the original Anthropic behavior, but I added a check for "annotated_regions_coordinate_space": "source" to indicate that the annotated_regions refer to the location in the source document instead of locations for the generated response. Does this seem like an appropriate way to handle the citations?
Jose Alvarez (jpalvarezl)
left a comment
There was a problem hiding this comment.
Approve with a small nit
ea1a03c to
63f108a
Compare

Motivation & Context
An internal bug reported that citations were not correctly being propagated with hosted agents. The citation would include the correct filename or source, but would not link to the annotation properly, instead registering as plain text.
Description & Review Guide
ResponsesHostServerto serialize URL and file citation annotations into Responses payloads for both streaming and non-streaming responses, with regression coverage for supported annotation types and edge cases.Related Issue
Fixes #9434
AI Assistance
AI assistance details: Used GPT-5.6 Sol for planning, implementation, and testing
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.