Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/src/main/java/com/google/adk/tools/FunctionTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ public Single<Map<String, Object>> runAsync(Map<String, Object> args, ToolContex
return this.call(args, toolContext).defaultIfEmpty(ImmutableMap.of());
} catch (Exception e) {
e.printStackTrace();
return Single.just(ImmutableMap.of());
return Single.just(
ImmutableMap.of("status", "error", "message", "An internal error occurred."));
}
}

Expand Down
13 changes: 13 additions & 0 deletions core/src/test/java/com/google/adk/tools/FunctionToolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,15 @@ public void call_withParameterizedListParam() throws Exception {
assertThat(result).containsExactly("listParam", listParam);
}

@Test
public void call_throwsException_returnsInternalError() {
FunctionTool tool = FunctionTool.create(Functions.class, "throwException");

Map<String, Object> result = tool.runAsync(ImmutableMap.of(), null).blockingGet();

assertThat(result).containsExactly("status", "error", "message", "An internal error occurred.");
}

@Test
public void create_withPojoParamWithGettersAndSetters() {
FunctionTool tool = FunctionTool.create(Functions.class, "pojoParamWithGettersAndSetters");
Expand Down Expand Up @@ -603,6 +612,10 @@ public static void voidReturnWithSchemaAndToolContext(
String param2,
ToolContext toolContext) {}

public static void throwException() {
throw new RuntimeException("test exception");
}

public static void voidReturnWithoutSchema() {}

public static ImmutableMap<String, Object> returnsMap() {
Expand Down