Skip to content

Ensure all property types are translated when converting function calls to a2a#657

Closed
zbirkenbuel wants to merge 3 commits into
google:mainfrom
zbirkenbuel:function_ids
Closed

Ensure all property types are translated when converting function calls to a2a#657
zbirkenbuel wants to merge 3 commits into
google:mainfrom
zbirkenbuel:function_ids

Conversation

@zbirkenbuel

Copy link
Copy Markdown

Python and Go implementations of ADK both copy function call and response properties by copying the entire struct automatically. Java does this a property at a time and so was missing the "id" property of the ADK event. Providing these allows downstream agents to properly associate multiple tool calls and responses to the same tool name.

…ls to a2a

Python and Go implementations of ADK both copy function call and response
properties by copying the entire struct automatically. Java does this a property
at a time and so was missing the "id" property of the ADK event.  Providing these
allows downstream agents to properly associate multiple tool calls and responses
to the same tool name.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @zbirkenbuel, 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 critical inconsistency in the Java ADK's handling of function call and response properties. Previously, the 'id' property, essential for correlating tool calls and responses, was not being properly translated, unlike its Python and Go counterparts. The changes ensure that this 'id' property is now correctly processed, leading to more robust and reliable communication between agents and tools within Java applications.

Highlights

  • Java ADK Function Call/Response Translation: The Java ADK now correctly translates the 'id' property for both function calls and function responses, aligning its behavior with the Python and Go implementations.
  • Improved Tool Association: This change ensures that downstream agents can properly associate multiple tool calls and responses to the same tool name, enhancing the reliability of tool interactions.
  • PartConverter Updates: The PartConverter class has been updated to extract and include the 'id' property during the conversion of DataPart to GenAiPart and vice-versa for function calls and responses.
  • Enhanced Test Coverage: New test cases have been added to EventConverterTest to validate that the 'id' property is correctly preserved and translated during the conversion process.
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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 correctly adds the id property to FunctionCall and FunctionResponse during A2A conversions, which aligns the Java implementation with others and enables better tool call tracking. The changes are well-implemented and include corresponding test updates to ensure correctness. I've added one suggestion to refactor a small piece of duplicated code for improved maintainability.

Comment on lines 132 to 153
if (data.containsKey("name") && data.containsKey("args")
|| A2A_DATA_PART_METADATA_TYPE_FUNCTION_CALL.equals(metadataType)) {
String functionName = String.valueOf(data.getOrDefault("name", ""));
String functionId = String.valueOf(data.getOrDefault("id", ""));
Map<String, Object> args = coerceToMap(data.get("args"));
return Optional.of(
com.google.genai.types.Part.builder()
.functionCall(FunctionCall.builder().name(functionName).args(args).build())
.functionCall(FunctionCall.builder().name(functionName).id(functionId).args(args).build())
.build());
}

if (data.containsKey("name") && data.containsKey("response")
|| A2A_DATA_PART_METADATA_TYPE_FUNCTION_RESPONSE.equals(metadataType)) {
String functionName = String.valueOf(data.getOrDefault("name", ""));
String functionId = String.valueOf(data.getOrDefault("id", ""));
Map<String, Object> response = coerceToMap(data.get("response"));
return Optional.of(
com.google.genai.types.Part.builder()
.functionResponse(
FunctionResponse.builder().name(functionName).response(response).build())
FunctionResponse.builder().name(functionName).id(functionId).response(response).build())
.build());
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

These two if blocks for handling function calls and function responses contain duplicated logic for extracting functionName and functionId. To improve code clarity and reduce redundancy, you could extract these variable assignments before the conditional checks.

    String functionName = String.valueOf(data.getOrDefault("name", ""));
    String functionId = String.valueOf(data.getOrDefault("id", ""));

    if (data.containsKey("name") && data.containsKey("args")
        || A2A_DATA_PART_METADATA_TYPE_FUNCTION_CALL.equals(metadataType)) {
      Map<String, Object> args = coerceToMap(data.get("args"));
      return Optional.of(
          com.google.genai.types.Part.builder()
              .functionCall(FunctionCall.builder().name(functionName).id(functionId).args(args).build())
              .build());
    }

    if (data.containsKey("name") && data.containsKey("response")
        || A2A_DATA_PART_METADATA_TYPE_FUNCTION_RESPONSE.equals(metadataType)) {
      Map<String, Object> response = coerceToMap(data.get("response"));
      return Optional.of(
          com.google.genai.types.Part.builder()
              .functionResponse(
                  FunctionResponse.builder().name(functionName).id(functionId).response(response).build())
              .build());
    }

…ls to a2a

Python and Go implementations of ADK both copy function call and response
properties by copying the entire struct automatically. Java does this a property
at a time and so was missing the "id" property of the ADK event.  Providing these
allows downstream agents to properly associate multiple tool calls and responses
to the same tool name.
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