Skip to content

Python: Feat: Add finish_reason support to AgentResponse and AgentResponseUpdate#4958

Open
LEDazzio01 wants to merge 3 commits intomicrosoft:mainfrom
LEDazzio01:feature/agent-response-finish-reason
Open

Python: Feat: Add finish_reason support to AgentResponse and AgentResponseUpdate#4958
LEDazzio01 wants to merge 3 commits intomicrosoft:mainfrom
LEDazzio01:feature/agent-response-finish-reason

Conversation

@LEDazzio01
Copy link
Copy Markdown
Contributor

Fixes #4622

This PR brings python agent responses closer to parity with the .NET SDK by supporting finish_reason. It correctly captures and propagates finish_reason through AgentResponse, AgentResponseUpdate, _process_update() merging logic, and the map_chat_to_agent_update() translation layer.

Changes Made

  • Added finish_reason to AgentResponse and AgentResponseUpdate constructors.
  • Added propagation logic to merge finish_reason correctly in _types.py:_process_update().
  • Forwarded finish_reason through the map_chat_to_agent_update() function.
  • Verified everything with comprehensive unit tests for initialization, mapping, merging, and serialization in test_finish_reason.py.

…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
Copilot AI review requested due to automatic review settings March 28, 2026 01:45
@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation python labels Mar 28, 2026
@github-actions github-actions bot changed the title Feat: Add finish_reason support to AgentResponse and AgentResponseUpdate Python: Feat: Add finish_reason support to AgentResponse and AgentResponseUpdate Mar 28, 2026
Copy link
Copy Markdown
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

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_reason to AgentResponse and AgentResponseUpdate (init + update merge) and forwarded it in map_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
@LEDazzio01
Copy link
Copy Markdown
Contributor Author

Addressed all 4 Copilot comments in 83255b2:

  1. ✅ Removed unused pytest import (F401)
  2. ✅ Removed unused BaseModel import (F401)
  3. ✅ Removed unused ChatResponse import (F401)
  4. ✅ Replaced dataclasses.asdict() with .to_dict() in both serialization tests — AgentResponse and AgentResponseUpdate are SerializationMixin classes, not dataclasses, so asdict() would raise TypeError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: Python: [Feature]: Python: add finish reason to AgentResponse and AgentResponseUpdate

3 participants