Skip to content

Commit 88a8b19

Browse files
Mateusz Krawieccopybara-github
authored andcommitted
fix: non-map value returned by a Function Tool should be automatically wrapped into a Map as per https://google.github.io/adk-docs/tools-custom/function-tools/#return-type
PiperOrigin-RevId: 838719814
1 parent e6755a2 commit 88a8b19

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

core/src/main/java/com/google/adk/tools/FunctionTool.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,12 @@ private Maybe<Map<String, Object>> call(Map<String, Object> args, ToolContext to
237237
.map(
238238
data -> OBJECT_MAPPER.convertValue(data, new TypeReference<Map<String, Object>>() {}))
239239
.toMaybe();
240-
} else {
240+
} else if (result instanceof Map) {
241241
return Maybe.just(
242242
OBJECT_MAPPER.convertValue(result, new TypeReference<Map<String, Object>>() {}));
243+
} else {
244+
// See https://google.github.io/adk-docs/tools-custom/function-tools/#return-type
245+
return Maybe.just(ImmutableMap.of("result", result));
243246
}
244247
}
245248

0 commit comments

Comments
 (0)