Skip to content

Conversation

@AlbumenJ
Copy link
Collaborator

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
@AlbumenJ AlbumenJ requested review from a team and Copilot January 23, 2026 02:58
@gemini-code-assist
Copy link

Summary of Changes

Hello @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 content field within ToolCalls could be set to null if the raw content string was empty. The change ensures that the content field is always a valid JSON string, defaulting to an empty JSON object ("{}") when no specific content is provided. This improves the robustness and compatibility of tool call handling with systems that expect a JSON format.

Highlights

  • ToolCalls Content Handling: Modified the ToolCallsAccumulator to ensure that when the rawContentStr for a tool call's content is empty, it is set to an empty JSON object string ("{}") instead of null. This prevents potential issues with downstream systems expecting a valid JSON structure.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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)

Choose a reason for hiding this comment

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

high

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.

Suggested change
.content(rawContentStr.isEmpty() ? "{}" : rawContentStr)
.content(rawContentStr.isEmpty() ? JsonUtils.getJsonCodec().toJson(finalArgs) : rawContentStr)

Copy link
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 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 of null when 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)
Copy link

Copilot AI Jan 23, 2026

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.

Suggested change
.content(rawContentStr.isEmpty() ? "{}" : rawContentStr)
.content(rawContentStr.isEmpty() ? null : rawContentStr)

Copilot uses AI. Check for mistakes.
.name(name)
.input(finalArgs)
.content(rawContentStr.isEmpty() ? null : rawContentStr)
.content(rawContentStr.isEmpty() ? "{}" : rawContentStr)
Copy link

Copilot AI Jan 23, 2026

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.

Suggested change
.content(rawContentStr.isEmpty() ? "{}" : rawContentStr)
.content(rawContentStr.isEmpty() ? null : rawContentStr)

Copilot uses AI. Check for mistakes.
.name(name)
.input(finalArgs)
.content(rawContentStr.isEmpty() ? null : rawContentStr)
.content(rawContentStr.isEmpty() ? "{}" : rawContentStr)
Copy link

Copilot AI Jan 23, 2026

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.

Suggested change
.content(rawContentStr.isEmpty() ? "{}" : rawContentStr)
.content(rawContentStr.isEmpty() ? null : rawContentStr)

Copilot uses AI. Check for mistakes.
.name(name)
.input(finalArgs)
.content(rawContentStr.isEmpty() ? null : rawContentStr)
.content(rawContentStr.isEmpty() ? "{}" : rawContentStr)
Copy link

Copilot AI Jan 23, 2026

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.

Copilot uses AI. Check for mistakes.
.name(name)
.input(finalArgs)
.content(rawContentStr.isEmpty() ? null : rawContentStr)
.content(rawContentStr.isEmpty() ? "{}" : rawContentStr)
Copy link

Copilot AI Jan 23, 2026

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.

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Jan 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@AlbumenJ AlbumenJ merged commit 757981d into agentscope-ai:main Jan 24, 2026
11 checks passed
Alexxigang pushed a commit to Alexxigang/agentscope-java that referenced this pull request Jan 25, 2026
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
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.

1 participant