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
Now let me find where the result of
executeInferenceAndToolsLoopgets converted to the AI service return value: - Assistant
Let me check the referenced Quarkus PR for the exact semantics:
- Assistant
Now let me look at DefaultAiServices imports and the relevant area:
- Assistant
Now I'll implement. First,
ToolServiceResult— add the fields carrying the final round's return behaviors and executions: - Assistant
Now update
ToolService: - Assistant
Now update
DefaultAiServices. First check for an existing primitive-wrapper utility: - Assistant
Now update the immediate-return handling in
DefaultAiServices: - Assistant
Now add the helper methods next to
fireEventAndReturn: - Assistant
Add the needed imports:
- Assistant
Now compile:
- Assistant
Existing tests pass. Let me check how
DefaultToolExecutorhandles null/void tool results before writing tests: - Assistant
voidis supported. Now the new test class: - Assistant
All 12 pass. Now run the broader service test suites for regressions:
- Assistant
Now update the tools tutorial docs. Let me read the relevant sections:
- Assistant
Check remaining doc references to the old restriction:
- Assistant
All pass. Check formatting compliance:
- Assistant
Let me review the final diff:
- Assistant
The diff looks right. Run the full module test suite once more to be safe after formatting:
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.