Repository navigation
fix(anthropic): report the stop reason of a response as its finish reason - #3852
Merged
jujn merged 1 commit intoOct 30, 2026
Merged
Conversation
…ason AnthropicResponseParser never set ChatResponse.finishReason, unlike the OpenAI, DashScope, Gemini and Ollama parsers, so a reply cut off at max_tokens looked like a normal completion. Read it from Message.stopReason() for a complete message and from the message_delta event when streaming. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
jujn
approved these changes
Oct 30, 2026
Buktal
added a commit
to Buktal/agentscope-java
that referenced
this pull request
Oct 30, 2026
Resolve conflicts with agentscope-ai#3852 in AnthropicResponseParser(.Test): keep this branch's native thinking signature/redacted-thinking replay and content-block metadata, and adopt main's finishReason handling (StopReason::asString wire value) in parseMessage and message_delta.
chickenlj
pushed a commit
that referenced
this pull request
Nov 13, 2026
…ason (#3852) Backport the verified fix to the 2.0.x implementation and retain its existing public contracts where the upstream kernel differs. (cherry picked from commit b604eca) Constraint: No AgentScope Service or SDK migration Confidence: high Not-tested: Whole-repository verification pending after lane integration
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.
AgentScope-Java Version
2.1.0-SNAPSHOT (
main)Description
ChatResponsehas afinishReason, whichReasoningContextuses to detect a reply cut off at the token limit (length,max_tokens; its comment already expects Anthropic to reportmax_tokens). The OpenAI, DashScope, Gemini and Ollama parsers fill it in, butAnthropicResponseParsernever did, so every Anthropic response had anullfinish reason and a reply truncated atmax_tokenslooked like a normal completion.Fix:
parseMessagenow setsfinishReasonfromMessage.stopReason(), and the streaming path reads it from themessage_deltaevent (delta().stopReason()), where Anthropic reports it. The value is the API's own string (end_turn,max_tokens,stop_sequence,tool_use, ...), the same style the other parsers use, and it staysnullwhen the API sends no stop reason.Tests:
AnthropicResponseParserTestgains cases for a non-streamed message withmax_tokens, one without a stop reason, and a streamedmessage_deltawithmax_tokens. The two existing tests that mock amessage_deltaevent now also mock itsdelta(), which the parser reads. The new cases fail onmain(expected: <max_tokens> but was: <null>) and pass with the change:No request was sent to the live API.
This change was prepared with the assistance of an AI coding agent (Claude).
Checklist
mvn spotless:applymvn test) — the Anthropic module's tests; the full suite was not runThis change was prepared with the assistance of an AI coding agent (Claude).