Skip to content

fix(core): sanitize interrupted tool call arguments#1157

Open
Alexxigang wants to merge 3 commits intoagentscope-ai:mainfrom
Alexxigang:fix/streaming-tool-call-json-recovery
Open

fix(core): sanitize interrupted tool call arguments#1157
Alexxigang wants to merge 3 commits intoagentscope-ai:mainfrom
Alexxigang:fix/streaming-tool-call-json-recovery

Conversation

@Alexxigang
Copy link
Copy Markdown
Contributor

Summary

  • sanitize interrupted streaming tool-call argument payloads before they are persisted into memory
  • add a shared JSON normalization helper used by the accumulator and provider converters
  • add regression tests for accumulator recovery plus DashScope/OpenAI formatter fallback behavior

Why this fix

When a streaming tool call is interrupted mid-JSON, AgentScope can persist a partial ToolUseBlock.content string into memory. On the next request, the DashScope/OpenAI formatter path reuses that invalid JSON as tool-call arguments, which can trigger provider-side 400 errors.

This patch fixes the bug at two layers:

  • ToolCallsAccumulator now normalizes incomplete raw argument fragments to either serialized structured input or {} before the message is finalized
  • DashScopeToolsHelper and OpenAIMessageConverter now defensively sanitize historical ToolUseBlock.content before sending it back to providers

Fixes #1147.

Validation

  • mvn -pl :agentscope-core -am spotless:apply
  • mvn -pl :agentscope-core -am "-Dtest=ToolCallsAccumulatorTest,DashScopeToolsHelperComprehensiveTest,OpenAIMessageConverterTest,ToolCallJsonUtilsTest" test

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.

Interrupted streaming tool call leaves invalid JSON arguments in memory, causing 400 errors on subsequent requests

1 participant