Skip to content
TheChatArchiveThe Chat Archive
x-ai/grok-4.5· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION [FEATURE] support non Result return types for AiService when tool…

  1. 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 void or all return null or 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 using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to 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.
    • I have thought about edge cases and made sure my fix handles them as well.
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.

    Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!

    (Current directory: /langchain4j, current file: none) bash-$

  2. Assistant

    I'll start by exploring the repository structure and locating the AiService / ReturnBehavior.IMMEDIATE related code so I can implement non-Result return types.

  3. Assistant

    Next I'll inspect ReturnBehavior, ToolService, and related tests to see how IMMEDIATE is handled today.

  4. Assistant

    Let me look at the ToolService executeInferenceAndToolsLoop method more carefully, and DefaultAiServices to understand the return type handling.

  5. Assistant

    Let me look at DefaultAiServices to see how the result is processed and what's currently done with return types.

  6. Assistant

    Looking at the immediate-return path in DefaultAiServices and the existing IMMEDIATE tests for context.

  7. Assistant

    Checking git history and any stubs or TODOs for this feature.

  8. Assistant

    Inspecting ToolExecution/result types and how streaming handles immediate returns.

  9. Assistant

    Looking for tests that assert non-Result IMMEDIATE failures and reviewing TypeUtils.

  10. Assistant

    Inspecting the non-Result IMMEDIATE failure test and related IMMEDIATE handling logic.

  11. Assistant

    Checking the streaming handler for the immediate-return path and scanning for related helper utilities.

  12. Assistant

    Reading the tools docs around IMMEDIATE return type constraints.

  13. Assistant

    Checking other callers of this API and how TypeUtils handles primitives.

  14. Assistant

    Checking void-tool results and imports used for configuration errors.

  15. Assistant
    // from DefaultToolExecutor around line 150-195
    
  16. Assistant

    Checking how ToolExecutor builds ToolExecutionResult:

  17. Assistant

    Implementing the changes: updating ToolService, ToolServiceResult, DefaultAiServices, docs, and ReturnBehavior.

  18. Assistant

    Updating ToolServiceResult to carry immediate-return tool execution metadata.

  19. Assistant

    Updating ToolService's immediate-return path next.

  20. Assistant

    I need to update the when shouldReturnImmediately block. Also check if Result import is only for the exception message - might still need it for something else.

  21. Assistant

    Updating the immediate-return block in ToolService.

  22. Assistant

    Now replace the immediate return block.

  23. Assistant

    Need to navigate to the line first or use sed.

  24. Assistant

    Now I can replace.

  25. Assistant

    Adding a static method on ToolService to map tool results to the AI Service return type.

  26. Assistant

    Cleaning up FQCNs and adding proper imports.

  27. Assistant

    need to goto first

  28. Assistant

    Let me do the replace now.

  29. Assistant

    Now fix the fully qualified names in resolveImmediateToolReturn.

  30. Assistant

    Let me fix the FQCN usage.

  31. Assistant

    Updating DefaultAiServices to handle non-Result immediate returns.

  32. Assistant

    I need to open DefaultAiServices

  33. Assistant

    Update the immediate return handling block.

  34. Assistant

    Need to add ToolService import to DefaultAiServices.

  35. Assistant

    Add ToolService import.

  36. Assistant

    Add import for ToolService

  37. Assistant

    Updating ReturnBehavior Javadoc and documentation.

  38. Assistant

    I'll update the Javadoc comprehensively.

  39. Assistant

    Updating the tutorials documentation next.

  40. Assistant

    Let me read those sections and update them.

  41. Assistant

    I'll update the docs with the new rules.

  42. Assistant

    I'll replace the note section and the IMMEDIATE_IF_LAST line, and expand the examples.

  43. Assistant

    Update the IMMEDIATE_IF_LAST note.

  44. Assistant

    goto first

  45. Assistant

    Nowreplace

  46. Assistant

    Writing a temporary unit test for the new behavior and compiling the module.

  47. Assistant

    HOME is not set. Let me set it.

  48. Assistant

    Compilation succeeded. Running the temporary test.

  49. Assistant

    One failure is from null String→ToolExecutionResultMessage, not the new mapping. Checking how void vs null String results are encoded:

  50. Assistant

    Adjusting the temp test (null-String→message is pre-existing) and re-running.

  51. Assistant

    Fixing the typo in the temporary test.

  52. Assistant

    Also need to check argument names - DefaultToolExecutor uses method parameter names which might be a,b not arg0,arg1. Looking at how tests usually call:

  53. Assistant

    The output got cut off - let me check Insed test results.

  54. Assistant

    All 9 tests passed. Removing the temporaryもたらtest and running existing related unit tests.

  55. Assistant

    Checking Utils.copy null-safety for a unset field.

  56. Assistant

    Fixing @since tags to match the current version.

  57. Assistant

    Updating @since to 1.16.0 for the new APIs.

  58. Assistant

    Update ToolService resolveImmediateToolReturn @since

  59. Assistant

    Fix @since

  60. Assistant

    Also check @Tool annotation javadoc if it mentions Result requirement.

  61. Assistant

    Doing a final compile to confirm everything builds’ cleanly.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.