Skip to content

Conversation

@FFengIll
Copy link
Contributor

@FFengIll FFengIll commented Dec 31, 2025

AgentScope Version

1.0.10 via import agentscope; print(agentscope.__version__)

Description

This PR fixes type process error and inconsistent while parsing anthropic response which may return error result.


The buggy parser behave different for text block and may cause problem in many edge case,
ref to agentscope.model._anthropic_model.AnthropicChatModel._parse_anthropic_stream_completion_response

Bad case example: anthropic return blocks [text, tool_use], the parser return [text, text(empty)].

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with pre-commit run --all-files command
  • All tests are passing
  • Docstrings are in Google style
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

@cla-assistant
Copy link

cla-assistant bot commented Dec 31, 2025

CLA assistant check
All committers have signed the CLA.

@cla-assistant
Copy link

cla-assistant bot commented Dec 31, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Member

@qbc2016 qbc2016 left a comment

Choose a reason for hiding this comment

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

Thank you very much for your PR. I have a small question about the implementation. I'm trying to understand how this modification addresses the bad case mentioned in the PR description.

From my understanding, the logic for handling TextBlock and ToolUseBlock appears to remain the same before and after the change:

For TextBlock: both versions extract the text content
For ToolUseBlock: it wouldn't enter this branch in either case
Could you help clarify the connection? I might be missing something in my analysis.

@FFengIll
Copy link
Contributor Author

FFengIll commented Jan 4, 2026

Thank you very much for your PR. I have a small question about the implementation. I'm trying to understand how this modification addresses the bad case mentioned in the PR description.非常感谢你的公关。我有一个关于实现的小问题。我正在试图理解这个修改如何解决 PR 描述中提到的糟糕情况。

From my understanding, the logic for handling TextBlock and ToolUseBlock appears to remain the same before and after the change:据我了解,TextBlock 和 ToolUseBlock 的处理逻辑在更改前后似乎保持不变:

For TextBlock: both versions extract the text content对于 TextBlock:两个版本都提取文本内容 For ToolUseBlock: it wouldn't enter this branch in either case对于 ToolUseBlock:无论哪种情况,它都不会进入这个分支 Could you help clarify the connection? I might be missing something in my analysis.你能帮我澄清一下这个联系吗?我可能忽略了什么分析。

@qbc2016 Thanks for your response.

Yes, the logic appears identical when reviewing the old version statically

However, I encountered a runtime bug:

  1. Old version: use tool enters as an empty text block.
  2. New version: Uses strict determination to correctly render use tool as a tool block.

please check bellow debug snapshot for old version

  • look at breakpoint
  • current block is tool use
  • but it entered into text block process
image

Furthermore, using new version - type for checking ensures more consistent, reliable, and safe behavior.

@FFengIll
Copy link
Contributor Author

FFengIll commented Jan 4, 2026

With my experiment, I believe this bug is trigger by new anthropic module (agentscope use it for anthropic api).
In anthropic, pydantic and pythonic process make each block contains text attr, so we can not use hasattr(x, 'text') simply.
image

This is a feature of pydantic

Copy link
Member

@DavdGao DavdGao left a comment

Choose a reason for hiding this comment

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

LGTM

@DavdGao DavdGao merged commit b67858e into agentscope-ai:main Jan 4, 2026
17 of 20 checks passed
AlwaysBluer added a commit to AlwaysBluer/agentscope that referenced this pull request Jan 4, 2026
* main:
  chore(version): update version to 1.0.11 (agentscope-ai#1074)
  fix(anthropic): fix the bug that anthropic response may have text field even for the tool_use block. (agentscope-ai#1070)
  fix(Gemini): fix the bug that Gemini LLMs doesn't support nested JSON schema in its tools API (agentscope-ai#1050)
  fix(mcp): support to raise the exception on MCP disconnection (agentscope-ai#1024)
  feat(a2a): support A2A protocol for inter-agent communication (agentscope-ai#1027)
hiyuchang pushed a commit to hiyuchang/agentscope that referenced this pull request Jan 7, 2026
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.

3 participants