adk-java icon indicating copy to clipboard operation
adk-java copied to clipboard

Base tool Interface doesn't properly allow returning empty

Open Poggecci opened this issue 1 year ago • 1 comments

Describe the bug

In Python, long-running tools can return None, which means their response is not recorded into an Event (and therefore not fed into the model). This is implemented here.

In Java, BaseTool::runAsync returns Single<...>, which means they must provide a return value, even if they're long-running. This causes the invocation to continue calling the LLM instead of ending. Ideally, BaseTool::runAsync should be returning Maybe<...> instead. There is some code to handle a null response here akin to the python one , but the BaseTool API simply doesn't allow returning null.

A (hacky) workaround is to call toolContext.actions().setEndInvocation(true) and then delete or filter out the initial response event before the next invocation with the real tool response.

To Reproduce

Self evident, just try creating a tool with a return type like Maybe https://github.com/google/adk-java/blob/417a8bcf12bb2c21cf869554335f9649f9ff7a56/core/src/main/java/com/google/adk/tools/BaseTool.java#L74

Expected behavior

Long running tools should be allowed to return empty function responses

Desktop (please complete the following information):

  • ADK version: latest

Poggecci avatar Aug 13 '25 06:08 Poggecci

This issue has been addressed by #1324, so I am closing it.

hemasekhar-p avatar Jul 20 '26 14:07 hemasekhar-p