Skip to content

Comments

Python: Fixed middleware and multimodal input samples#4022

Merged
dmytrostruk merged 6 commits intomicrosoft:mainfrom
dmytrostruk:more-sample-fixes
Feb 18, 2026
Merged

Python: Fixed middleware and multimodal input samples#4022
dmytrostruk merged 6 commits intomicrosoft:mainfrom
dmytrostruk:more-sample-fixes

Conversation

@dmytrostruk
Copy link
Member

Motivation and Context

  • Fixed runtime kwargs propagation from agent.run() to FunctionInvocationContext.kwargs in function middleware — kwargs like user_id were silently dropped and never reached middleware
  • Fixed get_response() calls in multimodal input samples to pass [message] (list) instead of message (single object), which caused TypeError: 'Message' object is not iterable
  • Fixed streaming branch in weather override middleware sample (replace broken _update_hook with proper AsyncIterable stream override, fixed Role.ASSISTANT → "assistant")
  • Fixed exception handling middleware sample (tuple literal had trailing comma creating a tuple instead of string concatenation)

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 and others added 5 commits February 17, 2026 14:49
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>
@dmytrostruk dmytrostruk self-assigned this Feb 17, 2026
Copilot AI review requested due to automatic review settings February 17, 2026 23:37
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Feb 17, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _agents.py3234287%425, 429, 481, 846, 882, 959–962, 1023–1025, 1146, 1162, 1164, 1177, 1183, 1219, 1221, 1230–1235, 1240, 1242, 1248–1249, 1256, 1258–1259, 1267–1268, 1271–1273, 1281–1282, 1284, 1289, 1291
   _types.py9988791%49, 58–59, 113, 118, 137, 139, 143, 147, 149, 151, 153, 171, 175, 201, 223, 228, 233, 237, 263, 267, 613–614, 985, 1047, 1064, 1082, 1087, 1105, 1115, 1132–1133, 1135, 1153–1154, 1156, 1163–1164, 1166, 1201, 1212–1213, 1215, 1253, 1480, 1532, 1623–1628, 1650, 1655, 1821, 1833, 2076, 2085, 2106, 2201, 2426, 2633, 2703, 2715, 2733, 2931–2933, 2936–2938, 2942, 2947, 2951, 3035–3037, 3066, 3120, 3139–3140, 3143–3147, 3153
TOTAL21168332284% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
4164 239 💤 0 ❌ 0 🔥 1m 12s ⏱️

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 critical bugs in Python middleware and multimodal input samples that would have caused runtime failures.

Changes:

  • Fixed runtime kwargs propagation from agent.run() to FunctionInvocationContext.kwargs in function middleware - kwargs like user_id were silently dropped
  • Fixed get_response() API calls in three multimodal input samples to pass [message] (list) instead of message (single object), preventing TypeError: 'Message' object is not iterable
  • Fixed streaming override in weather middleware sample by replacing broken with_transform_hook approach with proper AsyncIterable stream override and correcting Role.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

@dmytrostruk dmytrostruk added this pull request to the merge queue Feb 18, 2026
Merged via the queue into microsoft:main with commit 2dd731f Feb 18, 2026
25 checks passed
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.

4 participants