Middleware Set bug fixes, simplification, and testing#453
Middleware Set bug fixes, simplification, and testing#453rodrigobr-msft wants to merge 11 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors MiddlewareSet to simplify the middleware API surface, fixes registration behavior, updates ChannelAdapter to use the simplified entrypoint, and adds a dedicated test suite to validate MiddlewareSet behavior.
Changes:
- Refactor
MiddlewareSetto remove older “receive_*” APIs and consolidate behavior intoon_turn. - Update
ChannelAdapter.run_pipelineto invoke the middleware pipeline viaMiddlewareSet.on_turn. - Add a new test module covering middleware registration, ordering, nesting, and error propagation.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| tests/hosting_core/test_middleware_set.py | Adds new unit tests defining expected middleware pipeline behavior. |
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/middleware_set.py | Refactors middleware pipeline execution and use() registration semantics. |
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/channel_adapter.py | Switches pipeline execution to MiddlewareSet.on_turn. |
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/init.py | Exports MiddlewareSet from the hosting core package. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/storage/transcript_logger.py:120
- The updated implementation awaits the next step as logic(context), but the docstring for :param logic: still reads like a parameterless callback and doesn't mention it can be None. This can confuse middleware authors and users reading the docs.
"""Initialization for middleware.
:param context: Context for the current turn of conversation with the user.
:param logic: Function to call at the end of the middleware chain.
"""
…icrosoft/Agents-for-python into users/robrandao/middleware-set
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/storage/transcript_logger.py:120
TranscriptLoggerMiddleware.on_turn()now acceptslogicas optional (... | None), but the docstring still describes it as a required function. This can confuse middleware authors/callers.
"""Initialization for middleware.
:param context: Context for the current turn of conversation with the user.
:param logic: Function to call at the end of the middleware chain.
"""
| :param callback: A callback method to run at the end of the pipeline. | ||
| :type callback: Callable[[TurnContext], Awaitable] | ||
| :return: Result produced by the middleware pipeline. | ||
| :rtype: typing.Any | ||
| """ |
| await self._receive_activity_internal(context, None) | ||
| if logic: | ||
| await logic(context) |
The class previously was breaking in a couple of ways, and the API was a bit polluted.