Skip to content

Conversation

@dmytrostruk
Copy link
Member

@dmytrostruk dmytrostruk commented Feb 10, 2026

Motivation and Context

Resolves: #3584

Removed context parameter from call_next middleware callable.

Before:

await call_next(context)

After:

await call_next()

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 Feb 10, 2026
Copilot AI review requested due to automatic review settings February 10, 2026 22:51
@dmytrostruk dmytrostruk added python breaking change Introduces changes that are not backward compatible and may require updates to dependent code. labels Feb 10, 2026
@markwallace-microsoft markwallace-microsoft added the documentation Improvements or additions to documentation label Feb 10, 2026
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Feb 10, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _middleware.py3291695%80, 83, 88, 795, 797, 799, 920, 947, 949, 974, 1055, 1059, 1183, 1187, 1248, 1322
packages/orchestrations/agent_framework_orchestrations
   _handoff.py3265682%104–105, 107, 136–137, 159–169, 171, 173, 175, 180, 278, 332, 357, 385, 393–394, 408, 459–460, 492, 532–534, 539–541, 657, 660, 667, 672, 734, 739, 746, 756, 758, 777, 779, 861–862, 894–895, 977, 984, 1056–1057, 1059
packages/purview/agent_framework_purview
   _middleware.py1120100% 
TOTAL16901210987% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
4015 225 💤 0 ❌ 0 🔥 1m 11s ⏱️

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 implements the breaking API change requested in #3584 by simplifying Python middleware chaining so call_next is invoked as await call_next() (no context parameter), and updates the core middleware pipeline, tests, and samples accordingly.

Changes:

  • Update core middleware type aliases, wrappers, and pipeline execution to use call_next: Callable[[], Awaitable[None]].
  • Update all Python samples/docs to call await call_next() instead of await call_next(context).
  • Update unit tests across core/purview/ollama/orchestrations to match the new middleware signature.

Reviewed changes

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

Show a summary per file
File Description
python/packages/core/agent_framework/_middleware.py Changes middleware callable types and pipeline next handler construction to remove the context parameter.
python/packages/core/AGENTS.md Updates middleware usage example to await call_next().
python/packages/core/tests/core/test_middleware.py Updates middleware pipeline tests to use the new call_next() signature.
python/packages/core/tests/core/test_middleware_with_agent.py Updates agent middleware tests to use call_next() with no args.
python/packages/core/tests/core/test_middleware_with_chat.py Updates chat middleware tests to use call_next() with no args.
python/packages/core/tests/core/test_middleware_context_result.py Updates context/result middleware behavior tests for the new call_next() signature.
python/packages/core/tests/core/test_function_invocation_logic.py Updates function middleware tests that previously called next_handler(context) to next_handler().
python/packages/core/tests/core/test_as_tool_kwargs_propagation.py Updates agent middleware used in as-tool kwargs propagation tests to call_next().
python/packages/purview/agent_framework_purview/_middleware.py Updates Purview middleware process signatures to accept call_next() with no args.
python/packages/purview/tests/test_middleware.py Updates Purview agent middleware tests to provide mock_next() without a context parameter.
python/packages/purview/tests/test_chat_middleware.py Updates Purview chat middleware tests to provide mock_next() without a context parameter.
python/packages/orchestrations/agent_framework_orchestrations/_handoff.py Updates handoff middleware to call await call_next() when not intercepting.
python/packages/ollama/tests/test_ollama_chat_client.py Updates sample chat middleware test to call await call_next().
python/samples/getting_started/middleware/thread_behavior_middleware.py Updates sample middleware signature and invocation to call_next().
python/samples/getting_started/middleware/shared_state_middleware.py Updates sample function middleware signatures and invocations to call_next().
python/samples/getting_started/middleware/runtime_context_delegation.py Updates middleware samples (including decorators) to call call_next() without context.
python/samples/getting_started/middleware/override_result_with_middleware.py Updates chat/agent middleware samples to call call_next() without context.
python/samples/getting_started/middleware/middleware_termination.py Updates middleware signatures to call_next() and hardens sample printing when result may be None.
python/samples/getting_started/middleware/function_based_middleware.py Updates middleware signatures to call_next() and hardens sample printing when result may be None.
python/samples/getting_started/middleware/exception_handling_with_middleware.py Updates function middleware signature and invocation to call_next().
python/samples/getting_started/middleware/decorator_middleware.py Updates decorator middleware examples to call call_next() without context.
python/samples/getting_started/middleware/class_based_middleware.py Updates class-based middleware signatures to accept call_next() with no args.
python/samples/getting_started/middleware/chat_middleware.py Updates chat middleware samples to call call_next() with no args.
python/samples/getting_started/middleware/agent_and_run_level_middleware.py Updates agent/run-level middleware samples to call call_next() and hardens sample printing when result may be None.
python/samples/getting_started/devui/weather_agent_azure/agent.py Updates chat/function middleware in devui sample to call call_next() without context.
python/samples/getting_started/agents/openai/openai_responses_client_with_agent_as_tool.py Updates function middleware sample to call call_next() without context.
python/samples/getting_started/agents/openai/openai_responses_client_basic.py Updates chat middleware sample to call call_next() without context.
python/samples/getting_started/agents/azure_ai/azure_ai_with_agent_as_tool.py Updates function middleware sample to call call_next() without context.
python/samples/concepts/tools/README.md Updates documentation examples and explanatory text to reflect call_next() without a context argument.
Comments suppressed due to low confidence (2)

python/packages/purview/agent_framework_purview/_middleware.py:168

  • # type: ignore[override] on this override appears unnecessary now that ChatMiddleware.process accepts call_next: Callable[[], Awaitable[None]]. Consider removing it so static type checking can flag actual override issues.
    async def process(
        self,
        context: ChatContext,
        call_next: Callable[[], Awaitable[None]],
    ) -> None:  # type: ignore[override]

python/packages/core/tests/core/test_middleware_with_agent.py:1716

  • This statement is unreachable.
                await call_next()

@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue Feb 11, 2026
Merged via the queue into microsoft:main with commit 1fdc4be Feb 11, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Introduces changes that are not backward compatible and may require updates to dependent code. documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: middleware: Simplify next() call without passing context

4 participants