-
Notifications
You must be signed in to change notification settings - Fork 283
fix: empty content in ToolCalls #643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Change-Id: I9d13239d03f01ebebf281b0af1d0766a882c86b7
Summary of ChangesHello @AlbumenJ, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a specific bug where the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request aims to fix an issue with empty content in ToolCalls. The change replaces a null value with "{}" for the content field when no raw content is accumulated.
While this is a good step, it can lead to inconsistencies between the input and content fields of a ToolUseBlock. I've provided a suggestion to ensure that the content field is always a correct JSON representation of the input arguments, which provides a more robust fix.
| .name(name) | ||
| .input(finalArgs) | ||
| .content(rawContentStr.isEmpty() ? null : rawContentStr) | ||
| .content(rawContentStr.isEmpty() ? "{}" : rawContentStr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While changing null to "{}" for empty content is a good step to avoid nulls, it can introduce an inconsistency. When input arguments are provided via tool call chunks but no raw content is streamed, finalArgs will contain the arguments, but content will be an empty JSON object "{}", which is incorrect.
A more robust approach is to generate the content from finalArgs if rawContentStr is empty. This ensures that content is always a correct JSON representation of input. This also covers the case where finalArgs is empty, as serializing an empty map results in "{}".
It would also be beneficial to add a unit test to cover this scenario.
| .content(rawContentStr.isEmpty() ? "{}" : rawContentStr) | |
| .content(rawContentStr.isEmpty() ? JsonUtils.getJsonCodec().toJson(finalArgs) : rawContentStr) |
There was a problem hiding this 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 attempts to fix an issue with empty content in ToolCalls by changing the behavior of ToolCallsAccumulator to return "{}" instead of null when the accumulated raw content string is empty.
Changes:
- Modified ToolCallsAccumulator.build() to set content to
"{}"instead ofnullwhen rawContentStr is empty
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| .name(name) | ||
| .input(finalArgs) | ||
| .content(rawContentStr.isEmpty() ? null : rawContentStr) | ||
| .content(rawContentStr.isEmpty() ? "{}" : rawContentStr) |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing empty content from null to "{}" may cause validation issues. The ToolValidator.validateInput() method (used in ToolExecutor line 150) validates the content field as JSON against the tool's schema. An empty object "{}" will be validated against the schema, which may fail if the tool requires specific parameters. When content is empty and should rely on the input map, it's better to keep it as null so the validation can use the properly structured input map instead of trying to validate an empty JSON object.
| .content(rawContentStr.isEmpty() ? "{}" : rawContentStr) | |
| .content(rawContentStr.isEmpty() ? null : rawContentStr) |
| .name(name) | ||
| .input(finalArgs) | ||
| .content(rawContentStr.isEmpty() ? null : rawContentStr) | ||
| .content(rawContentStr.isEmpty() ? "{}" : rawContentStr) |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent behavior with existing code patterns. Multiple converters (DashScopeToolsHelper line 242, OpenAIMessageConverter line 328, GeminiMessageConverter line 97) check for non-empty content before using it. They use the pattern "if (content != null && !content.isEmpty())" which assumes null is a valid value for empty content. Changing this to "{}" breaks this pattern and may cause these converters to use "{}" when they should fall back to the input map.
| .content(rawContentStr.isEmpty() ? "{}" : rawContentStr) | |
| .content(rawContentStr.isEmpty() ? null : rawContentStr) |
| .name(name) | ||
| .input(finalArgs) | ||
| .content(rawContentStr.isEmpty() ? null : rawContentStr) | ||
| .content(rawContentStr.isEmpty() ? "{}" : rawContentStr) |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ToolUseBlock.getContent() javadoc (line 132) explicitly states "The raw content, or null if not set". This change violates the documented contract by returning "{}" instead of null when no content is set. This is a breaking API change that could affect consumers relying on null checks.
| .content(rawContentStr.isEmpty() ? "{}" : rawContentStr) | |
| .content(rawContentStr.isEmpty() ? null : rawContentStr) |
| .name(name) | ||
| .input(finalArgs) | ||
| .content(rawContentStr.isEmpty() ? null : rawContentStr) | ||
| .content(rawContentStr.isEmpty() ? "{}" : rawContentStr) |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description is empty and does not explain why this change is needed, what problem it solves, or what the expected behavior should be. This makes it difficult to understand if the fix is correct or if there might be a better approach.
| .name(name) | ||
| .input(finalArgs) | ||
| .content(rawContentStr.isEmpty() ? null : rawContentStr) | ||
| .content(rawContentStr.isEmpty() ? "{}" : rawContentStr) |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test coverage for the changed behavior. The test suite (ToolCallsAccumulatorTest) does not have any tests verifying what happens when content is empty after accumulation. Test testBuildSavesRawContentToContentField only tests non-empty content. A test should be added to verify the behavior when rawContentStr is empty and ensure it aligns with the API contract and downstream consumers' expectations.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Change-Id: I9d13239d03f01ebebf281b0af1d0766a882c86b7 ## AgentScope-Java Version [The version of AgentScope-Java you are working on, e.g. 1.0.7, check your pom.xml dependency version or run `mvn dependency:tree | grep agentscope-parent:pom`(only mac/linux)] ## Description [Please describe the background, purpose, changes made, and how to test this PR] ## 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.) - [ ] Code is ready for review
Change-Id: I9d13239d03f01ebebf281b0af1d0766a882c86b7
AgentScope-Java Version
[The version of AgentScope-Java you are working on, e.g. 1.0.7, check your pom.xml dependency version or run
mvn dependency:tree | grep agentscope-parent:pom(only mac/linux)]Description
[Please describe the background, purpose, changes made, and how to test this PR]
Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)