Skip to content

fix(model): preserve Anthropic streaming content blocks - #2495

Merged
qbc2016 merged 1 commit into
agentscope-ai:mainfrom
RICARDO51167:fix/anthropic-stream-blocks
Sep 15, 2026
Merged

qbc2016 merged 1 commit into
agentscope-ai:mainfrom
RICARDO51167:fix/anthropic-stream-blocks

Conversation

@RICARDO51167

Copy link
Copy Markdown
Contributor

AgentScope Version

2.0.7.post1

Description

Fixes #2494.

Anthropic streaming responses currently share one ID for all thinking blocks and one ID for all text blocks. This merges separate blocks, overwrites earlier thinking signatures, and changes their order relative to tool calls.

This PR assigns separate block IDs by event.index, preserving each block's content, signature, and position while continuing to accumulate deltas within the same block.

Regression tests cover:

  • Multiple thinking blocks with separate signatures.
  • Thinking blocks containing only signatures.
  • Text blocks before and after a tool call.
  • Thinking blocks separated by redacted thinking.
  • Multiple deltas within one block.

The tests compare streaming and non-streaming results and verify the assistant message formatted for the next request.

Validation

  • Related model, response aggregation, and Anthropic formatter tests: 80 passed, 10 subtests passed.
  • pre-commit run --all-files: passed.
  • The full test suite did not pass locally. Remaining failures include Redis/Lua, DingTalk, and MCP tests; Redis-backed tests reported missing Lua EVAL support.

Checklist

  • An issue has been created for this PR.
  • I have read CONTRIBUTING.md.
  • Docstrings follow the project style.
  • Documentation impact reviewed; no public API or configuration changes.
  • Code is ready for review.

@BlueX888

BlueX888 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for picking this up. I ran the repro script from #2494 against this branch: stream=True now yields thinking(sig_A) → thinking(sig_B) → tool_use, identical to stream=False and to the SDK's accumulate_event, and the replayed assistant message keeps both signatures. tests/model_anthropic_test.py passes locally (27 passed). LGTM from the reporter's side.

@qbc2016 qbc2016 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

@qbc2016
qbc2016 merged commit d0f4be4 into agentscope-ai:main Sep 15, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: AnthropicChatModel streaming merges all thinking blocks of one response into a single block, keeping only the last signature

3 participants