Skip to content

feat(anthropic): support extended thinking round trips - #2233

Open
dailingtao wants to merge 10 commits into
agentscope-ai:mainfrom
dailingtao:codex/issue-2219-anthropic-thinking
Open

feat(anthropic): support extended thinking round trips#2233
dailingtao wants to merge 10 commits into
agentscope-ai:mainfrom
dailingtao:codex/issue-2219-anthropic-thinking

Conversation

@dailingtao

@dailingtao dailingtao commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.0.3-SNAPSHOT

Description

Fixes #2219.

This PR adds Anthropic extended-thinking round-trip support while preserving Anthropic-native signed content across streaming, multi-turn, and tool-use flows.

  • map GenerateOptions.thinkingBudget to Anthropic manual thinking (type: enabled with budget_tokens)
  • allow explicit adaptive thinking through additionalBodyParams; per-call configuration overrides defaults, while conflicting manual/adaptive configurations fail locally
  • preserve signed and redacted thinking blocks in ThinkingBlock metadata and restore them in their original order when conversation history is sent back to Anthropic
  • preserve the complete assistant message when signed thinking accompanies parallel tool calls, and group their matching tool results into one user message
  • preserve thinking metadata while streaming chunks are accumulated by ReasoningContext
  • reject malformed Anthropic-owned thinking metadata instead of silently converting it to ordinary text; unsigned/non-Anthropic thinking keeps the existing text fallback
  • keep the latest main prompt-caching token accounting when merging streaming parser state
  • document adaptive and manual thinking configuration in English and Chinese
  • add an Anthropic SDK + MockWebServer HTTP round-trip regression test, which verifies the serialized follow-up request locally without a Cloud API key

Validation

  • mvn -pl agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-anthropic -am -Dtest=AnthropicResponseParserTest,AnthropicMessageConverterTest,AnthropicToolsHelperTest,AnthropicChatModelThinkingRoundTripTest -Dsurefire.failIfNoSpecifiedTests=false test
    • 83 tests, 0 failures, 0 errors, 1 skipped
  • mvn -pl agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-anthropic -am clean verify
    • AgentScope Core: 2,296 tests, 0 failures, 0 errors, 9 skipped
    • Anthropic model extension: 186 tests, 0 failures, 0 errors, 1 skipped
    • Anthropic JAR, sources JAR, and Javadoc JAR built successfully
  • git diff --check

Checklist

  • Code formatting verified by Spotless during clean verify
  • All relevant tests are passing
  • Javadoc comments follow project conventions
  • Related English and Chinese documentation has been updated
  • Code is ready for review

@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

@AgentScopeJavaBot AgentScopeJavaBot added enhancement New feature or request area/core/model Model providers and formatters area/ext/integration External protocols & middleware integrations labels Jul 16, 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

Aspect Count
🟢 Nitpick (信息性建议,不阻塞合并) 3
🟡 Recommended (建议修复,但不阻塞合并) 2

Overall Assessment: COMMENT — Well-designed extended thinking round-trip support; two defensive-programming improvements recommended before merge.

@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

Aspect Count
🟢 Nitpick (信息性建议,不阻塞合并) 3
🟡 Recommended (建议修复,但不阻塞合并) 2

Overall Assessment: COMMENT — Well-designed extended thinking round-trip support; two defensive-programming improvements recommended before merge.

@dailingtao

Copy link
Copy Markdown
Contributor Author

Hi @jujn, it looks like AgentScopeJavaBot may be stuck on this PR.

The bot submitted the same review summary twice for commit d7f6dea4,
reporting 3 nitpicks and 2 recommendations, but no inline comments or
review threads were created, so I couldn't see the specific findings.

The latest head is now 1bcd3d7c, and the new review request is still
pending. I also don't have permission to re-request reviewers.

Could you please help re-trigger the AI review or check whether the bot
service is working correctly?

All current CI checks are passing. Thanks!

@jujn

jujn commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Thanks for your contribution. I'll review it later when I have time.

@dailingtao dailingtao closed this Aug 22, 2026
@jujn jujn reopened this Aug 22, 2026
@jujn

jujn commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

为什么关闭了?因为PR比较大,之前一直抽不出完整的时间去审。预计 2.0.4 会合入

@jujn jujn self-assigned this Aug 22, 2026
@dailingtao

Copy link
Copy Markdown
Contributor Author

为什么关闭了?因为PR比较大,之前一直抽不出完整的时间去审。预计 2.0.4 会合入

好的 thanks ,以为不合入了 看到dingding群里的一个哥们说 可以抽空把自己没合入的PR 清一下 减小review的压力

…ropic-thinking

# Conflicts:
#	agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-anthropic/src/main/java/io/agentscope/extensions/model/anthropic/formatter/AnthropicResponseParser.java
#	agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-anthropic/src/test/java/io/agentscope/extensions/model/anthropic/formatter/AnthropicResponseParserTest.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core/model Model providers and formatters area/ext/integration External protocols & middleware integrations enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Anthropic 推理增强

3 participants