Skip to content

Conversation

@dmytrostruk
Copy link
Member

@dmytrostruk dmytrostruk commented Jan 17, 2026

Motivation and Context

Resolves #1576

  1. Moved _normalize_messages to a shared normalize_messages function in _types.py so the use_agent_middleware decorator no longer depends on BaseAgent internals. This allows the decorator to work with any agent implementing AgentProtocol.
  2. Made normalize_messages public, so it can be reused in A2A and Copilot Studio agents, and should be useful for end-users as well (similarly to normalize_tools).

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@dmytrostruk dmytrostruk self-assigned this Jan 17, 2026
Copilot AI review requested due to automatic review settings January 17, 2026 03:30
Copy link
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 PR fixes issue #1576 where the use_agent_middleware decorator was calling a private method _normalize_messages that wasn't part of the AgentProtocol interface. The fix extracts the message normalization logic into a shared utility function.

Changes:

  • Moved _normalize_messages from a private BaseAgent method to a shared normalize_messages function in _types.py
  • Updated use_agent_middleware decorator to use the new shared function instead of calling a private method
  • Added a test to verify the decorator works with agents implementing only AgentProtocol (not inheriting from BaseAgent)

Reviewed changes

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

File Description
python/packages/core/agent_framework/_types.py Added new normalize_messages utility function to handle message normalization without requiring BaseAgent
python/packages/core/agent_framework/_middleware.py Updated to import and use the new normalize_messages function instead of calling self._normalize_messages()
python/packages/core/agent_framework/_agents.py Removed private _normalize_messages method and updated to use the new shared function from _types.py
python/packages/core/tests/core/test_middleware_with_agent.py Added test case validating that use_agent_middleware works with minimal agents implementing only AgentProtocol

@markwallace-microsoft
Copy link
Member

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/a2a/agent_framework_a2a
   _agent.py139794%355–356, 393–394, 423–425
packages/copilotstudio/agent_framework_copilotstudio
   _agent.py75494%154–155, 190, 198
packages/core/agent_framework
   _agents.py2975481%51, 90, 96, 99, 102, 404–406, 452, 634, 803, 806–808, 925–928, 930, 933–935, 1036, 1077, 1079, 1088–1093, 1099, 1101, 1111–1112, 1119, 1121–1122, 1130–1134, 1142–1143, 1145, 1150, 1152, 1186, 1231–1232, 1234, 1236, 1247
   _middleware.py402798%805, 821, 868–869, 1074–1075, 1120
   _types.py102312088%99, 139, 141, 143, 145, 147, 149, 156–159, 177–178, 315, 317, 324, 343, 383, 429–430, 466, 616, 730–731, 733, 758, 765, 782–784, 869, 874–875, 877, 884–885, 887, 914, 923, 926–928, 933–934, 941, 945–947, 1103, 1192–1195, 1203–1204, 1295, 1476, 1482, 1877, 1893, 1895–1902, 1931, 1964–1966, 1972–1973, 2034, 2289, 2294, 2298, 2302, 2494, 2504, 2549, 2594–2599, 2621, 2626, 3085, 3171–3173, 3246, 3257–3258, 3482–3484, 3487–3489, 3493, 3498, 3502, 3614–3616, 3644, 3680, 3698, 3702–3704, 3706, 3717–3718, 3723, 3731
TOTAL17429266384% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3149 213 💤 0 ❌ 0 🔥 1m 8s ⏱️

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.

Python: use_agent_middleware calls private API _normalize_messages

2 participants