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-tool execution path and its existing return conversion/tests, then implement these rules and run the focused module tests.
- Assistant
The current guard rejects every non-
Resultmethod before the raw tool value reaches the proxy. I found the raw Java result is already retained in eachToolExecution, so the fix can preserve existingResultbehavior and resolve immediate results only for non-Resultmethods, while rejecting ambiguous/mixed cases. - Assistant
The implementation and focused coverage are in place. An offline reactor compile reached the prerequisite modules but stopped because this checkout expects locally installed test-classifier JARs; I’m building those prerequisites locally, then I’ll run the new test without network access.
- Assistant
The focused run exposed an adjacent null-handling gap: raw
nullwas retained correctly, but constructing the chat-memory tool-result message rejected an empty content list before immediate-result resolution. I’m representing that internal null result as empty text for the message while keeping the raw valuenull, which lets the requested return rules operate correctly.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.