Skip to content

Python: Fix Azure AI Search citation URLs#6453

Open
eavanvalkenburg wants to merge 3 commits into
microsoft:mainfrom
eavanvalkenburg:fix_search_citations
Open

Python: Fix Azure AI Search citation URLs#6453
eavanvalkenburg wants to merge 3 commits into
microsoft:mainfrom
eavanvalkenburg:fix_search_citations

Conversation

@eavanvalkenburg

@eavanvalkenburg eavanvalkenburg commented Jun 10, 2026

Copy link
Copy Markdown
Member

Motivation and Context

Fixes #5995.
Fixes #6330.

Azure AI Search citations in Foundry streaming responses can omit additional_properties.get_url because the per-document URLs arrive in later azure_ai_search_call_output stream events instead of on the citation annotation itself.

Foundry IQ / MCP search-index citations can also expose only mcp://searchindex/<document-id> citation URLs even when the MCP retrieval output includes document metadata such as title and source.

Description

  • Correlates streamed doc_N URL citation annotations with Azure AI Search get_urls[] from azure_ai_search_call_output events during final stream aggregation.
  • Preserves any get_url already present on annotations and avoids changing in-progress streaming chunks before the final response.
  • Recognizes Azure AI Search output events so they are not logged as unparsed, while keeping them out of visible response content.
  • Enriches mcp://searchindex/<document-id> citation annotations with MCP retrieval metadata (mcp_document_id, document_title, and source) when matching document JSON is present in MCP output.
  • Strips the client-side model for first-turn non-preview Foundry agent-reference calls so the service resolves the model from the Prompt Agent definition.
  • Adds unit regression coverage for final ChatResponse and mapped final AgentResponse enrichment, MCP search-index metadata, plus a local-only Foundry/Azure AI Search integration check that creates and cleans up a temporary Prompt Agent.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 10, 2026 14:10
@github-actions github-actions Bot changed the title Fix Azure AI Search citation URLs Python: Fix Azure AI Search citation URLs Jun 10, 2026
@github-actions

github-actions Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/foundry/agent_framework_foundry
   _agent.py2445677%119, 122, 244–245, 249–251, 256–259, 352, 427–428, 440–441, 453–455, 457–458, 460–466, 468–469, 471, 473, 479–481, 484–493, 497–498, 696–697, 700, 726, 736, 752, 822, 827, 831
packages/openai/agent_framework_openai
   _chat_client.py125315887%279, 292, 642–646, 654–657, 663–667, 717–724, 726–728, 735–737, 795, 803, 826, 944, 1043, 1102, 1104, 1106, 1108, 1174, 1188, 1268, 1278, 1283, 1326, 1437–1438, 1453, 1680, 1685, 1689–1691, 1695–1696, 1779, 1789, 1816, 1822, 1832, 1838, 1843, 1849, 1854–1855, 1874, 1877–1880, 1894, 1896, 1904–1905, 1917, 1959, 2024, 2039, 2042, 2069–2071, 2110, 2127, 2130, 2191–2192, 2227, 2265–2266, 2284–2285, 2328, 2494, 2532–2533, 2551, 2634–2642, 2672, 2782, 2817, 2832, 2852–2862, 2875, 2886–2890, 2904, 2918–2929, 2938, 2970–2973, 2983–2985, 2996–2998, 3012–3014, 3024–3025, 3031, 3046
TOTAL38783442588% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
7772 34 💤 0 ❌ 0 🔥 2m 0s ⏱️

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses missing per-document Azure AI Search REST URLs (additional_properties.get_url) on doc_N citation annotations in Foundry streaming responses by enriching citations during final stream aggregation using get_urls data emitted by Azure AI Search output events. It also adjusts Foundry Prompt Agent request preparation to rely on agent_reference (server-resolved model) for first-turn non-preview calls, and adds regression coverage (unit + optional local integration).

Changes:

  • Enrich streamed doc_N citation annotations post-stream by correlating them with azure_ai_search_call_output get_urls.
  • Suppress “unparsed event” logging / visible content emission for Azure AI Search output events.
  • Strip client-side model for first-turn non-preview Prompt Agent calls and add regression tests (plus a local integration check).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
python/packages/openai/tests/openai/test_openai_chat_client.py Adds unit regression tests for post-stream enrichment and for propagation into mapped AgentResponse.
python/packages/openai/agent_framework_openai/_chat_client.py Adds Azure AI Search output parsing + citation enrichment during streamed response finalization; suppresses logging/visibility for these events.
python/packages/foundry/tests/foundry/test_foundry_agent.py Updates Prompt Agent option-stripping assertions and adds an optional live integration test for Azure AI Search streaming citations.
python/packages/foundry/agent_framework_foundry/_agent.py Strips model for first-turn non-preview Prompt Agent calls so the service resolves model from the agent definition.

Comment thread python/packages/openai/agent_framework_openai/_chat_client.py
Comment thread python/packages/openai/agent_framework_openai/_chat_client.py Outdated
Comment thread python/packages/openai/agent_framework_openai/_chat_client.py Outdated
Comment thread python/packages/foundry/tests/foundry/test_foundry_agent.py

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review

Reviewers: 5 | Confidence: 89% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Failure Modes, Design Approach


Automated review by eavanvalkenburg's agents

eavanvalkenburg and others added 2 commits June 10, 2026 16:36
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

3 participants