Skip to content

refactor: Upgrade agent-framework and azure-ai-projects libraries with API changes#927

Merged
Avijit-Microsoft merged 4 commits into
devfrom
psl-hb-us-43549
Jun 4, 2026
Merged

refactor: Upgrade agent-framework and azure-ai-projects libraries with API changes#927
Avijit-Microsoft merged 4 commits into
devfrom
psl-hb-us-43549

Conversation

@Harsh-Microsoft

@Harsh-Microsoft Harsh-Microsoft commented May 22, 2026

Copy link
Copy Markdown
Contributor

Purpose

This pull request upgrades the agent framework and related Azure AI dependencies to their latest GA (General Availability) versions, and refactors the codebase to use the new FoundryAgent API instead of the deprecated AzureAIProjectAgentProvider. Additionally, it introduces a runtime patch to restore per-document URL enrichment for Azure AI Search citations, addressing a regression in the latest agent framework. The changes also update logging configuration and clean up requirements files to remove deprecated packages.

Dependency and API upgrades:

  • Upgraded azure-ai-projects, replaced azure-ai-agents and agent-framework-azure-ai with agent-framework-foundry, and updated all relevant requirements files to use GA versions of agent framework and Azure AI packages. (infra/scripts/agent_scripts/requirements.txt, infra/scripts/index_scripts/requirements.txt, src/api/requirements.txt) [1] [2] [3]

Agent API refactoring:

  • Refactored all usages of AzureAIProjectAgentProvider to use the new FoundryAgent API for agent creation and management in both agent and index scripts, as well as in service layers. (infra/scripts/agent_scripts/01_create_agents.py, infra/scripts/index_scripts/03_cu_process_data_text.py, infra/scripts/index_scripts/04_cu_process_custom_data.py, src/api/services/chat_service.py, src/api/services/history_service.py) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]

Azure AI Search citation enrichment patch:

  • Added a runtime patch to agent_framework_openai to restore per-document URL enrichment (get_url) for streaming Azure AI Search citations, working around a known regression in the GA release. This ensures downstream code receives the expected citation URLs. (src/api/services/_patches/agent_framework_search_citations.py, src/api/services/_patches/__init__.py, src/api/services/chat_service.py) [1] [2] [3] [4]

Logging and import updates:

  • Updated logging to target the new agent_framework.foundry logger instead of the deprecated agent_framework.azure, and adjusted imports throughout the codebase to match new package structure. (infra/scripts/index_scripts/03_cu_process_data_text.py, infra/scripts/index_scripts/04_cu_process_custom_data.py, src/api/services/chat_service.py) [1] [2] [3]

Other notable improvements:

  • Updated agent instantiation to properly handle session management with AgentSession and improved citation extraction logic to prefer the patched per-document URL. (src/api/services/chat_service.py) [1] [2]

Does this introduce a breaking change?

  • Yes
  • No

Golden Path Validation

  • I have tested the primary workflows (the "golden path") to ensure they function correctly without errors.

Deployment Validation

  • I have validated the deployment process successfully and all services are running as expected with this change.

What to Check

Verify that the following are valid

  • ...

Other Information

Harsh-Microsoft and others added 2 commits May 21, 2026 21:03
Library upgrades (US #43549):
- agent-framework-core: 1.0.0rc2 -> 1.3.0
- azure-ai-projects: 2.0.0b3 -> 2.1.0
- Replace retired agent-framework-azure-ai/azure-ai-agents with
  agent-framework-foundry==1.3.0 and azure-ai-inference==1.0.0b9

Code changes for the new GA API surface:
- chat_service / history_service: switch from AzureAIProjectAgentProvider
  to FoundryAgent and use AgentSession(service_session_id=...) in place of
  the removed conversation_id streaming kwarg.
- infra agent/index scripts: align with the new SDK imports and GA APIs.

Citation regression workaround (microsoft/agent-framework#5995):
- Add services/_patches/agent_framework_search_citations.py, a runtime
  monkey-patch of RawOpenAIChatClient._parse_chunk_from_openai that
  re-attaches per-document REST URLs (additional_properties.get_url) on
  Azure AI Search url_citation annotations. Mapping uses the doc index
  parsed from the citation title (doc_<N>) so duplicate citations resolve
  correctly. Patch is idempotent and degrades gracefully if upstream
  fixes the regression or renames the target method.
- chat_service citation extraction now prefers additional_properties.get_url
  over the search-service root url so titles/links are per-document.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The services/_patches/agent_framework_search_citations.py monkey-patch
targets internals of agent_framework_openai, so pin its version
explicitly instead of relying on transitive resolution via
agent-framework-foundry.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented May 22, 2026

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
src/api/services
   chat_service.py1751293%64–65, 236–239, 243, 246, 257–258, 278–279
   history_service.py2052488%90, 221–222, 224, 261–263, 279, 285–287, 304, 320–321, 323, 339, 365–366, 368, 384, 404–405, 407, 426
src/api/services/_patches
   __init__.py00100% 
   agent_framework_search_citations.py876426%54, 58–59, 63, 67, 73, 78, 82–83, 88–96, 98–112, 117, 121–131, 134–135, 140–149, 155–160, 162
TOTAL140321684% 

Tests Skipped Failures Errors Time
163 0 💤 0 ❌ 0 🔥 5.399s ⏱️

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 pull request upgrades Azure AI / agent-framework dependencies and refactors the app + scripts to use the new FoundryAgent API (replacing the deprecated AzureAIProjectAgentProvider). It also adds a runtime monkey-patch intended to restore per-document URL enrichment for Azure AI Search streaming citations.

Changes:

  • Upgraded azure-ai-projects and agent-framework packages, and updated requirements across app + infra scripts.
  • Refactored service and script codepaths to instantiate and run agents via FoundryAgent (including session handling via AgentSession).
  • Introduced a runtime patch module to re-introduce additional_properties.get_url enrichment for streaming search citations.

Reviewed changes

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

Show a summary per file
File Description
src/api/services/chat_service.py Migrates orchestration to FoundryAgent, adds AgentSession, and adjusts citation URL selection logic.
src/api/services/history_service.py Migrates title generation agent usage to FoundryAgent.
src/api/services/_patches/agent_framework_search_citations.py Adds a runtime patch attempting to restore streaming citation get_url enrichment.
src/api/services/_patches/init.py Introduces a patches package for third-party runtime hotfixes.
src/api/requirements.txt Updates core Azure AI + agent-framework dependencies (adds azure-ai-inference).
infra/scripts/index_scripts/requirements.txt Updates indexing script dependencies to match new agent-framework packages.
infra/scripts/index_scripts/03_cu_process_data_text.py Refactors agent calls to FoundryAgent and updates logger targeting.
infra/scripts/index_scripts/04_cu_process_custom_data.py Refactors agent calls to FoundryAgent and updates logger targeting.
infra/scripts/agent_scripts/requirements.txt Upgrades azure-ai-projects for agent creation scripts.
infra/scripts/agent_scripts/01_create_agents.py Updates Azure AI Search tool model name (AzureAISearchTool).
src/tests/api/services/test_chat_service.py Updates mocks/patches for FoundryAgent and session-based streaming.
src/tests/api/services/test_history_service.py Updates mocks/patches for FoundryAgent usage in title generation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/api/services/_patches/agent_framework_search_citations.py
Comment thread src/api/requirements.txt
Comment thread infra/scripts/index_scripts/requirements.txt
@Avijit-Microsoft Avijit-Microsoft merged commit 24445df into dev Jun 4, 2026
20 checks passed
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.23.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants