fix(a2a): convert ToolResultBlock output maps to ContentBlock#1346
Open
JGoP-L wants to merge 3 commits into
Open
fix(a2a): convert ToolResultBlock output maps to ContentBlock#1346JGoP-L wants to merge 3 commits into
JGoP-L wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
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
ToolResultBlocklist outputs item-by-item instead of performing a rawList<ContentBlock>cast. - Add
parseToContentBlockhelper that leveragesJsonUtils.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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AgentScope-Java Version
1.0.13-SNAPSHOT
Description
Fixes #1336.
Background
In Java-to-Java A2A communication,
DataPartParsermay receive aToolResultBlockoutput from JSON/A2A data where nested content blocks are deserialized as map objects, such asLinkedHashMap, instead of concreteContentBlockinstances.The previous implementation directly cast the output list to
List<ContentBlock>. Because Java generic casts do not convert list elements, this could leaveLinkedHashMapvalues inside the list and later trigger:Changes
DataPartParserto convert each tool result output item individually.ContentBlockinstances.ContentBlockvia the projectJsonUtilscodec, using the existingContentBlockpolymorphictypemetadata.How to test
All commands passed.
Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)