Python: [BREAKING] Moved to a single get_response and run API#3379
Open
eavanvalkenburg wants to merge 98 commits intomicrosoft:mainfrom
Open
Python: [BREAKING] Moved to a single get_response and run API#3379eavanvalkenburg wants to merge 98 commits intomicrosoft:mainfrom
eavanvalkenburg wants to merge 98 commits intomicrosoft:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR consolidates the Python Agent Framework's streaming and non-streaming APIs into a unified interface. The primary changes include:
Changes:
- Unified
run()andget_response()methods withstreamparameter replacing separaterun_stream()andget_streaming_response()methods - Migration from decorator-based (
@use_instrumentation,@use_function_invocation) to mixin-based architecture for telemetry and function invocation - Introduction of
ResponseStreamclass for unified stream handling with hooks, finalizers, and teardown support - Renamed
AgentExecutionExceptiontoAgentRunException
Reviewed changes
Copilot reviewed 84 out of 85 changed files in this pull request and generated 28 comments.
Show a summary per file
| File | Description |
|---|---|
_types.py |
Added ResponseStream class for unified streaming, updated prepare_messages to handle None |
_clients.py |
Refactored BaseChatClient with unified get_response() method, introduced FunctionInvokingChatClient mixin |
openai/_responses_client.py |
Consolidated streaming/non-streaming into single _inner_get_response() method |
openai/_chat_client.py |
Similar consolidation for chat completions API |
openai/_assistants_client.py |
Unified assistants API with stream parameter |
_workflows/_workflow.py |
Consolidated run() and run_stream() into single run(stream=bool) method |
_workflows/_agent.py |
Updated WorkflowAgent.run() to use stream parameter |
| Test files (multiple) | Updated all tests to use run(stream=True) and get_response(stream=True) |
| Sample files (multiple) | Updated samples to demonstrate new unified API |
| Provider clients | Updated all provider implementations (Azure, Anthropic, Bedrock, Ollama, etc.) to use mixins |
python/packages/core/agent_framework/openai/_assistants_client.py
Outdated
Show resolved
Hide resolved
python/packages/core/tests/workflow/test_agent_executor_tool_calls.py
Outdated
Show resolved
Hide resolved
07afd46 to
dd65afa
Compare
Member
32f0473 to
5c78d91
Compare
TaoChenOSU
reviewed
Jan 30, 2026
python/packages/anthropic/agent_framework_anthropic/_chat_client.py
Outdated
Show resolved
Hide resolved
python/packages/core/agent_framework/_workflows/_agent_executor.py
Outdated
Show resolved
Hide resolved
ebfc3b0 to
92995e6
Compare
Member
Author
|
Fixes lingering CI failures: import missing response types in streaming telemetry finalizers, move AG-UI tests to ag_ui_tests with config updates, and track service thread IDs in AG-UI test client.\n\nChecks: uv run poe fmt/lint/pyright/mypy; uv run poe all-tests. |
moonbox3
reviewed
Feb 3, 2026
a8f7c92 to
a5dadf8
Compare
dmytrostruk
approved these changes
Feb 4, 2026
92df8e3 to
a99fdba
Compare
- Fix a2a tests: Role comparisons and ChatMessage signatures - Fix lab tau2 source: Role enum comparison in flip_messages, log_messages, sliding_window - Fix lab tau2 tests: ChatMessage signatures and Role comparisons
After rebasing on upstream/main which merged PR microsoft#3647 (Types API Review improvements), fix all packages to use the new API: - ChatMessage: Use keyword args (role=, text=, contents=) instead of positional args - Role: Compare using .value attribute since it's now an enum Packages fixed: - ag-ui: Fixed Role value extraction bugs in _message_adapters.py - anthropic: Fixed ChatMessage and Role comparisons in tests - azure-ai: Fixed Role comparison in _client.py - azure-ai-search: Fixed ChatMessage and Role in source/tests - bedrock: Fixed ChatMessage signatures in tests - chatkit: Fixed ChatMessage and Role in source/tests - copilotstudio: Fixed ChatMessage and Role in tests - declarative: Fixed ChatMessage in _executors_agents.py - mem0: Fixed ChatMessage and Role in source/tests - purview: Fixed ChatMessage in source/tests
- durabletask: Use str() fallback in role value extraction - core: Fix ChatMessage in _orchestrator_helpers.py to use keyword args - core: Add type ignore for _conversation_state.py contents deserialization - ag-ui: Fix type ignore comments (call-overload instead of arg-type) - azure-ai-search: Fix get_role_value type hint to accept Any - lab: Move get_role_value to module level with Any type hint
- Increase job timeout from 10 to 15 minutes - Reduce per-test timeout to 60s (was 900s/300s) - Add --timeout_method thread for better timeout handling - Add --timeout-verbose to see which tests are slow - Reduce retries from 3 to 2 and delay from 10s to 5s This ensures individual test timeouts are shorter than the job timeout, providing better visibility when tests hang. With 60s timeout and 2 retries, worst case per test is ~180s.
- Fix ChatMessage positional args in docstrings: _serialization.py, _threads.py, _middleware.py - Fix ChatMessage in tau2 runner.py - Fix role comparison in _orchestrator_helpers.py to use .value - Fix role comparison in _group_chat.py docstring example - Fix role assertions in test_durable_entities.py to use .value
… no tools OpenAI API requires tool_choice and parallel_tool_calls to only be present when tools are specified. Restored the logic that removes these options when there are no tools. - Restored check in _chat_client.py to remove tool_choice and parallel_tool_calls when no tools present - Restored same logic in _responses_client.py - Reverted test to expect the correct behavior
- Refactor streaming function invocation to use get_final_response() on inner streams - Fix MiddlewareTermination to accept result parameter for passing results - Fix _AutoHandoffMiddleware to use MiddlewareTermination instead of context.terminate - Fix AgentMiddlewareLayer.run() to properly forward function/chat middleware - Remove duplicate middleware registration in AgentMiddlewareLayer.__init__ - Fix exception handling in _auto_invoke_function to properly capture termination - Fix mypy errors in core package - Update tests to use stream=True parameter for unified run API
ca3d898 to
3577435
Compare
- Merge testutils.py into conftest.py for azurefunctions integration tests - Merge dt_testutils.py into conftest.py for durabletask integration tests - Convert all integration tests to use fixtures instead of direct imports (fixes ModuleNotFoundError with --import-mode=importlib) - Add sample_helper fixture for azurefunctions tests - Add agent_client_factory and orchestration_helper fixtures for durabletask - Integration tests now skip with descriptive messages when services unavailable - Restructure devui tests into tests/devui/ with proper conftest.py - Add test organization guidelines to CODING_STANDARD.md - Remove __init__.py from test directories per pytest best practices
The hook was skipping all tests in the test session, not just integration tests. Now it only skips items in the integration_tests directory.
Use patch.object on the imported module instead of @patch with string path to ensure the mock takes effect regardless of import timing.
westey-m
approved these changes
Feb 5, 2026
Increase from 2 to 8 seconds to allow time for: - Python startup and module imports - Azure OpenAI client creation - Agent registration with DTS worker - Worker connection to DTS This helps prevent test failures in CI where the first tests may run before the worker is fully ready to process requests.
The _consume_stream method now expects a ResponseStream that can provide a final AgentResponse via get_final_response(). Update the test to use ResponseStream with AgentResponse.from_updates as the finalizer.
westey-m
approved these changes
Feb 5, 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
Summary
ResponseStream[ChatResponseUpdate, ChatResponse]toResponseStream[AgentResponseUpdate, AgentResponse], but the object has a classmethod calledwrapthat is used to wrap the ResponseStream from the chat client into the new ResponseStream in the Agent.Description
Contribution Checklist
Fixes #3585
Fixes #3607
Fixes #3617
Fixes #3581
Fixes #3610