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
Exploring the codebase to locate AiService IMMEDIATE return-type handling and implement the feature.
- Assistant
Implementing the resolver and wiring it into
ToolServiceandDefaultAiServices. - Assistant
Implemented support for non-
ResultAI service return types when immediate tool return applies.Changes
-
ImmediateToolReturnValueResolver– Resolves the method return value from immediate tool executions:void→null- Any executed tool with
ReturnBehavior.TO_LLM→IllegalConfigurationException(e.g.[TO_LLM, IMMEDIATE_IF_LAST]) - All tool
resultObject()valuesnulland nullable return type →null - Primitive return type with all-null tool results →
IllegalConfigurationException - Exactly one non-null tool result → convert via assignability or
ServiceOutputParser - Multiple non-null results →
IllegalConfigurationException
-
ToolService– Removed the requirement that the method returnResultwhen short-circuiting; the loop still setsimmediateToolReturn(true)as before.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.