Skip to content

fix: Refactor code structure for improved readability and maintainability#271

Open
Dhanushree-Microsoft wants to merge 17 commits into
devfrom
cm-upg-aiproj
Open

fix: Refactor code structure for improved readability and maintainability#271
Dhanushree-Microsoft wants to merge 17 commits into
devfrom
cm-upg-aiproj

Conversation

@Dhanushree-Microsoft
Copy link
Copy Markdown
Contributor

Purpose

This pull request updates dependencies and refactors the agent builder and client helper code to align with the latest agent-framework library changes. The main focus is on supporting the new Agent class and handling the removal or renaming of several types and clients in agent-framework 1.3.0. The changes improve compatibility and future-proof the codebase.

Does this introduce a breaking change?

  • Yes
  • No

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 updates the processor/backend dependency set and refactors the “agent framework” integration layer to be compatible with agent-framework==1.3.0, including migrating from legacy event/agent types to the newer Agent + WorkflowEvent APIs.

Changes:

  • Bumped agent-framework (and related Azure SDK deps) and refreshed uv.lock/requirements across processor, backend-api, and infra.
  • Refactored orchestrators, agent builder/helper code, and MCP examples to use Agent, WorkflowEvent, and FunctionTool-style tooling.
  • Updated unit tests to align with the new event/message shapes and renamed coordinator response model.

Reviewed changes

Copilot reviewed 29 out of 31 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/processor/uv.lock Updates processor locked dependencies for agent-framework 1.3.0 and related packages.
src/processor/pyproject.toml Pins processor runtime dependencies to agent-framework 1.3.0 and newer Azure SDK versions.
src/backend-api/uv.lock Updates backend-api lockfile to newer azure-ai-agents.
src/backend-api/pyproject.toml Pins backend-api dependency azure-ai-agents to 1.2.0b6.
infra/vscode_web/requirements.txt Updates infra requirements to azure-ai-projects==2.1.0.
infra/vscode_web/endpoint-requirements.txt Updates endpoint requirements to azure-ai-projects==2.1.0.
src/processor/src/steps/migration_processor.py Migrates workflow stream handling from event classes to WorkflowEvent with event.type checks.
src/processor/src/steps/analysis/orchestration/analysis_orchestrator.py Updates MCP tool typing/imports for agent-framework 1.3.0.
src/processor/src/steps/design/orchestration/design_orchestrator.py Updates MCP tool typing/imports for agent-framework 1.3.0.
src/processor/src/steps/convert/orchestration/yaml_convert_orchestrator.py Updates MCP tool typing/imports for agent-framework 1.3.0.
src/processor/src/steps/documentation/orchestration/documentation_orchestrator.py Updates MCP tool typing/imports for agent-framework 1.3.0.
src/processor/src/libs/base/orchestrator_base.py Switches to Agent, adds coordinator response model, and configures tool-result compaction.
src/processor/src/libs/agent_framework/agent_builder.py Refactors fluent builder from ChatAgent to Agent and updates types/tools/middleware handling.
src/processor/src/libs/agent_framework/agent_framework_helper.py Adjusts client creation paths for removed/renamed agent-framework Azure clients.
src/processor/src/libs/agent_framework/azure_openai_response_retry.py Re-bases retry client on new OpenAI client surface and adapts request/stream method signatures.
src/processor/src/libs/agent_framework/groupchat_orchestrator.py Migrates orchestrator types/events/messages to agent-framework 1.3.0 equivalents.
src/processor/src/libs/agent_framework/shared_memory_context_provider.py Updates context provider to use Message and revised context injection surface.
src/processor/src/libs/agent_framework/middlewares.py Updates middleware interfaces to AgentContext and Message.
src/processor/src/libs/agent_framework/agent_speaking_capture.py Updates middleware context type (AgentRunContextAgentContext).
src/processor/src/libs/agent_framework/agent_info.py Updates tool typing from ToolProtocol to FunctionTool.
src/processor/src/libs/agent_framework/coordinator_selection_response.py Adds new coordinator selection response model used for routing/termination.
src/processor/src/libs/mcp_server/MCPMicrosoftDocs.py Updates MCP usage examples to use Agent instead of ChatAgent.
src/processor/src/libs/mcp_server/MCPDatetimeTool.py Updates MCP usage examples to use Agent instead of ChatAgent.
src/processor/src/libs/mcp_server/MCPBlobIOTool.py Updates MCP usage examples to use Agent instead of ChatAgent.
src/processor/src/tests/unit/steps/test_migration_processor_run.py Updates tests to use WorkflowEvent.*() factories instead of legacy event classes.
src/processor/src/tests/unit/libs/agent_framework/test_shared_memory_context_provider.py Adjusts assertions for updated context object shape.
src/processor/src/tests/unit/libs/agent_framework/test_middlewares_extras.py Introduces message stubs/patching to test middlewares under new Message API.
src/processor/src/tests/unit/libs/agent_framework/test_input_observer_middleware.py Introduces message stubs/patching to test input observer behavior under new Message API.
src/processor/src/tests/unit/libs/agent_framework/test_groupchat_orchestrator_internals.py Updates internal orchestrator tests to use message stubs and string roles.
src/processor/src/tests/unit/libs/agent_framework/test_agent_framework_helper.py Updates helper tests to reflect removed azure clients and renamed agent client.
src/processor/src/tests/unit/libs/agent_framework/test_agent_builder.py Updates builder tests to patch Agent construction instead of ChatAgent.

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

Comment thread src/processor/src/libs/agent_framework/azure_openai_response_retry.py Outdated
Dhanushree-Microsoft and others added 2 commits June 4, 2026 12:34
When callers pass credential=None explicitly, the key exists in kwargs
but the ad_token_provider mapping was skipped. Use kwargs.get() is None
to correctly handle this case.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When callers pass credential=None explicitly, the key exists in kwargs
but the ad_token_provider mapping was skipped. Use kwargs.get() is None
to correctly handle this case.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 4, 2026 07:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 29 out of 31 changed files in this pull request and generated 7 comments.

Comment thread src/processor/src/libs/base/orchestrator_base.py
Comment thread src/processor/src/libs/agent_framework/groupchat_orchestrator.py
Comment thread src/processor/src/libs/agent_framework/groupchat_orchestrator.py
Comment thread src/processor/src/steps/migration_processor.py Outdated
Keep agent-framework==1.3.0 upgrade from PR (per user story 43673).
Accept newer general dependency versions from dev branch.
Keep upgraded azure_openai_response_retry.py from PR.

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

github-actions Bot commented Jun 4, 2026

Coverage

Coverage Report •
FileStmtsMissCoverMissing
TOTAL309720893% 
report-only-changed-files is enabled. No files were changed during this commit :)

Tests Skipped Failures Errors Time
588 0 💤 0 ❌ 0 🔥 28.378s ⏱️

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 4, 2026

Coverage

Processor Coverage Report •
FileStmtsMissCoverMissing
src/processor/src/libs/agent_framework
   agent_builder.py1230100% 
   agent_framework_helper.py821186%84, 151, 175, 197, 220, 237, 371, 390, 411, 448–449
   agent_info.py240100% 
   agent_speaking_capture.py66493%206–207, 210, 212
   azure_openai_response_retry.py37914462%193, 201, 223, 236, 253, 262–263, 268–271, 273, 397, 404–407, 409–411, 417–419, 436, 457–458, 463–466, 469–472, 474–477, 479, 489–491, 493–496, 498–501, 503–507, 509, 517–519, 521, 544–549, 551–553, 559–560, 564–567, 571, 574, 582–583, 589–590, 595, 597, 618, 624–626, 630–631, 647–648, 650–653, 657, 660, 668–669, 675–677, 679–682, 684–695, 698, 705–706, 731–732, 739–740, 742, 746, 749–750, 754–755, 757–759, 767, 769–771, 773–775, 777–778, 788
   coordinator_selection_response.py60100% 
   groupchat_orchestrator.py5439083%130–131, 138–139, 144–145, 472, 475–479, 481, 483–484, 487, 490, 493, 495, 497–500, 507–508, 515–516, 523–524, 527–529, 531–532, 537–539, 542–543, 548, 551–553, 556–557, 562, 565, 571, 574, 578, 580–584, 588–589, 595, 598, 602, 607, 610, 621–622, 624, 626–627, 629, 639–640, 642, 735, 909, 928, 930, 932, 961, 1090, 1092, 1207, 1216, 1218, 1263–1264, 1267, 1288–1291, 1309
   middlewares.py820100% 
   shared_memory_context_provider.py1241389%111, 138, 219, 230, 234, 239, 282, 287, 310–314
src/processor/src/libs/base
   orchestrator_base.py1675070%65, 71, 74–77, 83–84, 86–87, 130, 141, 146, 151–152, 156, 164, 166, 168, 175–176, 183, 189, 191, 198, 202, 211, 215, 220, 222–223, 225, 324–326, 329, 335, 342–344, 371–373, 376, 383, 390–392, 443–444
src/processor/src/libs/mcp_server
   MCPBlobIOTool.py50100% 
   MCPDatetimeTool.py60100% 
   MCPMicrosoftDocs.py30100% 
src/processor/src/steps
   migration_processor.py2644084%88–89, 145–146, 160, 187, 222–223, 229–230, 234, 238, 309–312, 315–318, 322–323, 336–337, 395–396, 496–497, 547–548, 555–556, 594–595, 613–614, 678–679, 703, 732
src/processor/src/steps/analysis/orchestration
   analysis_orchestrator.py85890%46–47, 61, 65, 112, 115, 121, 123
src/processor/src/steps/convert/orchestration
   yaml_convert_orchestrator.py97594%64, 112, 115, 121, 123
src/processor/src/steps/design/orchestration
   design_orchestrator.py82989%42–43, 50, 54, 104, 107, 114–115, 117
src/processor/src/steps/documentation/orchestration
   documentation_orchestrator.py95693%69, 117, 120, 126–127, 129
TOTAL576474087% 

Tests Skipped Failures Errors Time
812 0 💤 0 ❌ 0 🔥 19.382s ⏱️

The teardown_module from one test file was restoring the real Message
before another test file's tests ran. Adding setup_module ensures the
stub is re-applied before each module's tests execute.

Also fix test assertion to check contents instead of text since the
middleware now uses Message(contents=).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

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

Comments suppressed due to low confidence (1)

src/processor/src/libs/agent_framework/shared_memory_context_provider.py:312

  • SharedMemoryContextProvider._get_text() checks message.content, but the new agent-framework Message uses contents (and callers in this repo treat tool calls / message payloads as Message.contents). As written, this will return str(message) for most messages and degrade both memory search queries and stored memory quality.
    def _get_text(message: Message) -> str:
        """Extract text content from a Message."""
        if hasattr(message, "text") and message.text:
            return message.text
        if hasattr(message, "content"):
            return str(message.content) if message.content else ""
        return str(message) if message else ""

Comment thread src/processor/src/libs/agent_framework/middlewares.py
The middleware now uses Message(contents=) so the test must verify
the contents field, not text.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Set both text= and contents= when constructing Message in
  InputObserverMiddleware for compatibility with downstream code
- Restore missing copyright header in azure_openai_response_retry.py

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 28 out of 29 changed files in this pull request and generated 6 comments.

Comment thread src/processor/src/libs/agent_framework/middlewares.py
Comment thread src/processor/src/libs/agent_framework/groupchat_orchestrator.py Outdated
Comment thread src/processor/src/libs/agent_framework/azure_openai_response_retry.py Outdated
Comment thread src/processor/src/libs/agent_framework/azure_openai_response_retry.py Outdated
Comment thread src/processor/pyproject.toml
- shared_memory_context_provider: _get_text() now checks message.contents
- middlewares: InputObserverMiddleware handles messages with only contents (no text)
- azure_openai_response_retry: _get_message_role() handles enum roles via .value
- azure_openai_response_retry: _set_message_text() also updates contents attribute
- groupchat_orchestrator: updated comment to reference Coordinator (not manager)
- uv.lock: regenerated to match pyproject.toml pinned versions

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants