From b6c9fade08ba27b65c88fe55d45339cc796c63ea Mon Sep 17 00:00:00 2001 From: Yufeng He <40085740+he-yufeng@users.noreply.github.com> Date: Fri, 22 May 2026 23:26:58 +0800 Subject: [PATCH 1/2] fix: keep citation get_url metadata --- .../packages/openai/agent_framework_openai/_chat_client.py | 5 ++++- .../packages/openai/tests/openai/test_openai_chat_client.py | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/python/packages/openai/agent_framework_openai/_chat_client.py b/python/packages/openai/agent_framework_openai/_chat_client.py index 8257678584..226f66e500 100644 --- a/python/packages/openai/agent_framework_openai/_chat_client.py +++ b/python/packages/openai/agent_framework_openai/_chat_client.py @@ -2880,11 +2880,14 @@ def _get_ann_value(key: str) -> Any: if ann_url: ann_start = _get_ann_value("start_index") ann_end = _get_ann_value("end_index") + additional_properties: dict[str, Any] = {"annotation_index": event.annotation_index} + if ann_get_url := _get_ann_value("get_url"): + additional_properties["get_url"] = ann_get_url annotation_obj = Annotation( type="citation", title=_get_ann_value("title") or "", url=str(ann_url), - additional_properties={"annotation_index": event.annotation_index}, + additional_properties=additional_properties, raw_representation=annotation, ) if ann_start is not None and ann_end is not None: diff --git a/python/packages/openai/tests/openai/test_openai_chat_client.py b/python/packages/openai/tests/openai/test_openai_chat_client.py index 31c3c26fe0..31a90c2f1d 100644 --- a/python/packages/openai/tests/openai/test_openai_chat_client.py +++ b/python/packages/openai/tests/openai/test_openai_chat_client.py @@ -3410,6 +3410,7 @@ def test_streaming_annotation_added_with_url_citation() -> None: mock_event.annotation = { "type": "url_citation", "url": "https://example.sharepoint.com/sites/my-site/doc.pdf", + "get_url": "https://example.search.windows.net/indexes/docs/documents/doc-123?api-version=2024-07-01", "title": "doc.pdf", "start_index": 100, "end_index": 112, @@ -3427,6 +3428,10 @@ def test_streaming_annotation_added_with_url_citation() -> None: assert annotation["title"] == "doc.pdf" assert annotation["url"] == "https://example.sharepoint.com/sites/my-site/doc.pdf" assert annotation["additional_properties"]["annotation_index"] == 0 + assert ( + annotation["additional_properties"]["get_url"] + == "https://example.search.windows.net/indexes/docs/documents/doc-123?api-version=2024-07-01" + ) assert annotation["raw_representation"] == mock_event.annotation assert annotation["annotated_regions"] is not None assert len(annotation["annotated_regions"]) == 1 From a4800406a30241f5a5dfd86124d20f5fffc3aa5b Mon Sep 17 00:00:00 2001 From: Yufeng He <40085740+he-yufeng@users.noreply.github.com> Date: Thu, 28 May 2026 02:01:46 +0800 Subject: [PATCH 2/2] fix: satisfy citation metadata mypy check --- .../openai/agent_framework_openai/_chat_client.py | 9 +++++---- .../openai/tests/openai/test_openai_chat_client.py | 8 +++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/python/packages/openai/agent_framework_openai/_chat_client.py b/python/packages/openai/agent_framework_openai/_chat_client.py index 226f66e500..3a40652d8f 100644 --- a/python/packages/openai/agent_framework_openai/_chat_client.py +++ b/python/packages/openai/agent_framework_openai/_chat_client.py @@ -2880,14 +2880,15 @@ def _get_ann_value(key: str) -> Any: if ann_url: ann_start = _get_ann_value("start_index") ann_end = _get_ann_value("end_index") - additional_properties: dict[str, Any] = {"annotation_index": event.annotation_index} - if ann_get_url := _get_ann_value("get_url"): - additional_properties["get_url"] = ann_get_url + annotation_properties: dict[str, Any] = {"annotation_index": event.annotation_index} + ann_get_url = _get_ann_value("get_url") + if ann_get_url is not None: + annotation_properties["get_url"] = ann_get_url annotation_obj = Annotation( type="citation", title=_get_ann_value("title") or "", url=str(ann_url), - additional_properties=additional_properties, + additional_properties=annotation_properties, raw_representation=annotation, ) if ann_start is not None and ann_end is not None: diff --git a/python/packages/openai/tests/openai/test_openai_chat_client.py b/python/packages/openai/tests/openai/test_openai_chat_client.py index 31a90c2f1d..f10aeddb8c 100644 --- a/python/packages/openai/tests/openai/test_openai_chat_client.py +++ b/python/packages/openai/tests/openai/test_openai_chat_client.py @@ -3407,10 +3407,11 @@ def test_streaming_annotation_added_with_url_citation() -> None: mock_event = MagicMock() mock_event.type = "response.output_text.annotation.added" mock_event.annotation_index = 0 + get_url = "https://example.search.windows.net/indexes/docs/documents/doc-123?api-version=2024-07-01" mock_event.annotation = { "type": "url_citation", "url": "https://example.sharepoint.com/sites/my-site/doc.pdf", - "get_url": "https://example.search.windows.net/indexes/docs/documents/doc-123?api-version=2024-07-01", + "get_url": get_url, "title": "doc.pdf", "start_index": 100, "end_index": 112, @@ -3428,10 +3429,7 @@ def test_streaming_annotation_added_with_url_citation() -> None: assert annotation["title"] == "doc.pdf" assert annotation["url"] == "https://example.sharepoint.com/sites/my-site/doc.pdf" assert annotation["additional_properties"]["annotation_index"] == 0 - assert ( - annotation["additional_properties"]["get_url"] - == "https://example.search.windows.net/indexes/docs/documents/doc-123?api-version=2024-07-01" - ) + assert annotation["additional_properties"]["get_url"] == get_url assert annotation["raw_representation"] == mock_event.annotation assert annotation["annotated_regions"] is not None assert len(annotation["annotated_regions"]) == 1