Skip to content

fix(a2a): convert ToolResultBlock output maps to ContentBlock#1346

Open
JGoP-L wants to merge 3 commits into
agentscope-ai:mainfrom
JGoP-L:fix/a2a-tool-result-output-deserialization
Open

fix(a2a): convert ToolResultBlock output maps to ContentBlock#1346
JGoP-L wants to merge 3 commits into
agentscope-ai:mainfrom
JGoP-L:fix/a2a-tool-result-output-deserialization

Conversation

@JGoP-L
Copy link
Copy Markdown
Contributor

@JGoP-L JGoP-L commented May 6, 2026

AgentScope-Java Version

1.0.13-SNAPSHOT

Description

Fixes #1336.

Background

In Java-to-Java A2A communication, DataPartParser may receive a ToolResultBlock output from JSON/A2A data where nested content blocks are deserialized as map objects, such as LinkedHashMap, instead of concrete ContentBlock instances.

The previous implementation directly cast the output list to List<ContentBlock>. Because Java generic casts do not convert list elements, this could leave LinkedHashMap values inside the list and later trigger:

ClassCastException: java.util.LinkedHashMap cannot be cast to io.agentscope.core.message.ContentBlock

Changes

  • Updated DataPartParser to convert each tool result output item individually.
  • Preserved items that are already ContentBlock instances.
  • Converted map-like items to ContentBlock via the project JsonUtils codec, using the existing ContentBlock polymorphic type metadata.
  • Added a regression test covering deserialized map-list output.

How to test

mvn -pl agentscope-extensions/agentscope-extensions-a2a/agentscope-extensions-a2a-client -am -Dtest=DataPartParserTest test
mvn -pl agentscope-extensions/agentscope-extensions-a2a/agentscope-extensions-a2a-client -am -Dtest=DataPartParserTest,ToolResultBlockParserTest,ContentBlockParserRouterTest test
mvn -pl agentscope-extensions/agentscope-extensions-a2a/agentscope-extensions-a2a-client -am test
git diff --check

All commands passed.

Checklist

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

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)

@JGoP-L JGoP-L requested review from a team and Copilot May 6, 2026 03:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes A2A Java-to-Java ToolResultBlock parsing when tool output content blocks are deserialized as map objects (e.g., LinkedHashMap) by converting each list element into a concrete ContentBlock via the project JsonUtils codec, and adds a regression test to prevent the ClassCastException reported in #1336.

Changes:

  • Convert ToolResultBlock list outputs item-by-item instead of performing a raw List<ContentBlock> cast.
  • Add parseToContentBlock helper that leverages JsonUtils.getJsonCodec().convertValue(..., ContentBlock.class) for map-like items.
  • Add a regression test that simulates map-deserialized content blocks inside tool output.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
agentscope-extensions/agentscope-extensions-a2a/agentscope-extensions-a2a-client/src/main/java/io/agentscope/core/a2a/agent/message/DataPartParser.java Converts list output items to ContentBlock instances using the global JSON codec.
agentscope-extensions/agentscope-extensions-a2a/agentscope-extensions-a2a-client/src/test/java/io/agentscope/core/a2a/agent/message/DataPartParserTest.java Adds a regression test for map-list tool output parsing.

Comment on lines +91 to 97
} else if (output instanceof List<?> outputList) {
List<ContentBlock> contentBlocks = new ArrayList<>(outputList.size());
for (Object outputItem : outputList) {
contentBlocks.add(parseToContentBlock(outputItem));
}
builder.output(contentBlocks);
} else {
@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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]:ClassCastException in DataPartParser when deserializing ToolResultBlock in Java-to-Java A2A communication

2 participants