Skip to content

Python: Add include_reference_source_data to agentic search requests - #5100

Merged
Evan Mattson (moonbox3) merged 1 commit into
microsoft:mainfrom
mvanhorn:fix/source-data-none-5095
Jul 8, 2026
Merged

Python: Add include_reference_source_data to agentic search requests#5100
Evan Mattson (moonbox3) merged 1 commit into
microsoft:mainfrom
mvanhorn:fix/source-data-none-5095

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Summary

_agentic_search() in AzureAISearchContextProvider constructs KnowledgeBaseRetrievalRequest without passing knowledge_source_params, so include_reference_source_data is never set. This causes ref.source_data to always be None on returned references, even when the knowledge source has source_data_fields configured.

Changes

  • Pass knowledge_source_params=[KnowledgeSourceParams(..., include_reference_source_data=True)] to both KnowledgeBaseRetrievalRequest constructions in _agentic_search() (the minimal reasoning path at line 828 and the non-minimal path at line 836)
  • Add KnowledgeSourceParams to both TYPE_CHECKING and runtime import blocks
  • Add two unit tests verifying the parameter is passed for both reasoning effort paths

Testing

  • Existing 119 tests pass
  • New tests verify knowledge_source_params is present with correct knowledge_source_name and include_reference_source_data=True for both the minimal and non-minimal reasoning paths

Fixes #5095

This contribution was developed with AI assistance (Claude Code).

@eavanvalkenburg

Copy link
Copy Markdown
Member

Matt Van Horn (@mvanhorn) some tests and check failures, please have a look

@mvanhorn

Copy link
Copy Markdown
Contributor Author

Took a look - the 6 failing tests are all in packages/durabletask/tests/test_executors.py (TestOrchestrationAgentExecutorFireAndForget) with a TypeError: argument of type 'Mock' is not iterable in the durabletask dependency. This PR only touches files in packages/azure-ai-search/, so the failures are unrelated to these changes.

@eavanvalkenburg

Copy link
Copy Markdown
Member

then ensure you are working against the latest main

@mvanhorn

Copy link
Copy Markdown
Contributor Author

Eduard van Valkenburg (@eavanvalkenburg) rebased onto latest main in d1fd0a8. The durabletask test failures should clear if the fix landed upstream. CI running now.

@moonbox3

Evan Mattson (moonbox3) commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/azure-ai-search/agent_framework_azure_ai_search
   _context_provider.py3901995%96–97, 122–125, 536, 615–616, 743–744, 797–798, 842, 847, 852, 946–947, 995
TOTAL44393533887% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
8769 33 💤 0 ❌ 0 🔥 2m 20s ⏱️

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 updates the Python Azure AI Search AzureAISearchContextProvider agentic retrieval request construction so that reference source_data can be returned by opting in via knowledge_source_params (include_reference_source_data=True). It also adds unit tests to validate the request includes these parameters for both minimal and non-minimal reasoning effort paths.

Changes:

  • Add KnowledgeSourceParams(..., include_reference_source_data=True) to both KnowledgeBaseRetrievalRequest code paths in _agentic_search().
  • Add KnowledgeSourceParams to the type-checking and runtime import blocks.
  • Add unit tests asserting knowledge_source_params is present for minimal and non-minimal reasoning effort requests.

Reviewed changes

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

File Description
python/packages/azure-ai-search/agent_framework_azure_ai_search/_context_provider.py Injects knowledge_source_params into agentic retrieval requests so reference source_data can be returned.
python/packages/azure-ai-search/tests/test_aisearch_context_provider.py Adds tests verifying knowledge_source_params is set for both reasoning-effort branches.

@TaoChenOSU

Copy link
Copy Markdown
Contributor

Please address or resolve the comments from Copilot if they are valid.

auto-merge was automatically disabled June 2, 2026 04:10

Head branch was pushed to by a user without write access

@mvanhorn

Copy link
Copy Markdown
Contributor Author

Good catch from Copilot, both comments were valid. Fixed in cee7874: in agentic mode against an existing Knowledge Base, index_name is forced to None, so f"{self.index_name}-source" was producing "None-source". The provider now resolves the real knowledge source names from the existing KB via get_knowledge_base(...).knowledge_sources (and stores [f"{index_name}-source"] for the create-from-index path), then builds knowledge_source_params from the resolved list. Added a test asserting no "None-source" is emitted when index_name is None. Package tests and ruff are green.

@moonbox3

Copy link
Copy Markdown
Contributor

Can you resolve the comments by Copilot, if no longer needed/applicable, please?

@eavanvalkenburg

Copy link
Copy Markdown
Member

Matt Van Horn (@mvanhorn) there are some failing tests and some open comments, please have a look, so we can get this fixed.

WERCK Ayrton (Athosone) added a commit to Athosone/agent-framework that referenced this pull request Jun 19, 2026
Add an optional keyword-only `knowledge_source_params` to the agentic
overloads of `AzureAISearchContextProvider`, forwarded verbatim into both
`KnowledgeBaseRetrievalRequest` constructions in `_agentic_search`. This lets
callers set per-source agentic retrieval options such as `filter_add_on`
(OData filtering), `include_reference_source_data`, and similar.

Default `None` keeps existing behavior unchanged. The parameter is
agentic-only: it is omitted from the semantic overload (a type-level
contract) and a runtime ValueError guards untyped callers that pass it in
semantic mode.

Superset of microsoft#5095 / microsoft#5100.

Refs microsoft#5560
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Both Copilot comments were valid and are fixed in cee7874 — in agentic mode against an existing Knowledge Base, index_name is forced to None, so the source name no longer resolves to "None-source". I've resolved those two threads since they're now addressed. On the failing tests: the checks I can see here (license/cla, add_label) are green — I think the Python test workflow needs a maintainer to approve/re-run it on this fork PR. Could you kick that off, or point me at a specific failure and I'll dig in right away?

@moonbox3

Copy link
Copy Markdown
Contributor

Matt Van Horn (@mvanhorn) can you please have a look at the conflict as well?

@mvanhorn

Copy link
Copy Markdown
Contributor Author

Rebased onto main. The conflict was in _agentic_search: main refactored the retrieval request to a request_kwargs dict with the preview reasoning-effort/output-mode gating, while this branch's two commits added include_reference_source_data and then switched the source name to the resolved _knowledge_source_names (to avoid "None-source"). Merged both: kept main's request_kwargs + preview gating and built knowledge_source_params from _knowledge_source_names.

Ran the azure-ai-search tests: 129 pass with the preview SDK (12.1.0b1); on GA 12.0.0 everything passes except the one preview-only messages test (which needs the preview request shape), as expected. ruff clean.

@moonbox3

Copy link
Copy Markdown
Contributor

Hi Matt Van Horn (@mvanhorn), still seeing a lot of CI/CD test failures.

Pass knowledge_source_params with include_reference_source_data=True for
each resolved knowledge source on the KnowledgeBaseRetrievalRequest, so
ref.source_data is populated when the source has source_data_fields
configured. Uses SearchIndexKnowledgeSourceParams (azure-search-documents
12.0.0) and resolves real source names for both created and existing
knowledge bases (avoids the prior 'None-source' name).

Fixes microsoft#5095
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Rebased onto main and reworked this for the azure-search-documents 12.0.0 API that CI now uses — the branch was pinned to an older 11.7 beta, which is why KnowledgeBaseRetrievalRequest(messages=...) was blowing up. It's now a small delta on top of main's current structure: passes knowledge_source_params with include_reference_source_data=True per resolved knowledge source (via SearchIndexKnowledgeSourceParams), and resolves real source names for both created and existing KBs. Ran the package suite locally — 128 passed (incl. 2 new tests covering the params being set and omitted), ruff + pyright clean. Should be green now.

@moonbox3 Evan Mattson (moonbox3) 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.

Thanks for helping see this through, Matt Van Horn (@mvanhorn)

@moonbox3
Evan Mattson (moonbox3) added this pull request to the merge queue Jul 8, 2026
Merged via the queue into microsoft:main with commit fb4be3b Jul 8, 2026
37 checks passed
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks for shepherding this through, Evan Mattson (@moonbox3) - include_reference_source_data rounds out the agentic search response.

@mvanhorn

Copy link
Copy Markdown
Contributor Author

Appreciate the review and merge, Evan Mattson (@moonbox3)! include_reference_source_data on agentic search should help folks trace citations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: AzureAISearchContextProvider agentic mode: source_data is always None on references — missing include_reference_source_data parameter

6 participants