ISSUE DESCRIPTION [FEATURE] support non Result return types for AiService when tool…
- User
ISSUE DESCRIPTION
[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
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- Assistant
I’ll trace the immediate tool-execution path and its return-type handling, inspect related tests, then implement the smallest general change and run the affected test suite. I’ll also verify behavior for void, nullable null, incompatible/multiple results, and TO_LLM cases before submitting.
- Assistant
The immediate path currently rejects every non-
Resultmethod insideToolService, before the caller can inspect actual tool values. I’ll move the policy toDefaultAiServices: retain the existingResultwrapper behavior, while direct returns use the tool execution objects, enforce the TO_LLM restriction, and validate nullability/type compatibility. - Assistant
The implementation now compiles, and the focused immediate-return test invocation passes. The change preserves
Resultbehavior, allows direct values for reference and primitive-wrapper-compatible returns, returns null for void/all-null nullable cases, and rejects TO_LLM, primitive-null, multiple non-null, or incompatible results. The repository’s Spotless check could not run because this checkout lacksorigin/main; compilation and targeted tests did run successfully.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.