Python: Enable Agentic Mode to Use Existing Knowledge Bases Without index_name#2464
Merged
eavanvalkenburg merged 3 commits intomicrosoft:mainfrom Dec 3, 2025
Merged
Python: Enable Agentic Mode to Use Existing Knowledge Bases Without index_name#2464eavanvalkenburg merged 3 commits intomicrosoft:mainfrom
eavanvalkenburg merged 3 commits intomicrosoft:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the Azure AI Search Knowledge Base initialization logic to support two distinct paths for using agentic mode: users can now either provide an existing knowledge_base_name directly (simplest approach) or provide index_name to auto-create a Knowledge Base. Previously, all parameters were required even when using an existing KB.
Key Changes
- Added
knowledge_base_namefield toAzureAISearchSettingsfor environment variable support - Updated validation logic to require exactly ONE of
index_nameORknowledge_base_namefor agentic mode - Removed unnecessary
azure_ai_project_endpointparameter - Simplified the sample to demonstrate both usage patterns
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
python/packages/azure-ai-search/agent_framework_azure_ai_search/_search_provider.py |
Core refactoring: added knowledge_base_name to settings, updated validation logic to support both KB paths, made _search_client optional, and refactored _ensure_knowledge_base() to handle existing KB vs auto-creation |
python/packages/azure-ai-search/tests/test_search_provider.py |
Updated tests to cover both agentic mode paths, added tests for validation rules, and cleared environment variables in tests to prevent interference |
python/samples/getting_started/context_providers/azure_ai_search/azure_ai_with_search_context_agentic.py |
Updated sample to demonstrate both usage patterns: using existing KB (simplest) and auto-creating KB from index, with improved documentation |
python/packages/azure-ai-search/agent_framework_azure_ai_search/_search_provider.py
Show resolved
Hide resolved
python/packages/azure-ai-search/agent_framework_azure_ai_search/_search_provider.py
Show resolved
Hide resolved
eavanvalkenburg
approved these changes
Nov 26, 2025
Member
giles17
approved these changes
Dec 3, 2025
arisng
pushed a commit
to arisng/agent-framework
that referenced
this pull request
Feb 2, 2026
…ndex_name (microsoft#2464) * refactor KB for index creation logic * add user agent header for tracking * fix mypy issues --------- Co-authored-by: farzad528 <farzad528@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
When using agentic mode with Azure AI Search, users with an existing Knowledge Base should be able to use it directly by providing
knowledge_base_namewithout needing to specifyindex_name. Previously, the validation logic requiredindex_namefor agentic mode, which forced users to go through the KB auto-creation path even when they already had a Knowledge Base set up.Description
Updated the
AzureAISearchContextProvidervalidation logic for agentic mode to support two paths:Option 1: Use existing Knowledge Base (simplest)
knowledge_base_nameonlyindex_nameormodel_deployment_namerequiredOption 2: Auto-create Knowledge Base from index
index_name+model_deployment_name+azure_openai_resource_url{index_name}-kbValidation rules:
index_nameORknowledge_base_name(not both, not neither)index_name,model_deployment_nameis requiredAZURE_SEARCH_INDEX_NAME/AZURE_SEARCH_KNOWLEDGE_BASE_NAME)Changes:
knowledge_base_namefield toAzureAISearchSettingsfor env var supportContribution Checklist
index_namecontinues to work