Add local document chat agent using Microsoft Agent Framework + Azure AI Search#101
Add local document chat agent using Microsoft Agent Framework + Azure AI Search#101Copilot wants to merge 14 commits into
Conversation
… Search Co-authored-by: sbaidachni <10055252+sbaidachni@users.noreply.github.com>
|
@copilot It will be great to have code that created connection id if it should be created or document about how to make it. Utilize the same Foundry that we already have in config rather than generate a new parameter. Index name should be generated dynamically using the same approach that we are using to create it |
Co-authored-by: sbaidachni <10055252+sbaidachni@users.noreply.github.com>
Addressed in commit 85570b9:
|
sbaidachni
left a comment
There was a problem hiding this comment.
@copilot please, follow-up my comments
| parser = argparse.ArgumentParser( | ||
| description="Run an interactive chat session with indexed documents." | ||
| ) | ||
| parser.add_argument( |
There was a problem hiding this comment.
@copilot any reason to use stage here since our config parts are stage agnostic?
There was a problem hiding this comment.
Removed the --stage argument in commit 8b0f8ac. MLOpsConfig() is now called with no arguments since agent_config and acs_config are not stage-specific.
| help="Stage to find parameters (pr, dev). Defaults to 'pr'.", | ||
| ) | ||
| parser.add_argument( | ||
| "--model", |
There was a problem hiding this comment.
@copilot we don't need the deployment as a parameter since it's in our config file
There was a problem hiding this comment.
Removed the --model argument in commit 8b0f8ac. The model deployment is now read directly from agent_config["agent_model_deployment"] in config.yaml.
| ) | ||
| # Prefer the connection whose target URL contains the configured service name | ||
| matched = next( | ||
| (c for c in connections if acs_service_name.lower() in c.target.lower()), |
There was a problem hiding this comment.
@copilot can we create a connection if it doesn't exist?
There was a problem hiding this comment.
Yes — implemented in commit 8b0f8ac. The function ensure_ai_search_connection_id now:
- Lists existing
CognitiveSearchconnections in the AI Foundry project - Returns the matching connection ID if one is found whose target URL contains
ACS_SERVICE_NAME - If no match, calls
MLClient.connections.create_or_update(AzureAISearchConnection(...))usingsubscription_idandresource_group_namefromsub_config— the project name is extracted from the endpoint URL. AAD/managed-identity auth is used (no API key needed).
Co-authored-by: sbaidachni <10055252+sbaidachni@users.noreply.github.com>
All three review comments addressed in commit
|
|
@copilot the pr fails with the following error: ./src/agent/agent.py:48:1: D205 1 blank line required between summary line and description |
Co-authored-by: sbaidachni <10055252+sbaidachni@users.noreply.github.com>
Fixed in commit |
|
@copilot Now, I have a problem with unit tests: ============================= test session starts ==============================
|
Co-authored-by: sbaidachni <10055252+sbaidachni@users.noreply.github.com>
Fixed in commit |
|
@copilot FAILED tests/agent/test_agent.py::TestExtractProjectName::test_extracts_last_path_segment - ModuleNotFoundError: No module named 'src' |
…ndError Co-authored-by: sbaidachni <10055252+sbaidachni@users.noreply.github.com>
…ow deprecation warnings Co-authored-by: sbaidachni <10055252+sbaidachni@users.noreply.github.com>
Fixed in commit
Result: 12 tests pass, 0 warnings. |
… changes Co-authored-by: sbaidachni <10055252+sbaidachni@users.noreply.github.com>
|
@copilot when I am looking at Pre-build Dev Container Image and Push to Azure Container Registry Action log I don't see any azure-search-documents package to be installed as a part of container. it should be fixed. add code that will print version of this package at the end of build as well |
Co-authored-by: sbaidachni <10055252+sbaidachni@users.noreply.github.com>
Done in commit RUN /home/$USERNAME/llm-env/bin/python -c \
"import importlib.metadata; print('azure-search-documents version:', importlib.metadata.version('azure-search-documents'))"This will produce a line like |
Search Evaluation Results
|
|
@copilot code doesn't create ai searcj connection raising the error: azure.core.exceptions.ResourceNotFoundError: (ResourceNotFound) The Resource 'Microsoft.MachineLearningServices/workspaces/proj-default' under resource group 'mlops-aisearch-pull' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix |
Co-authored-by: sbaidachni <10055252+sbaidachni@users.noreply.github.com>
Fixed in commit I updated connection creation to retry ML workspace resolution using both names parsed from the Foundry endpoint:
If the project workspace is not found, it now falls back to the hub workspace instead of failing immediately. I also added tests for this fallback path and malformed endpoint parsing, and validated with |
|
@copilot revert latest commit. I am not using any Hub based foundry. I am using new foundry |
Co-authored-by: sbaidachni <10055252+sbaidachni@users.noreply.github.com>
Done in commit I reverted the latest hub-based fallback changes and restored Validation: UI screenshot: N/A (no UI changes in this update). |
|
@copilot Now, fix this issue: azure.core.exceptions.ResourceNotFoundError: (ResourceNotFound) The Resource 'Microsoft.MachineLearningServices/workspaces/proj-default' under resource group 'mlops-aisearch-pull' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix |
…t path Co-authored-by: sbaidachni <10055252+sbaidachni@users.noreply.github.com>
Fixed in commit The root cause was that Changed |
Adds a local document chat agent that utilizes an Azure AI Search index to answer user queries about indexed content, built on the Microsoft Agent Framework.
Changes Made
src/agent/agent.py): Created a document chat agent usingAzureAIAgentfrom Semantic Kernel with anAzureAISearchToolconfigured for vector-semantic-hybrid queries. The agent reads all configuration (endpoint, model deployment, search service name) fromconfig/config.yamlwith no CLI arguments required.ensure_ai_search_connection_idfunction lists existing AI Search connections in the AI Foundry project and returns a match by service name. If no connection exists, it auto-creates one viaMLClient.connections.create_or_updateusing AAD authentication._extract_workspace_namehelper extracts the Foundry resource name from the endpoint hostname (e.g.,myfoundryfrommyfoundry.services.ai.azure.com) for use as theworkspace_nameparameter inMLClient, matching the ARM resource name used by the new (non-hub) Azure AI Foundry.generate_index_name()utility (same asbuild_indexer.py) so the index name is consistent across the pipeline.agent_configinconfig.yamluses${AI_FOUNDRY_PROJECT_URI}and${AZURE_AI_AGENT_MODEL_DEPLOYMENT_NAME}— no duplicate environment variables.RUNstep in.buildcontainer/Dockerfileto print theazure-search-documentspackage version at build time.tests/agent/test_agent.py): 12 unit tests covering workspace name extraction, connection resolution/creation, agent creation, conversation handling, and module constants.azure-ai-projects,azure-ai-agents,semantic-kernel, andazure-ai-mlto rootrequirements.txt; addedsrc/__init__.pyandsrc/agent/__init__.pyfor package resolution; added[tool:pytest] pythonpath = .tosetup.cfg.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.