-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Python: [BREAKING] Removed context parameter from call_next #3829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python: [BREAKING] Removed context parameter from call_next #3829
Conversation
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this 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 ofawait 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 thatChatMiddleware.processacceptscall_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()
Motivation and Context
Resolves: #3584
Removed
contextparameter fromcall_nextmiddleware callable.Before:
After:
Contribution Checklist