Skip to content

fix(anthropic): preserve thinking signatures - #2418

Open
logicwu0 wants to merge 2 commits into
agentscope-ai:mainfrom
logicwu0:fix/2400-preserve-anthropic-thinking
Open

logicwu0 wants to merge 2 commits into
agentscope-ai:mainfrom
logicwu0:fix/2400-preserve-anthropic-thinking

Conversation

@logicwu0

Copy link
Copy Markdown
Contributor

Summary

  • preserve extended-thinking signatures in non-streaming and streaming responses
  • accumulate signature metadata with streamed thinking text
  • send signed thinking blocks back with the native Anthropic content type
  • skip unsigned thinking blocks instead of exposing them as ordinary text

Testing

  • mvn -pl agentscope-core -Dtest=ReasoningContextTest test
  • mvn -pl agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-anthropic test
  • mvn spotless:apply

Fixes #2400

@codecov

codecov Bot commented Jul 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.22222% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...pe/core/agent/accumulator/ThinkingAccumulator.java 90.90% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review — Approved ✅

Overall: Important fix for Anthropic's extended thinking feature. The PR ensures that thinking block signatures (required by Anthropic's API for multi-turn conversations with extended thinking) are preserved during streaming accumulation and message serialization.

Key Changes:

  1. ThinkingAccumulator now preserves metadata (including anthropicSignature) during streaming accumulation
  2. ThinkingBlock gets a new metadata key METADATA_ANTHROPIC_SIGNATURE for storing the signature
  3. AnthropicChatModel now extracts and stores the signature from Anthropic's response
  4. AnthropicMessageConverter includes the signature in the request payload when present

Code Quality:

  • ✅ Correct handling of metadata preservation during accumulation
  • ✅ Clean separation of concerns — signature is stored in metadata, not as a separate field
  • ✅ Proper reset of metadata in ThinkingAccumulator.reset()
  • ✅ Good Javadoc explaining the Anthropic signature requirement

CI Status: ✅ All checks passed

Verdict: Critical fix for anyone using Anthropic's extended thinking feature. Without this, multi-turn conversations with thinking blocks would fail due to missing signatures.

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/core/agent Agent runtime, pipeline, hooks, plan area/core/model Model providers and formatters labels Aug 11, 2026

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

PR title "feat(memory): add vector-based memory retrieval" is completely incorrect. Actual changes implement Anthropic extended-thinking signature round-tripping. Code is well-structured but has a latent NullPointerException in the non-streaming path: Map.of() throws NPE on null values when signature() returns null.

(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

PR title "feat(memory): add vector-based memory retrieval" is completely incorrect. Actual changes implement Anthropic extended-thinking signature round-tripping. Code is well-structured but has a latent NullPointerException in the non-streaming path: Map.of() throws NPE on null values when signature() returns null.

(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

PR title "feat(memory): add vector-based memory retrieval" is completely incorrect. Actual changes implement Anthropic extended-thinking signature round-tripping. Code is well-structured but has a latent NullPointerException in the non-streaming path: Map.of() throws NPE on null values when signature() returns null.

(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)

@oss-maintainer

Copy link
Copy Markdown
Collaborator

⚠️ Merge conflict detected

This PR currently conflicts with main and cannot be merged. Please rebase (or merge main in) and resolve the conflicts:

git fetch upstream
git checkout fix/2400-preserve-anthropic-thinking
git rebase upstream/main
# resolve conflicts, then:
git push --force-with-lease

This is a one-time reminder. Once the conflicts are resolved, comment @oss-maintainer please re-review and I will pick it up again.


Automated notification by github-manager-bot

This branch has not been deployed

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

Labels

area/core/agent Agent runtime, pipeline, hooks, plan area/core/model Model providers and formatters bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:AnthropicChatModel 将 ThinkingBlock 作为普通 text 传回 API,导致 400 错误

3 participants