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 I have the full picture. Let me implement. First,
ToolService: - Assistant
Now add the resolution helper after
shouldReturnImmediately: - Assistant
Now update the imports in ToolService:
- Assistant
Now
ToolServiceResult— add theimmediateReturnValuefield: - Assistant
Now update
DefaultAiServices: - Assistant
Now compile the main module:
- Assistant
Compilation succeeded. Now update the
ReturnBehaviorjavadoc, which documents the old restriction: - Assistant
Now check the docs mention in
docs/docs/tutorials/tools.md: - Assistant
Now let me write tests. First check
AiServiceValidationfor anything about return types: - Assistant
While that runs, let me check the other test files referencing IMMEDIATE for assumptions about the old behavior:
- Assistant
While waiting, let me review the final state of the modified loop in
ToolService: - Assistant
Spotless reformatted the files. Let me re-run the focused tests to confirm everything still passes:
- Assistant
Now reapply the minimal change to the IT:
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.