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
I’ll trace the AI service immediate-return path and existing tests, then implement these resolution rules and run the focused test suite.
- Assistant
The restriction is split across the tool loop and proxy return parsing. I found that raw tool objects are already preserved, so the fix can return them without serialization; I’m checking type-resolution conventions and event/guardrail behavior before patching.
- Assistant
The implementation now follows the requested priority rules, including primitive boxing and rejection of ambiguous/mixed results. I’ve added end-to-end tests for void, nullable, primitive, compatible, incompatible, multiple-result, and
TO_LLMcases; I’m running the module tests now. - Assistant
Compilation now succeeds for all main and test sources. The test runner itself is unavailable offline in this workspace, so I’m doing the remaining static checks and updating the public enum documentation, which still described the old
Result-only restriction. - Assistant
The focused run exposed one real edge case: an annotated tool returning
nullcurrently produces empty message content before the immediate-return decision, which the message builder rejects. I’m fixing that path so null raw results can reach the new resolver while preserving the existing LLM-facing representation.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.