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

ISSUE DESCRIPTION Subagent toolcalls not handled when using LiteLLM proxy Summary When…

  1. User

    ISSUE DESCRIPTION

    Subagent tool_calls not handled when using LiteLLM proxy

    Summary

    When using cagent with a LiteLLM proxy (OpenAI-compatible API), a subagent can return a valid tool_calls response, but the host agent reports “no response from subagent” and does not execute the tool call.

    Environment

    • cagent: v1.19.7
    • OS: Linux (WSL2) x86_64
    • LLM: gemini-pro via LiteLLM proxy (OpenAI-compatible)

    Expected

    Host agent receives the subagent response and executes the tool call(s), then continues the conversation with the tool result.

    Actual

    Host agent reports there is “no response from subagent” even though the subagent response contains a valid tool_calls entry. The requested tool call is not executed.

    Minimal reproduction

    1. Configure cagent to use LiteLLM as the model provider (OpenAI-compatible API).
    2. Run a workflow where the subagent is asked to use tools.
    3. The subagent returns a tool call (e.g., company_search with JSON arguments) and finishes with finish_reason: "stop".
    4. The host agent logs “no response from subagent” and does not invoke the tool.

    Notes

    • The subagent response includes a valid tool call object (type: function, name: company_search, arguments: {"datasources": ["confluence", "github", "gdrive"], "query": "LiteLLM usage teams integrations standards"}).
    • I can reproduce consistently with LiteLLM as the proxy in front of an OpenAI-compatible endpoint.

    Please let me know if you want a sanitized example payload or a minimal agent config.

    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: /docker-agent, current file: none) bash-$

  2. Assistant

    I'll start by exploring the repository to understand the codebase structure and locate relevant files related to subagent tool_calls handling. Let's first get a high-level view.

  3. Assistant

    Let me explore the repository more broadly to understand its structure.

  4. Assistant

    This is a Go repository. Let me explore the pkg directory to understand the structure better.

  5. Assistant

    This is a Go repository. Let me understand the structure better and find where subagent tool_calls are handled.

  6. Assistant

    Let me search for "no response from subagent" to understand where this error is reported.

  7. Assistant

    Let me search more broadly for "subagent" related terms.

  8. Assistant

    The issue mentions "no response from subagent" - let me search for "No response from agent" since that's what appears in the code.

  9. Assistant

    Let me examine the relevant files to understand the subagent handling:

  10. Assistant

    Let me search for the "No response from agent" message more carefully.

  11. Assistant

    Let me search for how the runtime processes LLM responses and handles tool_calls:

  12. Assistant

    Let me look at the runtime loop to understand how tool calls are processed:

  13. Assistant

    Let me look at the streaming code to understand how tool calls are extracted from LLM responses:

  14. Assistant

    Let me look at the rest of the loop code to understand how tool calls are processed:

  15. Assistant

    Let me examine the rest of the runStreamLoop function.

  16. Assistant

    Let me look at how the subagent response is processed in runForwarding:

  17. Assistant

    Let me examine GetLastAssistantMessageContent in the session package:

  18. Assistant

    Let me search more carefully for the "no response" message. It might be in a different form:

  19. Assistant

    Let me understand the flow better. The issue is about subagent tool calls not being handled. Let me look at the streaming code for how tool_calls with finish_reason "stop" are handled:

  20. Assistant

    Let me look at GetLastAssistantMessageContent more carefully:

  21. Assistant

    Let me look at the main loop's handling of tool calls and the processToolCalls function:

  22. Assistant

    Let me find and examine the processToolCalls function:

  23. Assistant

    Let me examine the tool_dispatch.go file:

  24. Assistant

    Now let me look at how the Stopped field is used in the main loop:

  25. Assistant

    Let me see the full context around the Stopped handling:

  26. Assistant

    Let me search for the exact error message "no response from subagent":

  27. Assistant

    The exact message "no response from subagent" doesn't appear in the code. Let me look at the transfer_task tool implementation:

  28. Assistant

    Let me look at the model providers, especially how they handle streaming and tool_calls:

  29. Assistant

    Let me look at the model provider directory.

  30. Assistant

    Let me focus on the core issue. Let me look at the OpenAI streaming provider and how it handles tool_calls:

  31. Assistant

    Let me examine the response_stream.go to see how tool calls are parsed from streaming:

  32. Assistant

    Now let me look at the chat completions streaming adapter:

  33. Assistant

    Let me look at the oaistream package which handles the chat completions streaming:

  34. Assistant

    Let me look at the messages.go file in oaistream which handles the chat completions API:

  35. Assistant

    Let me look at the adapter.go to understand how streaming works:

  36. Assistant

    Let me understand the flow better. Let me look at how the StreamAdapter is used and how trackUsage is set:

  37. Assistant

    Let me look at how the OpenAI client decides which stream format to use (chat completions vs responses API):

  38. Assistant

    Let me look at the full stream creation logic:

  39. Assistant

    Let me understand the full flow better. Let me look at how GetLastAssistantMessageContent works and trace the delegation path:

  40. Assistant

    Let me look at the chat types to understand finish reasons:

  41. Assistant

    Let me look at the complete flow more carefully. Let me trace the exact execution path in handleStream when LiteLLM sends tool_calls with finish_reason "stop". Let me look at how the adapter handles the finish_reason clearing:

  42. Assistant

    Now let me look at how the Stopped flag affects the tool call execution flow. Let me look at the runTurn code after processToolCalls:

  43. Assistant

    Now I have a good understanding of the flow. Let me look at the runForwarding function more closely. The key issue is likely that when a subagent's model returns tool_calls with finish_reason: "stop" (as LiteLLM does), something goes wrong. Let me look at the runForwarding path and the GetLastAssistantMessageContent function:

  44. Assistant

    Let me look at the agent tool implementation for subagents:

  45. Assistant

    Let me read the agent.go file:

  46. Assistant

    Now I understand the issue. Let me trace through the exact flow to identify the root cause. Let me look at the handleStream function more closely, specifically the order of processing:

  47. Assistant

    Now I can see the issue clearly. In the handleStream function, the order of processing is:

    1. Check choice.FinishReason == FinishReasonStop → early return
    2. Handle tool calls

    This means when a response chunk contains BOTH tool calls AND finish_reason: "stop", the finish reason check happens FIRST and the tool calls from that chunk are NEVER accumulated. The function returns early with an empty or incomplete toolCalls slice.

    With LiteLLM proxy and trackUsage enabled (the default), the adapter:

    1. Clears finish_reason: "stop" from the choice to empty
    2. Processes tool call deltas normally
    3. When usage is present (same chunk), re-injects FinishReasonStop into Choices[0].FinishReason

    So the response from the adapter has BOTH Choices[0].Delta.ToolCalls AND Choices[0].FinishReason = "stop". Then handleStream sees the "stop" finish reason first and returns early, losing the tool calls from that chunk.

    Let me verify this theory by looking at the tests:

  48. Assistant

    Let me look at the existing tests for the streaming code:

  49. Assistant

    Let me look at the existing tests for the handleStream function:

  50. Assistant

    Let me look at the test files to understand how handleStream is tested:

  51. Assistant

    Let me look at the adapter tests for the oaistream package:

  52. Assistant

    Let me look at turn_end_test.go:

  53. Assistant

    Now I can see the bug clearly! In handleStream (streaming.go), the order of processing is:

    1. Check FinishReasonStop or FinishReasonLength → early return
    2. Process tool calls from choice.Delta.ToolCalls

    This means if a chunk has both tool calls AND finish_reason: "stop" (which happens when LiteLLM proxy sends the final chunk with usage data and trackUsage is enabled), the tool calls from that chunk are never accumulated. The function returns early with an empty or incomplete toolCalls slice.

    The fix is to move the tool call processing before the early return on FinishReasonStop, so that tool calls from the same chunk are accumulated before checking the finish reason.

  54. Assistant

    Now I understand the root cause. Let me look at the full order of processing in handleStream more carefully:

  55. Assistant

    Now I have a clear understanding of the issue. Let me create a reproduction script first to confirm the problem:

  56. Assistant

    Let me look at the streamBuilder more to understand the test patterns:

  57. Assistant

    Now I understand the issue. Let me look at the exact sequence of events with the streamBuilder to understand how tests construct tool calls with stop:

  58. Assistant

    Now I have a clear picture. Let me now understand the exact bug:

    In handleStream (streaming.go), the processing order is:

    1. Check FinishReasonStop/FinishReasonLength → early return (line 132-149)
    2. Process choice.Delta.ToolCalls (line 160+)

    When LiteLLM proxy sends tool_calls AND finish_reason: "stop" in the same chunk (which happens because the oaistream.StreamAdapter re-injects "stop" when usage data is present alongside choices), the early return at step 1 happens before the tool calls from that chunk are accumulated. This means toolCalls is empty (or missing the calls from the final chunk), and Stopped is true.

    The fix is to move the tool call delta processing before the finish_reason check.

    Let me now implement the fix:

  59. Assistant

    Now I have a clear picture. Let me implement the fix. The issue is in handleStream - the tool call delta processing must happen before the finish_reason early return. When LiteLLM proxy sends both tool_calls and finish_reason: "stop" in the same chunk (via the adapter's usage re-injection), the current order causes tool calls to be lost.

  60. Assistant

    Now let me implement the fix. The cleanest approach is to move the tool call delta processing before the finish_reason check:

  61. Assistant

    Now let me verify the fix was applied correctly:

  62. Assistant

    The fix looks correct. Now let me run the existing tests to make sure the fix doesn't break anything:

  63. Assistant

    Let me set up the Go environment:

  64. Assistant

    The go environment needs GOPATH or GOMODCACHE to be set. Let me try setting that.

  65. Assistant

    Let me fix the Go environment:

  66. Assistant

    Good, the existing tests pass. Let me run all the runtime tests:

  67. Assistant

    Let me check if the failure is from my changes or pre-existing:

  68. Assistant

    Let me check if this test was already failing before my changes:

  69. Assistant

    Good, the test failure TestDoCompactAfterHookFires is a pre-existing failure, not related to my change. Let me restore my fix:

  70. Assistant

    Now let me run all the tests except the pre-existing failure:

  71. Assistant

    The bash shell is interpreting the !. Let me escape it or use a different approach.

  72. Assistant

    All non-broken tests pass. Let me also run the specific tests that exercise streaming and tool calls:

  73. Assistant

    All tests pass. Let me also run the adapter tests:

  74. Assistant

    All tests pass. Now let me create a test to verify the fix works for the specific scenario described in the issue - tool_calls and finish_reason "stop" in the same chunk:

  75. Assistant

    I need to add the AddToolCallAndStopInSameChunk method to the streamBuilder. Let me look at how to properly structure the test:

  76. Assistant

    Let me check what's available in the runtime test package:

  77. Assistant

    Let me check how the runtime tests set up their test infrastructure:

  78. Assistant

    Let me create a proper test that uses the existing test infrastructure. I'll add the test to the existing test file:

  79. Assistant

    Wait, I need to re-read the constraints. The instructions say "UNDER NO CIRCUMSTANCES should you modify existing tests or add new tests to the repository." So I should NOT add test methods to the streamBuilder or add new test functions to the repository. I can only modify the source code and run existing tests.

    Let me just verify my fix by creating a temporary test script that I'll delete before submitting.

  80. Assistant

    Let me create a temporary test file to verify the fix, then delete it:

  81. Assistant

    Let me check if the noopTel struct needs the context import:

  82. Assistant

    Let me check the Telemetry interface:

  83. Assistant

    I need to update the test file to implement all methods of the Telemetry interface:

  84. Assistant

    Let me check the full Telemetry interface:

  85. Assistant

    Good, the interface matches. Now let me run the tests:

  86. Assistant

    I need to remove the unused tm variable.

  87. Assistant

    Let me also check if we need the team import at all:

  88. Assistant

    Let me simplify the test by removing the unnecessary team import:

  89. Assistant

    Let me check if NewChannelSink exists:

  90. Assistant

    Good. Now let me run the tests:

  91. Assistant

    All tests pass, including the new ones that specifically test the LiteLLM scenario. Let me also verify the fix works by reverting it and confirming the new tests would fail with the old code:

  92. Assistant

    The test confirms the bug - with the old code, tool calls are lost when they arrive in the same chunk as finish_reason: "stop" (0 calls instead of 1). Let me restore the fix:

  93. Assistant

    Now let me verify the fix works again:

  94. Assistant

    The fix works. Now let me remove the temporary test file and run all existing tests one final time:

  95. Assistant

    Now let me run all existing tests to make sure everything is good:

  96. Assistant

    All tests pass. Let me clean up the backup file and verify the final state:

  97. Assistant

    Let me verify no temporary test files remain:

  98. Assistant

    Good. Let me also run the adapter tests one more time:

  99. Assistant

    Let me view the final diff to verify the change:

  100. Assistant

    The diff looks clean. Let me verify there are no other changes:

  101. Assistant

    The diff looks clean - only one file changed with the exact fix needed. Let me now run one final comprehensive test to make sure everything works:

  102. Assistant

    The only failure is the pre-existing TestDoCompactAfterHookFires test which was already broken before my change. All other tests pass. Let me verify this one more time:

  103. Assistant

    Good, the only failure is the pre-existing TestDoCompactAfterHookFires. Let me also make sure the entire project builds:

  104. Assistant

    Good, the build succeeded. Let me also run the linter to make sure my change follows the project's style:

  105. Assistant

    Let me run go vet to check for any issues:

  106. Assistant

    All checks pass. Let me now review the complete change one final time and submit:

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