Skip to content

Build and run agents you can see, understand and trust.

fix(anthropic): fix the bug that anthropic response may have text field even for the tool_use block. (#1070)

FFengIllb67858e14099
diff --git a/src/agentscope/model/_anthropic_model.py b/src/agentscope/model/_anthropic_model.py
index 31e89fd11..0120fb846 100644
--- a/src/agentscope/model/_anthropic_model.py
+++ b/src/agentscope/model/_anthropic_model.py
@@ -304,7 +304,10 @@ class AnthropicChatModel(ChatModelBase):
thinking_block["signature"] = content_block.signature
content_blocks.append(thinking_block)
- elif hasattr(content_block, "text"):
+ elif (
+ hasattr(content_block, "type")
+ and content_block.type == "text"
+ ):
content_blocks.append(
TextBlock(
type="text",