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
Interface
No new interfaces are introduced.
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.
- Assistant
I'll start by exploring the repository structure and locating the AiService / tool execution code related to IMMEDIATE return behavior.
- Assistant
Next I'll inspect the ReturnBehavior types and how AiService currently handles IMMEDIATE tool results.
- Assistant
I'll read the immediate-return path in ToolService and how DefaultAiServices maps results to the method return type.
- Assistant
I'll examine the existing immediate-return tests and the DefaultAiServices handling around line 349.
- Assistant
I'll look up the Quarkus PR changes and review ToolExecution / ToolServiceResult next.
- Assistant
Fetching the rest of the Quarkus PR diff to mirror its logic.
- Assistant
Empty? Let me try again differently.
- Assistant
Strange, maybe sed failed. Let me try cat.
- Assistant
I'll search for related PRs or TODOs and inspect the streaming handler next.
- Assistant
Checking TypeUtils and how return behaviors are exposed from tool executions for resolution.
- Assistant
Inspecting the streaming immediate-return path and related tests.
- Assistant
Looking for validation of Result return type and IMMEDIATE tool tests in the shared IT suite.
- Assistant
Reading the IllegalConfigurationException test and surrounding IMMEDIATE tool cases.
- Assistant
Finding all callers of
executeInferenceAndToolsLoopand inspecting ToolServiceTest. - Assistant
I'll implement the resolution logic: update ToolService, ToolServiceResult, DefaultAiServices, and ReturnBehavior docs.
- Assistant
Implementing ToolServiceResult changes first, then ToolService and DefaultAiServices.
- Assistant
Fixing the deprecated constructor and adding the getter plus builder support.
- Assistant
Continue editing getter, equals, hashCode, toString, Builder
- Assistant
Updating ToolService to resolve non-Result return types on immediate tool return.
- Assistant
I'll update imports and the executeInferenceAndToolsLoop method.
- Assistant
Restoring the dropped LocalDateTime import.
- Assistant
I also see ArrayList missing from the imports — restoring it.
- Assistant
Still missing the Collection import — fixing the full import block.
- Assistant
Updating executeInferenceAndToolsLoop and adding the resolve helper.
- Assistant
I also need static import for typeHasRawClass
- Assistant
Cleaning up Result detection and adding the resolve method properly.
- Assistant
Now simplify the isReturnTypeResult detection.
- Assistant
Removing the duplicated declarations.
- Assistant
Adding
resolveImmediateReturnValueaftershouldReturnImmediately. - Assistant
sed syntax wrong with colon
- Assistant
I'll insert the resolve methods after shouldReturnImmediately.
- Assistant
Checking for a duplicated javadoc after the inserted methods.
- Assistant
Removing the duplicate javadoc.
- Assistant
Cleaning up the leftover duplicate signature.
- Assistant
Updating DefaultAiServices to pass the return type and handle non-Result immediate returns.
- Assistant
Updating ReturnBehavior documentation and fixing formatting.
- Assistant
Fixing the class javadoc closing and enum constant docs.
- Assistant
Removing the duplicate enum declaration.
- Assistant
Updating constant-level javadocs for IMMEDIATE and IMMEDIATE_IF_LAST.
- Assistant
Update IMMEDIATE_IF_LAST javadoc similarly.
- Assistant
Writing a temporary verification test and compiling the module.
- Assistant
Setting HOME and re-running the build.
- Assistant
Need different flags
- Assistant
Checking the end of ToolServiceResult for the syntax error.
- Assistant
Removing leftover junk after the closing brace.
- Assistant
Re-running the compilation and tests.
- Assistant
Writing a temporary script to verify the new non-Result immediate-return behaviors.
- Assistant
All new-behavior checks passed. Removing the temporary test file.
- Assistant
Doing a final review of the key changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.