Skip to content

Python: support knowledge_source_params in AzureAISearchContextProvider - #6612

Closed
WERCK Ayrton (Athosone) wants to merge 2 commits into
microsoft:mainfrom
Athosone:issue-5560
Closed

Python: support knowledge_source_params in AzureAISearchContextProvider#6612
WERCK Ayrton (Athosone) wants to merge 2 commits into
microsoft:mainfrom
Athosone:issue-5560

Conversation

@Athosone

Copy link
Copy Markdown

Summary

Adds an optional keyword-only knowledge_source_params: list[KnowledgeSourceParams] | None = None
to AzureAISearchContextProvider, forwarded verbatim into both
KnowledgeBaseRetrievalRequest constructions in _agentic_search.

This lets callers set per-source agentic retrieval options — most importantly
filter_add_on (server-side OData filtering), and also
include_reference_source_data and the other KnowledgeSourceParams fields —
without subclassing the provider or reaching into private methods.

Behavior

  • Back-compatible: default None means retrieval requests are built exactly as before.
  • Agentic-only: the parameter is omitted from the semantic overload, so passing it
    in semantic mode is a type error; a runtime ValueError also guards untyped callers.

Relationship to existing work

Superset of #5095 / #5100 (which hardcodes include_reference_source_data): this exposes
the full KnowledgeSourceParams surface generically.

Tests

  • knowledge_source_params reaches the request in both the minimal (intents) and
    non-minimal (messages) agentic branches.
  • Default path sends None (back-compat).
  • Passing the parameter in semantic mode raises.

uv run poe test -P azure-ai-search (121 passed, 97% coverage), uv run poe syntax -P azure-ai-search,
and uv run poe pyright -P azure-ai-search all pass.

Closes #5560

Copilot AI review requested due to automatic review settings June 19, 2026 07:33

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.

✅ Ready to approve

The change is narrowly scoped, preserves back-compat via a None default, includes a clear semantic-mode guard, and adds targeted tests for the new behavior.

Note: this review does not count toward required approvals for merging.

Pull request overview

Adds a new optional knowledge_source_params keyword-only argument to the Python AzureAISearchContextProvider so callers can pass Azure AI Search Knowledge Base per-source retrieval options (notably filter_add_on and include_reference_source_data) into agentic retrieval requests without subclassing or using private APIs.

Changes:

  • Extend AzureAISearchContextProvider (agentic mode) to accept and store knowledge_source_params, and forward it into both KnowledgeBaseRetrievalRequest constructions in _agentic_search.
  • Add a runtime guard to reject knowledge_source_params in semantic mode (with semantic overloads also excluding the parameter for static type-checking).
  • Add tests covering: forwarding in both agentic request branches and default None behavior; update docs/sample usage to mention per-source parameters.
File summaries
File Description
python/packages/azure-ai-search/agent_framework_azure_ai_search/_context_provider.py Adds knowledge_source_params to the provider API and forwards it into agentic retrieval requests with a semantic-mode guard.
python/packages/azure-ai-search/tests/test_aisearch_context_provider.py Adds unit tests validating semantic-mode rejection and agentic request forwarding/default behavior.
python/packages/azure-ai-search/README.md Documents support for per-source retrieval parameters in agentic mode.
python/samples/02-agents/context_providers/azure_ai_search/search_context_agentic.py Shows how to configure per-source parameters (e.g., OData filter_add_on) when using agentic mode.

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 0

Note

Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.

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
@moonbox3 Evan Mattson (moonbox3) added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Jun 19, 2026
The agentic-retrieval tests fail the zuban/pyrefly/ty type-checking
gate (mypy is lenient and passes): the parametrized `effort` was typed
`str` but assigned to a `Literal[...]` attribute, and `params` was
inferred as `list[SearchIndexKnowledgeSourceParams]` where a
`list[KnowledgeSourceParams] | None` is expected (list invariance).

Annotate the parametrized `effort` and the `params` list with their
proper types so all five gating type-checkers pass. Test-only; no
behavior change.

Refs microsoft#5560
@eavanvalkenburg

Copy link
Copy Markdown
Member

there was a recent update to the this class, can you catch up with main and see if this is still relevant WERCK Ayrton (@Athosone)

retrieval_reasoning_effort=reasoning_effort,
output_mode=output_mode,
include_activity=True,
knowledge_source_params=self._knowledge_source_params,

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.

Should this preserve the source-data params that are now built on main before forwarding caller params? Current main resolves _knowledge_source_names and sends include_reference_source_data=True; this branch sends None on the default path, so existing agentic retrieval loses ref.source_data again after the conflict is resolved this way. Could we merge caller-supplied fields with the resolved-source defaults instead of replacing them?

@moonbox3

Copy link
Copy Markdown
Contributor

Please re-open when ready to address the conflicts, and if the fix is needed as it may not be any longer.

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

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: AzureAISearchContextProvider lacks a way to set KnowledgeSourceParams

4 participants