Python: Fixed middleware and multimodal input samples#4022
Merged
dmytrostruk merged 6 commits intomicrosoft:mainfrom Feb 18, 2026
Merged
Python: Fixed middleware and multimodal input samples#4022dmytrostruk merged 6 commits intomicrosoft:mainfrom
dmytrostruk merged 6 commits intomicrosoft:mainfrom
Conversation
The streaming branch of weather_override_middleware only prefixed the original weather data via a transform hook instead of replacing the content with the 'perfect weather' override like the non-streaming branch does. Replace with a new ResponseStream that yields the override content as ChatResponseUpdate chunks. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
Python Test Coverage Report •
Python Unit Test Overview
|
|||||||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes critical bugs in Python middleware and multimodal input samples that would have caused runtime failures.
Changes:
- Fixed runtime kwargs propagation from
agent.run()toFunctionInvocationContext.kwargsin function middleware - kwargs likeuser_idwere silently dropped - Fixed
get_response()API calls in three multimodal input samples to pass[message](list) instead ofmessage(single object), preventingTypeError: 'Message' object is not iterable - Fixed streaming override in weather middleware sample by replacing broken
with_transform_hookapproach with properAsyncIterablestream override and correctingRole.ASSISTANT→"assistant" - Fixed exception handling middleware where tuple literal had trailing comma creating a tuple instead of string concatenation
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| python/packages/core/agent_framework/_agents.py | Merges runtime kwargs into additional_function_arguments to propagate them to function middleware |
| python/packages/core/agent_framework/_types.py | Cosmetic formatting change to tools type annotation (single line instead of multi-line) |
| python/packages/core/tests/core/test_middleware_with_agent.py | Adds 4 comprehensive tests for kwargs propagation behavior |
| python/samples/02-agents/middleware/override_result_with_middleware.py | Fixes streaming override logic and removes non-existent Role enum usage |
| python/samples/02-agents/middleware/exception_handling_with_middleware.py | Fixes tuple literal bug by removing trailing comma for proper string concatenation |
| python/samples/02-agents/multimodal_input/openai_chat_multimodal.py | Fixes get_response() calls to pass list of messages and updates comment |
| python/samples/02-agents/multimodal_input/azure_responses_multimodal.py | Fixes get_response() calls to pass list of messages and updates comment |
| python/samples/02-agents/multimodal_input/azure_chat_multimodal.py | Fixes get_response() calls to pass list of messages and updates comment |
giles17
approved these changes
Feb 18, 2026
TaoChenOSU
reviewed
Feb 18, 2026
python/samples/02-agents/middleware/exception_handling_with_middleware.py
Show resolved
Hide resolved
TaoChenOSU
approved these changes
Feb 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Contribution Checklist