Python: Feat: Add finish_reason support to AgentResponse and AgentResponseUpdate#4958
Open
LEDazzio01 wants to merge 3 commits intomicrosoft:mainfrom
Open
Python: Feat: Add finish_reason support to AgentResponse and AgentResponseUpdate#4958LEDazzio01 wants to merge 3 commits intomicrosoft:mainfrom
LEDazzio01 wants to merge 3 commits intomicrosoft:mainfrom
Conversation
…GENTS.md Fixes microsoft#4789 - Update python/packages/anthropic/AGENTS.md to document RawAnthropicClient and the layered client architecture - Add Chat Client Layer Architecture section to python/packages/core/AGENTS.md explaining the standard layer ordering (FunctionInvocationLayer -> ChatMiddlewareLayer -> ChatTelemetryLayer -> Raw/Base), per-call middleware routing via client_kwargs, and raw vs public client pattern
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Python support for propagating finish_reason through agent response types to align behavior with the .NET SDK, and documents the standard public chat client layering model.
Changes:
- Added
finish_reasontoAgentResponseandAgentResponseUpdate(init + update merge) and forwarded it inmap_chat_to_agent_update(). - Added unit tests covering init/mapping/merge/serialization scenarios for
finish_reason. - Expanded AGENTS documentation to describe the public client layer stack and clarified Anthropic client types.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| python/packages/core/tests/core/test_finish_reason.py | New tests for finish_reason behavior across agent responses/updates. |
| python/packages/core/agent_framework/_types.py | Plumbs finish_reason through AgentResponse/AgentResponseUpdate, _process_update(), and map_chat_to_agent_update(). |
| python/packages/core/AGENTS.md | Documents chat client layer architecture and raw vs public client responsibilities. |
| python/packages/anthropic/AGENTS.md | Clarifies AnthropicClient vs RawAnthropicClient and documents their layer composition. |
… serialization API - Remove unused imports: `pytest`, `BaseModel` (F401), `ChatResponse` (F401) - Replace `dataclasses.asdict()` with `.to_dict()` for both `AgentResponse` and `AgentResponseUpdate` serialization tests, since these are `SerializationMixin` classes, not dataclasses
Contributor
Author
|
Addressed all 4 Copilot comments in
|
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.
Fixes #4622
This PR brings python agent responses closer to parity with the .NET SDK by supporting
finish_reason. It correctly captures and propagatesfinish_reasonthroughAgentResponse,AgentResponseUpdate,_process_update()merging logic, and themap_chat_to_agent_update()translation layer.Changes Made
finish_reasontoAgentResponseandAgentResponseUpdateconstructors.finish_reasoncorrectly in_types.py:_process_update().finish_reasonthrough themap_chat_to_agent_update()function.test_finish_reason.py.