Untitled conversation
- User
[FEATURE] support non Result return types for AiService when tool execution is IMMEDIATE Is your feature request related to a problem? Please describe. If using ReturnBehavior.IMMEDIATE, your AiService method has to return Result even if all tools called return
voidor all returnnullor there's one tool method that returns same type as AiService return type.Describe the solution you'd like I'd like to support non-Result return types for AiService methods when tool execution has IMMEDIATE results based on these rules:
- If ai service method return type is void, just return null
- If any tool executions are TO_LLM throw exception (IMMEDIATE_IF_LAST case)
- If all tool executions have a null result and return type is nullable (not a primitive), then return null
- If there is one non-null tool execution result, and the result can be resolved to the return type, then return that object
I have a PR for this open in Quarkus too:
https://github.com/quarkiverse/quarkus-langchain4j/pull/2529
Interface
No new interfaces are introduced.
- Assistant
Exploring the codebase to see how AiService handles IMMEDIATE tool execution and return types.
- Assistant
Implementing the merged PR changes in production files.
- Assistant
Implemented support for non-
ResultAI Service return types when immediate tool return applies.Changes
-
ToolService.java
Removed the guard that threwIllegalConfigurationExceptionwhen immediate return happened on a non-Resultmethod. The loop can short-circuit for any return type; resolution happens inDefaultAiServices. -
DefaultAiServices.java
WhenimmediateToolReturn()is true:Result: unchanged — buildResultwithcontent(null)and tool execution metadata.void: returnnull.- Other types (only if every tool is
IMMEDIATEorIMMEDIATE_IF_LAST):- All
resultObject()values null → returnnull - Exactly one non-null value assignable to the return type → return that object
- Otherwise →
IllegalConfigurationExceptionwith guidance to useResult
- All
- Mixed with
TO_LLMon an immediate-return batch →IllegalConfigurationException(non-immediate tools with non-Resultreturn types)
Added
resolvesToType()for assignability checks. -
DefaultToolExecutor.javatoContents(null)returnsnullso void/null tool results keepresultObject()null for immediate return logic.toTexthandlesnullStringtool results safely.
Verification
ReturnBehaviorCombinationsTest,ProgrammaticCreatedImmediateReturnToolTest,DefaultToolExecutorTest,ToolServiceTest, and broader*Tool*Test— all passedgit diff --check— clean- Production diff: 3 files, +62 / −17 lines
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →
- fable-5Compare side by side →