Skip to content

Return final answer first in AnthropicChatModel - #7001

Open
iuliiasobolevska wants to merge 1 commit into
spring-projects:mainfrom
iuliiasobolevska:anthropic-primary-generation
Open

iuliiasobolevska wants to merge 1 commit into
spring-projects:mainfrom
iuliiasobolevska:anthropic-primary-generation

Conversation

@iuliiasobolevska

Copy link
Copy Markdown
Contributor

Summary

AnthropicChatModel currently adds thinking and redacted-thinking generations before the accumulated assistant response. Since ChatResponse.getResult() returns the first generation, callers receive reasoning content instead of the final answer, and typed ChatClient conversion can fail on empty redacted-thinking content.

This change places the final AnthropicAssistantMessage first while preserving individual thinking generations in getResults() and signed thinking content for tool-call replay.

Fixes #7000

Testing

./mvnw -Dmaven.build.cache.enabled=false -pl models/spring-ai-anthropic clean package

Tests run: 126, failures: 0, errors: 0, skipped: 0. Formatting, Checkstyle, JAR packaging, sources, and Javadocs also passed.

AI assistance was used for investigation, implementation, and test preparation.

Anthropic thinking blocks were added before the accumulated assistant
response, so ChatResponse.getResult() exposed reasoning instead of the
final answer. Place the assistant generation first while retaining
thinking generations and replay state.

Fixes spring-projects#7000

Signed-off-by: Iuliia Sobolevska <isobolevska@netflix.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AnthropicChatModel makes thinking blocks the primary generation

4 participants