Skip to content

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

Merged
Avijit-Microsoft merged 18 commits into
devfrom
psl-cmupgrade
Jun 4, 2026
Merged

fix: Refactor code structure for improved readability and maintainability#272
Avijit-Microsoft merged 18 commits into
devfrom
psl-cmupgrade

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

Dhanushree-Microsoft and others added 16 commits May 21, 2026 11:44
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>
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>
…de clarity

- Fix create_agents return type annotation to dict[str, Agent]
- Narrow participants param to Mapping only (Sequence was unused)
- Normalize self.agents with dict() and correct value type
- Replace redundant pass with continue and clarifying comment
- Add teardown_module to test files to restore patched Message class

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Update InputObserverMiddleware to use Message(contents=) instead of
  Message(text=) since agent-framework 1.3.0 renamed the parameter
- Update corresponding tests to verify contents field
- Fix teardown_module signature to accept optional module parameter

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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>
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>
@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.py36913962%193, 201, 223, 249, 259–261, 385, 392–395, 397–399, 405–407, 424, 445–446, 451–454, 457–460, 462–465, 467, 477–479, 481–484, 486–489, 491–495, 497, 505–507, 509, 532–537, 539–541, 547–548, 552–555, 559, 562, 570–571, 577–578, 583, 585, 606, 612–614, 618–619, 635–636, 638–641, 645, 648, 656–657, 663–665, 667–670, 672–683, 686, 693–694, 719–720, 727–728, 730, 734, 737–738, 742–743, 745–747, 755, 757–759, 761–763, 765–766, 776
   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.py800100% 
   shared_memory_context_provider.py1221190%111, 138, 219, 230, 234, 239, 282, 287, 310–312
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
TOTAL575073387% 

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

@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 🔥 30.267s ⏱️

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 to agent-framework==1.3.0 and refactors the local agent/orchestration integration to match the newer framework surface area (e.g., Agent, WorkflowEvent, FunctionTool) while updating affected unit tests and related dependency pins.

Changes:

  • Migrates agent orchestration/runtime code from legacy event/classes (ChatAgent, Workflow*Event, ToolProtocol) to Agent, WorkflowEvent, and FunctionTool.
  • Updates shared-memory context provider and middleware/test stubs to the new Message shape (contents vs text).
  • Bumps key dependencies (processor + vscode_web requirements) to align with the updated framework ecosystem.

Reviewed changes

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

Show a summary per file
File Description
src/processor/src/tests/unit/steps/test_migration_processor_run.py Updates workflow event stubs to WorkflowEvent.*() factories.
src/processor/src/tests/unit/libs/agent_framework/test_shared_memory_context_provider.py Loosens assertions to account for updated context shape.
src/processor/src/tests/unit/libs/agent_framework/test_middlewares_extras.py Reworks middleware tests with a Message stub and module-level patching.
src/processor/src/tests/unit/libs/agent_framework/test_input_observer_middleware.py Updates input observer middleware test for Message(contents=...).
src/processor/src/tests/unit/libs/agent_framework/test_groupchat_orchestrator_internals.py Updates orchestrator internals tests to new Message/role expectations and patching.
src/processor/src/tests/unit/libs/agent_framework/test_agent_framework_helper.py Adjusts helper tests for removed/renamed azure clients (now expecting ImportError).
src/processor/src/tests/unit/libs/agent_framework/test_agent_builder.py Updates builder tests to patch Agent instead of ChatAgent.
src/processor/src/steps/migration_processor.py Refactors streaming event handling to WorkflowEvent (event.type, executor_id).
src/processor/src/steps/documentation/orchestration/documentation_orchestrator.py Updates tool typing/imports to FunctionTool.
src/processor/src/steps/design/orchestration/design_orchestrator.py Updates tool typing/imports to FunctionTool.
src/processor/src/steps/convert/orchestration/yaml_convert_orchestrator.py Updates tool typing/imports to FunctionTool.
src/processor/src/steps/analysis/orchestration/analysis_orchestrator.py Updates tool typing/imports to FunctionTool.
src/processor/src/libs/mcp_server/MCPMicrosoftDocs.py Updates examples to use Agent instead of ChatAgent.
src/processor/src/libs/mcp_server/MCPDatetimeTool.py Updates examples to use Agent instead of ChatAgent.
src/processor/src/libs/mcp_server/MCPBlobIOTool.py Updates examples to use Agent instead of ChatAgent.
src/processor/src/libs/base/orchestrator_base.py Switches orchestration to Agent and introduces tool result compaction + new coordinator response model.
src/processor/src/libs/agent_framework/shared_memory_context_provider.py Migrates context provider to Message and adds a default prompt; refactors text extraction.
src/processor/src/libs/agent_framework/middlewares.py Migrates middleware types to new agent framework context/message types.
src/processor/src/libs/agent_framework/groupchat_orchestrator.py Migrates group chat orchestrator to new streaming/update events and Message.
src/processor/src/libs/agent_framework/coordinator_selection_response.py Adds local CoordinatorSelectionResponse model replacing removed framework type.
src/processor/src/libs/agent_framework/azure_openai_response_retry.py Re-implements retry wrapper against new agent-framework OpenAI client surface.
src/processor/src/libs/agent_framework/agent_speaking_capture.py Updates middleware signature to AgentContext.
src/processor/src/libs/agent_framework/agent_info.py Updates tool typing to FunctionTool.
src/processor/src/libs/agent_framework/agent_framework_helper.py Updates client type hints/imports for renamed Durable agent client.
src/processor/src/libs/agent_framework/agent_builder.py Reworks builder to construct Agent instead of ChatAgent, updating types accordingly.
src/processor/pyproject.toml Bumps agent-framework to 1.3.0 and related dependency versions.
infra/vscode_web/requirements.txt Updates azure-ai-projects version pin.
infra/vscode_web/endpoint-requirements.txt Updates azure-ai-projects version pin.
Comments suppressed due to low confidence (1)

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

  • SharedMemoryContextProvider._get_text() looks for message.content, but the rest of this repo (and updated tests) treat the new agent-framework Message as using contents (and/or text). As written, this can return an empty string and prevent memory search/storage from working. Prefer text, then fall back to contents.
        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 ""

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

Comment thread src/processor/src/libs/agent_framework/middlewares.py
Comment thread src/processor/src/libs/agent_framework/middlewares.py
Comment thread src/processor/src/libs/agent_framework/middlewares.py Outdated
Comment thread src/processor/src/libs/agent_framework/middlewares.py Outdated
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/libs/agent_framework/groupchat_orchestrator.py
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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 2 comments.

Comments suppressed due to low confidence (2)

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

  • SharedMemoryContextProvider._get_text() currently ignores message.contents. Elsewhere in this repo (e.g., middlewares/groupchat) messages may carry their primary payload in .contents, so memory query extraction and stored memories can end up using str(message) instead of the actual text/tool output.
        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 ""

src/processor/src/libs/agent_framework/groupchat_orchestrator.py:1303

  • _build_result_generator_conversation() constructs new Message objects with text=... only. Other parts of this orchestrator treat Message.contents as the canonical place for tool calls / content, and agent-framework 1.3.0 appears to be moving toward contents-first messages. Setting contents here makes downstream handling (and framework compatibility) more reliable.
                Message(
                    role=role,
                    text=truncated,
                    author_name=author,
                )

Comment thread src/processor/src/libs/agent_framework/middlewares.py
Comment thread src/processor/pyproject.toml
@Avijit-Microsoft Avijit-Microsoft merged commit 3968aed into dev Jun 4, 2026
14 checks passed
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.

3 participants