-
Notifications
You must be signed in to change notification settings - Fork 359
Ensure all property types are translated when converting function calls to a2a #656
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
bed8a4a
Ensure all property types are translated when converting function cal…
zbirkenbuel ddbe414
Ensure all property types are translated when converting function cal…
zbirkenbuel dc0ecca
Ensure all property types are translated when converting function cal…
zbirkenbuel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -132,21 +132,23 @@ private static Optional<com.google.genai.types.Part> convertDataPartToGenAiPart( | |
| 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()); | ||
|
Comment on lines
145
to
152
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the function call, there are two issues to address for the function response conversion:
Here is a suggested improvement for the null handling. Please also address the missing reverse conversion. String functionName = String.valueOf(data.getOrDefault("name", ""));
Object idObj = data.get("id");
String functionId = (idObj == null) ? null : String.valueOf(idObj);
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()); |
||
| } | ||
|
|
||
|
|
@@ -167,6 +169,7 @@ private static Optional<com.google.genai.types.Part> convertDataPartToGenAiPart( | |
| private static Optional<DataPart> createDataPartFromFunctionCall(FunctionCall functionCall) { | ||
| Map<String, Object> data = new HashMap<>(); | ||
| data.put("name", functionCall.name().orElse("")); | ||
| data.put("id", functionCall.id().orElse("")); | ||
| data.put("args", functionCall.args().orElse(Map.of())); | ||
|
|
||
| Map<String, Object> metadata = | ||
|
|
@@ -185,6 +188,7 @@ private static Optional<DataPart> createDataPartFromFunctionResponse( | |
| FunctionResponse functionResponse) { | ||
| Map<String, Object> data = new HashMap<>(); | ||
| data.put("name", functionResponse.name().orElse("")); | ||
| data.put("id", functionResponse.id().orElse("")); | ||
| data.put("response", functionResponse.response().orElse(Map.of())); | ||
|
|
||
| Map<String, Object> metadata = | ||
|
|
||
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
Oops, something went wrong.
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.
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.
This change is a good step, but there are two issues to address for the function call conversion:
FunctionCallto an A2ADataPartis missing. ThecreateDataPartFromFunctionCallmethod should be updated to also handle theidproperty, otherwise it will be lost. This will also cause the new tests to fail.idcan result in bugs. Ifdatacontains("id", null),functionIdwill become the string"null".Here is a suggested improvement for the null handling. Please also address the missing reverse conversion.