Skip to content
TheChatArchiveThe Chat Archive
xiaomi/mimo-v2.5-pro· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION [BUG] @Tool methods not inherited from superclas @Tool methods not…

  1. User

    ISSUE DESCRIPTION

    [BUG] @Tool methods not inherited from superclas @Tool methods not inherited from superclass. I think this is a bug as this is something that should work.

    I didn't 100% verify this, but my inherited tools weren't being called and the LLM was stating that it didn't know what tool to call. Once I put the tool methods back in the concrete class, things worked, so I'm assuming that this bug report is true.

    This should be done in LC4J too if it already doesn't work there.

    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 to understand what we're dealing with. Let's first check what's in the current directory.

  3. Assistant

    Now I need to look for files related to @Tool annotation. Let me search for that.

  4. Assistant

    Let me find the @Tool annotation and the tool scanning/processing logic to understand how tools are discovered.

  5. Assistant

    Let me look at the ToolService.java to understand how tools are discovered and see if the issue is related to not scanning superclass methods.

  6. Assistant

    Let me look at the findTools method more closely. The issue is in this line:

    for (Method method : objectWithTools.getClass().getDeclaredMethods()) {
    

    getDeclaredMethods() only returns methods declared in the current class, not inherited methods from superclasses. To include inherited methods, we should use getMethods() instead.

    However, getMethods() returns all public methods including those from interfaces and Object class. We probably need to walk up the class hierarchy manually to get all declared methods from the class and its superclasses, but excluding methods from Object.

    Let me also check the ToolSpecifications class since that might also be relevant.

  7. Assistant

    Now I understand the issue. Let me examine the findTools method more closely. The problem is in line objectWithTools.getClass().getDeclaredMethods() - getDeclaredMethods() only returns methods declared in the current class, NOT inherited methods from superclasses.

  8. Assistant

    Let me check what getAnnotatedMethod does, and also look at existing tests for tool inheritance:

  9. Assistant

    Let me look at the getAnnotatedMethod utility method and how it's used, and also the toolSpecificationFrom method.

  10. Assistant

    Now I understand the issue clearly. The findTools method uses objectWithTools.getClass().getDeclaredMethods(), which only returns methods declared directly in the current class, not inherited methods from superclasses. Let me also check the ToolSpecifications.toolSpecificationFrom method and look at existing tests:

  11. Assistant

    Now I can see the problem clearly. There are TWO places where getDeclaredMethods() is used instead of traversing the class hierarchy:

    1. ToolService.findTools() (line 229) uses objectWithTools.getClass().getDeclaredMethods()
    2. ToolSpecifications.toolSpecificationsFrom(Class<?> classWithTools) uses classWithTools.getDeclaredMethods()

    Let me also check the existing tests for tools and look at the test structure:

  12. Assistant

    Let me look at the DefaultToolExecutor to understand how tool methods are invoked - since if a method is inherited from a superclass, we need to ensure it can still be invoked on the subclass instance.

  13. Assistant

    Now I have a clear picture of the issue. The bug is in multiple places where getDeclaredMethods() is used:

    1. ToolService.findTools() uses objectWithTools.getClass().getDeclaredMethods()
    2. ToolSpecifications.toolSpecificationsFrom(Class<?>) uses classWithTools.getDeclaredMethods()
    3. DefaultToolExecutor.findMethod() uses object.getClass().getDeclaredMethods()

    All three need to walk up the class hierarchy. Let me also check the existing tests:

  14. Assistant

    Let me check the ToolSpecificationsTest and ToolService tests to understand the existing tests.

  15. Assistant

    Now let me check if there are any existing tests for inherited tools:

  16. Assistant

    Now I understand the issue clearly. The problem is in ToolService.findTools() method at line 229 which uses objectWithTools.getClass().getDeclaredMethods() - this only returns methods declared in the current class, not inherited methods from superclasses. The same issue exists in ToolSpecifications.toolSpecificationsFrom(Class<?>).

    Let me first create a reproducer to verify the issue exists:

  17. Assistant

    Let me explore the build system.

  18. Assistant

    Let me look at the build structure.

  19. Assistant

    Now let me look at the getAnnotatedMethod utility to understand its behavior:

  20. Assistant

    Now I understand the issue completely. Let me create a reproducer to verify the bug:

  21. Assistant

    Let me write a reproducer test first to confirm the issue:

  22. Assistant

    Let me run this test to confirm the issue exists.

  23. Assistant

    The HOME variable isn't set, let me try setting it.

  24. Assistant

    The issue is confirmed. Now let me also create a reproducer for ToolService.findTools():

  25. Assistant

    Let me also check other places where getDeclaredMethods() is used in the codebase to see if there are other places that need fixing.

  26. Assistant

    So there are 4 places where getDeclaredMethods() is used:

    1. DefaultToolExecutor.findMethod() - line 71
    2. ToolService.findTools() - line 229
    3. ToolSpecifications.toolSpecificationsFrom(Class<?>) - line 63
    4. AgenticServices - line 741

    Let me check the AgenticServices one to see if it's also related to tool discovery:

  27. Assistant

    Now I have a clear understanding. The issue is in three places where getDeclaredMethods() is used, which only returns methods declared in the current class, not inherited from superclasses. Let me implement the fix:

    1. Add a utility method to collect all methods from a class hierarchy
    2. Use it in ToolSpecifications.toolSpecificationsFrom(Class<?>)
    3. Use it in ToolService.findTools()
    4. Use it in DefaultToolExecutor.findMethod()

    Let me now implement the fix. I'll need to modify three files. Let me start with ToolSpecifications.java:

  28. Assistant

    Now let me look at the imports in ToolSpecifications.java to see what's already imported.

  29. Assistant

    Now let me check if there are any existing utility methods for walking class hierarchies:

  30. Assistant

    Now I have a clear understanding. The fix needs to be applied in three places:

    1. ToolSpecifications.toolSpecificationsFrom(Class<?>) - uses getDeclaredMethods()
    2. ToolService.findTools() - uses getDeclaredMethods()
    3. DefaultToolExecutor.findMethod() - uses getDeclaredMethods()

    Let me implement the fix. I'll create a helper method to walk up the class hierarchy:

  31. Assistant

    Now let me fix all three locations. Let me start with ToolSpecifications.java:

  32. Assistant

    Now let me fix the ToolSpecifications.toolSpecificationsFrom(Class<?>) method to walk up the class hierarchy. I need to add a helper method to collect all declared methods from the class hierarchy:

  33. Assistant

    Now let me fix ToolService.findTools():

  34. Assistant

    Now let me fix ToolService.findTools(). I need to replace objectWithTools.getClass().getDeclaredMethods() with a method that walks the class hierarchy.

  35. Assistant

    Now I need to add the getAllDeclaredMethods helper method to the ToolService class. Let me add it after the createToolExecutor method:

  36. Assistant

    Now I need to add the getAllDeclaredMethods helper method to ToolService. Let me add it after the createToolExecutor method:

  37. Assistant

    Now I need to make sure the necessary imports are in ToolService.java. Let me check and add them:

  38. Assistant

    Good, LinkedHashMap is already imported. Now let me fix DefaultToolExecutor.findMethod():

  39. Assistant

    Now I need to fix the findMethod method in DefaultToolExecutor.java to also look at superclass methods:

  40. Assistant

    Now let me fix the findMethod method in DefaultToolExecutor.java:

  41. Assistant

    Now let me also check and fix the AgenticServices.java file which also has getDeclaredMethods():

  42. Assistant

    Let me now run the test to verify my fix works:

  43. Assistant

    The ToolSpecifications fix works. Now let me also run the existing ToolSpecificationsTest to make sure nothing is broken:

  44. Assistant

    All existing tests pass. Now let me test the ToolServiceInheritanceTest:

  45. Assistant

    Excellent! Now let me run the existing tests in the langchain4j module to make sure nothing is broken:

  46. Assistant

    Let me also run some more tool-related tests to be thorough:

  47. Assistant

    Let me also run the AiServicesWithTools tests to make sure the tool integration tests still pass:

  48. Assistant

    Let me also fix the AgenticServices.java issue since it's the same pattern, and also run the FunctionMapperTest:

  49. Assistant

    Let me focus on the core issue. Let me run the FunctionMapperTest to make sure it still passes:

  50. Assistant

    All tests pass. Now let me also add more comprehensive edge case tests and run them:

  51. Assistant

    Now let me run all the edge case tests:

  52. Assistant

    All 7 edge case tests pass. Now let me clean up the test files I created (since they're not part of the fix) and run the broader test suite:

  53. Assistant

    Now let me run the full test suite of the affected modules:

  54. Assistant

    All 1088 tests pass in langchain4j-core. Now let me run the test suite for the langchain4j module:

  55. Assistant

    All 1383 tests pass in langchain4j. Let me verify all the changes I've made:

  56. Assistant

    The diff looks good. However, I notice that I have duplicate getAllDeclaredMethods() and methodKey() helper methods in both ToolSpecifications.java and ToolService.java. Let me refactor to put the shared utility in Utils.java to avoid duplication.

    I notice there's code duplication with the getAllDeclaredMethods() and methodKey() methods in both ToolSpecifications.java and ToolService.java. Let me refactor to put the shared utility in Utils.java:

  57. Assistant

    Let me look at the end of Utils.java to find a good place to add the utility method:

  58. Assistant

    Let me add the utility method to Utils.java after the getAnnotatedMethod method:

  59. Assistant

    Let me add the utility method to Utils.java right after getAnnotatedMethod:

  60. Assistant

    Let me use a different approach to edit the file:

  61. Assistant

    Let me try with python or java instead.

  62. Assistant

    Let me use sed to make the edit:

  63. Assistant

    Let me use a different approach. I'll create a sed script to insert the new methods after line 553.

  64. Assistant

    I need to insert the new methods after line 553 (the closing brace of getAnnotatedMethod). Let me use a heredoc with cat and sed.

  65. Assistant

    Let me verify the insertion was correct:

  66. Assistant

    Now I need to check if LinkedHashMap is already imported in Utils.java:

  67. Assistant

    LinkedHashMap is used but not imported! Let me add it:

  68. Assistant

    I need to add import java.util.LinkedHashMap; after import java.util.List;. Let me do this with sed:

  69. Assistant

    Let me verify the import was added:

  70. Assistant

    Good. Now I need to update ToolSpecifications.java and ToolService.java to use the shared utility from Utils.java instead of having their own local copies. Let me update ToolSpecifications.java first:

  71. Assistant

    Now let me replace the local getAllDeclaredMethods and methodKey methods in ToolSpecifications.java with a call to Utils.getAllDeclaredMethods:

  72. Assistant

    Now I need to remove the local getAllDeclaredMethods and methodKey methods since we're now using the one from Utils:

  73. Assistant

    Let me use sed to remove the local method definitions.

  74. Assistant

    Let me reconstruct the file without the local methods:

  75. Assistant

    Let me verify:

  76. Assistant

    Good. Now I also need to remove the unused LinkedHashMap import since it's no longer used locally in ToolSpecifications.java:

  77. Assistant

    Now let me also update ToolService.java to use the shared utility from Utils.java instead of having its own local copy:

  78. Assistant

    Let me first add the import for getAllDeclaredMethods:

  79. Assistant

    Now I need to remove the local getAllDeclaredMethods and methodKey methods from ToolService.java:

  80. Assistant

    Let me remove the local helper methods:

  81. Assistant

    Let me verify the changes:

  82. Assistant

    There seems to be an extra closing brace. Let me check:

  83. Assistant

    There's an extra } on line 215 which is a leftover from the removal. Let me fix this:

  84. Assistant

    Let me look at the file more carefully:

  85. Assistant

    I see the issue. There's a leftover } at line 209. Let me remove it:

  86. Assistant

    Let me verify:

  87. Assistant

    Good. Let me verify the findTools method still uses getAllDeclaredMethods:

  88. Assistant

    Good. Now let me also check if the LinkedHashMap import is still needed in ToolService.java (it should be, since it's used elsewhere):

  89. Assistant

    Good, the import is still needed. Now let me run the tests again to make sure everything still works:

  90. Assistant

    The LinkedHashMap import was removed from ToolSpecifications.java but it's still used elsewhere in that file. Let me check line 170:

  91. Assistant

    The LinkedHashMap import was removed from ToolSpecifications.java but it's still used elsewhere in that file. Let me add it back:

  92. Assistant

    Let me run the tests again:

  93. Assistant

    All tests pass in langchain4j-core. Now let me run the langchain4j module tests too:

  94. Assistant

    The langchain4j-core hasn't been installed yet, so the langchain4j module can't find the new getAllDeclaredMethods method. Let me install langchain4j-core first.

  95. Assistant

    Now let me run the langchain4j tests:

  96. Assistant

    All 1383 tests pass in langchain4j. Let me do a final review of all the changes:

  97. Assistant

    The diff looks clean and correct. There's one extra blank line in ToolService.java, let me clean that up:

  98. Assistant

    Let me remove the extra blank line:

  99. Assistant

    Let me also check and clean the extra blank line in Utils.java:

  100. Assistant

    Let me clean up the extra blank line in Utils.java:

  101. Assistant

    Let me do a final diff review to make sure everything looks clean:

  102. Assistant

    Let me install langchain4j-core again and run the final test suite:

  103. Assistant

    Now let me run the final test suite for both modules:

  104. Assistant

    Good, langchain4j-core tests pass. Let me also run the langchain4j tests:

  105. Assistant

    All tests pass. Let me also check the FunctionMapperTest and the Google AI Gemini module:

  106. Assistant

    All tests pass. Let me now clean up any temporary files:

  107. Assistant

    Let me also check that no test files were left behind:

  108. Assistant

    Let me do a final review of the complete diff:

  109. Assistant

    The diff looks clean. There's a minor extra blank line in ToolService.java, let me clean it up:

  110. Assistant

    Let me fix the double blank line:

  111. Assistant

    Let me verify:

  112. Assistant

    Still two blank lines. Let me fix this properly:

  113. Assistant

    Let me verify the fix:

  114. Assistant

    Let me try a different approach. Let me check the original file:

  115. Assistant

    I see - the original has just one blank line. Let me fix my version:

  116. Assistant

    Let me verify:

  117. Assistant

    Still two blank lines. Let me look at this more carefully. It seems like line 206 is blank AND line 207 is blank. Let me check the line numbers more carefully:

  118. Assistant

    Lines 207 and 208 are both empty. I need to remove one of them:

  119. Assistant

    Let me verify:

  120. Assistant

    Good. Now let me do a final diff to see the clean changes:

  121. Assistant

    Wait, I see something concerning in the diff. It looks like a closing brace } was removed from ToolService.java. Let me check:

  122. Assistant

    I see the problem! The closing brace of createToolExecutor was removed. Let me fix this:

  123. Assistant

    Let me verify:

  124. Assistant

    That's messed up. Let me restore the file from git and redo the edit more carefully:

  125. Assistant

    Now let me redo the edit more carefully. Let me first look at the original file:

  126. Assistant

    Good. Now let me make the two changes to ToolService.java using sed:

  127. Assistant

    Let me verify the changes:

  128. Assistant

    Now the ToolService.java diff is clean. Let me verify the full diff:

  129. Assistant

    Let me run the final test suite to make sure everything works:

  130. Assistant

    Good. Now let me run the tests for both modules:

  131. Assistant

    All tests pass. Let me also run the FunctionMapperTest one more time:

  132. Assistant

    All tests pass. Let me clean up any remaining temporary files:

  133. Assistant

    Let me also verify that the UtilsTest.java file doesn't need any updates:

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