Skip to content

fix(anthropic): serialize non-streaming tool arguments as JSON - #4031

Merged
jujn merged 1 commit into
agentscope-ai:mainfrom
iluv7:fix/anthropic-nonstream-tool-arguments
Nov 7, 2026
Merged

jujn merged 1 commit into
agentscope-ai:mainfrom
iluv7:fix/anthropic-nonstream-tool-arguments

Conversation

@iluv7

@iluv7 iluv7 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Problem

Non-streaming Anthropic tool responses set ToolUseBlock.content using JsonValue.toString(). Non-empty arguments can become Java-style map text such as {store_id=S001, month=2026-10} instead of JSON. The agent accumulator rejects those arguments as malformed, so tools do not execute even though the API request succeeds.

This independent bug was reported during validation of #4019: #4018 (comment). This PR is based on current upstream main and does not include or depend on #4019.

Changes

  • Serialize the already-parsed argument map with the existing JSON codec, keeping input and content consistent.
  • Add regression coverage using real SDK-deserialized non-streaming responses through ReAct accumulation, tool execution, and the next model turn. Cover non-empty arguments, nested objects/arrays/null values, and empty objects.

Validation

  • Before the fix, both non-empty argument cases fail with JSON deserialization errors; the empty-object case passes.
  • mvn -T1C -pl agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-anthropic -am spotless:apply test passed: core 2,993 tests (9 skipped), Anthropic 259 tests (1 existing skip), no failures/errors.
  • The same module/dependency spotless:check and git diff --check passed.
  • Live DeepSeek verification: deepseek-flash via the official Anthropic-compatible endpoint, stream(false), thinking disabled. A complete ReActAgent run generated non-empty arguments (store_id=S001, month=2026-10), executed the tool exactly once with those values, and returned the supplied sales value (1,286,400).
  • Full-repository clean verify and live thinking-enabled verification were not run.

@jujn
jujn merged commit e473edb into agentscope-ai:main Nov 7, 2026
5 checks passed
chickenlj pushed a commit that referenced this pull request Nov 13, 2026
Backport the verified fix to the 2.0.x implementation and retain its
existing public contracts where the upstream kernel differs.

(cherry picked from commit e473edb)
Constraint: No AgentScope Service or SDK migration
Confidence: high
Not-tested: Whole-repository verification pending after lane integration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 紧急不重要

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants