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 / IMMEDIATE tool-execution code related to this feature.
- Assistant
Let me look at the DefaultAiServices and ReturnBehavior related code.
- Assistant
I'll inspect ToolService and DefaultAiServices around the IMMEDIATE return handling next.
- Assistant
I'll search for tests and code that already cover ReturnBehavior.IMMEDIATE.
- Assistant
Checking git history and the tests around the Result-only restriction for more context.
- Assistant
Looking at ToolExecution, Result handling, and streaming for similar return path logic.
- Assistant
Let me look at the Quarkus PR code if we can find references, and look at ToolExecution fully. Also check AiServiceStreamingResponseHandler for immediate return.
- Assistant
I'll inspect type utilities and the full DefaultAiServices method-invocation path next.
- Assistant
Checking the docs and looking for ANY existing related draft or util methods.
- Assistant
Checking validation and unit tests for IMMEDIATE restrictions, plus how ToolService uses
isReturnTypeResult. - Assistant
I'll look for type conversion helpers and inspect how tool executors return result objects.
- Assistant
Let me look at the Quarkus approach conceptually. The feature description is quite complete. Let me also check if there's something about boxing primitives when matching return types. I understand the feature request and the rules you've outlined for supporting non-Result return types when using IMMEDIATE behavior. Let me think through how to implement this properly.
First, let me check the current codebase structure to see where these changes need to be made. I'll start by examining the relevant files. Let me use to explore the current state.
Let me look at the ReturnBehavior enum and the AiService interface to understand the current constraints. I'll use to check the current implementation.
Based on the rules you provided, I need to:
- Update the tool execution logic to handle non-Result return types
- Assistant
I'll look at related exceptions and the Double tooling/boxing helpers.
- Assistant
Looking for Utils that has primitive wrapping.
- Assistant
Checking parallel tool execution ordering and other edge cases.
- Assistant
Implementing the changes: updating
ToolServicefirst, thenDefaultAiServices. - Assistant
Let me implement the changes now.
- Assistant
Now update the shouldReturnImmediately block and add the resolve method.
- Assistant
Need to navigate to the line first with goto
- Assistant
Now I can edit.
- Assistant
Adding a method to resolve immediate tool return values after
shouldReturnImmediately. - Assistant
Cleaning up fully-qualified names by adding proper imports.
- Assistant
Need to goto first
- Assistant
Let me edit imports and FQCN.
- Assistant
Now fix the FQCN in the method.
- Assistant
Updating DefaultAiServices to handle non-Result immediate returns.
- Assistant
Need to import ToolService.resolveImmediateToolReturnValue - ToolService is in tool package. DefaultAiServices already imports ToolServiceResult.
- Assistant
Adding the ToolService import.
- Assistant
Need goto first
- Assistant
Checking the current version and updating documentation.
- Assistant
I'll set
@sinceto 1.16.0 and update the ReturnBehavior Javadoc and docs. - Assistant
Let me update ReturnBehavior docs carefully.
- Assistant
Continue updating the rest of ReturnBehavior docs.
- Assistant
Update IMMEDIATE and IMMEDIATE_IF_LAST enum value javadocs.
- Assistant
I'll carefully update that section using the exact text.
- Assistant
Remove the outdated "Only allowed on AI services returning Result" lines.
- Assistant
There may be HTML entities -
>vs->. Let me read the exact content. - Assistant
The arrows use
>HTML entity. Let me use that. - Assistant
The issue is that in the file it's
->but when I type->it may not match. Let me try with the HTML entity. - Assistant
No python3 - try python or perl.
- Assistant
No python. I'll use perl.
- Assistant
First one worked. Second one had a ty po with
\c*. Fix IMMEDIATE_IF_LAST. - Assistant
The
@symbols got stripped by perl — fixing that next. - Assistant
Good. Now update tools.md docs and fix ToolService @since.
- Assistant
The白雪跳 goto failed because wrong file is open. Let me fix ToolService and docs.
- Assistant
There's something weird - the sed output got jumbled. Let me look at ToolService around that method again.
- Assistant
File is fine. Let me update with sed.
- Assistant
Oops — sed changed every
@since 1.13.0in ToolService; checking and restoring legitimate ones. - Assistant
Restoring the original 1.13.0 annotations that weren't mine.
- Assistant
Need tv restore 1.13.0 for findTools and refreshDynamicProviders.
- Assistant
Writing and running a temporary test to verify the feature.
- Assistant
Checking how tool parameter names are resolved so the test mock args match.
- Assistant
HOME isn't set — I'll set it and rerun.
- Assistant
Need to set failIfNoSpecifiedTests or use -Dsurefire.failIfNoSpecifiedTests=false
- Assistant
Five of six tests passed. Updating the null-result test to use a void tool, which correctly yields a null result object.
- Assistant
I'll change the null tool test to use void tool with String assistant.
- Assistant
Removing the unused ImmediateNullTool class and re-running tests.
- Assistant
Typo in search - returnBehavior not returnBehaviors
- Assistant
Re-running the temporary test, then removing cookbook it before submit.
- Assistant
All tests passed. Removing the temporary test file before submit.
- Assistant
Checking whether the docs edit accidentally mangled other parts of tools.md.
- Assistant
The perl edit corrupted em-dashes across tools.md. Restoring the file and applying a surgical edit.
- Assistant
Let me check line numbers again for IMMEDIATE_IF_LAST line.
- Assistant
I'll use a small perl/awk that only replaces those specific short phrases without reading whole file with -0.
- Assistant
Final review of the complete diff, then submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.