You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python: Fix file_search citations breaking assistant history roundtrip (microsoft#5557)
* Python: Fix file_search citations breaking assistant history roundtrip
The Responses API rejects 'input_file' inside an assistant message, but the
SDK was emitting it whenever an assistant Message contained a hosted_file
content (which is what file_search citations become). Three coordinated fixes:
1. _prepare_content_for_openai now skips hosted_file for the assistant role
instead of mapping to input_file (which the API rejects there).
2. The streaming response.output_text.annotation.added handler attaches
file_citation, container_file_citation, and file_path as annotations on
text content, matching the non-streaming path. Previously streaming
produced standalone HostedFileContent items that always tripped (1).
3. output_text serialization preserves Annotation objects on roundtrip via a
new _annotations_to_output_text helper instead of hardcoding 'annotations'
to []. file_search citations now survive multi-agent forwarding.
Closesmicrosoft#5556.
* Address PR review
- _annotations_to_output_text: fan out one entry per annotated_region for
url_citation/container_file_citation (Annotation.annotated_regions is a
Sequence; the API form carries one start/end per entry).
- Validate region span bounds are ints before emitting; skip otherwise.
- Add test for the file_path branch (annotation with file_id only).
- Add test verifying streamed citation events coalesce onto surrounding
text via _finalize_response so span indices reference the merged text,
not the empty-text streaming carrier.
0 commit comments