Skip to content
TheChatArchiveThe Chat Archive
GLMz-ai/glm-5.2· 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. GLM Assistant

    Let me start by exploring the repository structure to understand the codebase.

  3. GLM Assistant

    This is a Go repository. Let me search for "no response from subagent" to find the relevant code.

  4. GLM Assistant

    Let me search for "no response" more broadly, perhaps in case it's worded differently.

  5. GLM Assistant

    Let me look for subagent tool handling code.

  6. GLM Assistant

    Let me look at the agent delegation code and how subagent responses are processed.

  7. GLM Assistant

    Now let me look at the GetLastAssistantMessageContent function in session.go, which is the key function that returns the subagent's response. The issue is that the subagent returns tool_calls but the host agent reports "no response from subagent". This suggests GetLastAssistantMessageContent returns empty content when the last assistant message contains tool_calls instead of content.

    Let me look at session.go.

  8. GLM Assistant

    Found it. The getLastMessageContentByRole function returns only the content of the last assistant message, ignoring tool calls. Let me see the full function.

  9. GLM Assistant

    Let me look at the chat package to understand how streaming messages and tool calls are processed.

  10. GLM Assistant

    Now let me look at the runtime loop that processes model streaming responses and tool calls. Let me find the main run loop.

  11. GLM Assistant

    Let me look at the stream processing and recordAssistantMessage, processToolCalls functions.

  12. GLM Assistant

    Let me look at the stream processing into streamResult, particularly how Stopped and Calls are set.

  13. GLM Assistant

    Let me look at the loop logic around Stopped and how the loop decides to continue or exit.

  14. GLM Assistant

    Let me look at the OpenAI provider's stream parsing for tool calls.

  15. GLM Assistant

    Let me look at the response_stream.go which seems to handle the new "responses" API and the event_stream.go. But wait, the issue is about LiteLLM proxy as an OpenAI-compatible API. Let me look at the response_stream.go around lines 240-270, where it sets the finish reason.

  16. GLM Assistant

    That's the "responses" API. LiteLLM uses the chat completions API. Let me look at event_stream.go which handles the chat completions SSE stream.

  17. GLM Assistant

    Let me look at how the chat completions stream is created in client.go.

  18. GLM Assistant

    Let me look at the StreamAdapter Recv function fully.

  19. GLM Assistant

    Let me look at processToolCalls to understand when tool calls are not processed.

  20. GLM Assistant

    Let me look at existing tests for getLastMessageContentByRole / GetLastAssistantMessageContent to understand expected behavior.

  21. GLM Assistant

    Let me check the git log for recent changes to relevant files.

  22. GLM Assistant

    Let me look at loop_steps.go for max-iterations and non-interactive handling.

  23. GLM Assistant

    Let me look at the existing tests for handleStream / streaming to understand the test setup.

  24. GLM Assistant

    Let me look at TestToolCallSequence and the runSession helper fully.

  25. GLM Assistant

    I believe I've found the bug. In handleStream, the early-return check for FinishReasonStop/FinishReasonLength happens BEFORE processing the tool call deltas in the same chunk. If a provider (like LiteLLM) sends tool calls in the same chunk as the finish_reason, those tool calls are dropped.

    Let me write a reproduction test to confirm.

  26. GLM Assistant

    Let me simplify the reproduction test using existing helpers.

  27. GLM Assistant

    GOMODCACHE and GOPATH are empty. Let me set them explicitly.

  28. GLM Assistant

    I've reproduced the bug. The early-return on FinishReasonStop fires before processing tool call deltas in the same chunk. Let me view the exact code structure to design a clean fix.

  29. GLM Assistant

    Now I understand the full structure. The fix: move the delta processing (tool calls, reasoning, content) BEFORE the finish-reason early-return check. But the tool call processing block ends with continue, which would skip the finish-reason check. So I need to remove that continue and instead, after processing tool calls, fall through to the finish-reason check.

    Let me restructure. The cleanest approach: extract the finish-reason early-return to AFTER all the delta processing. So:

    choice := response.Choices[0]
    
    if len(choice.Delta.ThoughtSignature) > 0 {
        thoughtSignature = choice.Delta.ThoughtSignature
    }
    
    // Handle tool calls
    if len(choice.Delta.ToolCalls) > 0 {
        // process tool calls (remove the `continue`)
    }
    
    // reasoning
    if choice.Delta.ReasoningContent != "" { ... }
    
    // thinking signature
    if choice.Delta.ThinkingSignature != "" { thinkingSignature = ... }
    
    // content
    if choice.Delta.Content != "" { ... }
    
    // Now check finish reason for early return (after processing the delta,
    // so tool calls/content in the same chunk as finish_reason are captured)
    if choice.FinishReason == chat.FinishReasonStop || choice.FinishReason == chat.FinishReasonLength {
        recordUsage()
        applyXMLFallback()
        finishReason := choice.FinishReason
        if finishReason == chat.FinishReasonStop && len(toolCalls) > 0 {
            finishReason = chat.FinishReasonToolCalls
        }
        return streamResult{...}, nil
    }
    
    // Track the provider's explicit finish reason (e.g. tool_calls)
    if choice.FinishReason != "" {
        providerFinishReason = choice.FinishReason
    }
    

    Wait, but the providerFinishReason tracking is currently AFTER the early-return. If I move the early-return to after delta processing, I need to keep providerFinishReason tracking after the early-return. That's fine.

    But there's a subtle issue: the original code tracks providerFinishReason for non-stop/length finish reasons (like "tool_calls"). With my restructure, the early-return handles stop/length. For "tool_calls" finish reason, the early-return doesn't fire, and we track providerFinishReason = "tool_calls". Good, that's preserved.

    However, there's a concern about the continue after tool calls. Currently, when a chunk has tool calls, it processes them and continues (skipping reasoning/content). If I remove the continue and there's no finish reason, it falls through to reasoning/content processing (which are empty) and then to the finish-reason check (no early return) and providerFinishReason tracking. That's fine.

    But if a chunk has tool calls AND a finish reason "stop", removing the continue means after processing tool calls, it falls through to reasoning/content (empty), then hits the early-return.

    Now, there's another concern: the order of the early-return check vs the providerFinishReason tracking. In the original, for stop/length, the early-return fires and providerFinishReason is NOT updated (which is fine, since stop/length are handled by early return). For "tool_calls", providerFinishReason is set. With my restructure, same behavior.

    Let me now also consider: what about content being processed before the early-return when finish_reason is "stop"? Currently content in the same chunk as stop is dropped. With my fix, it's captured. Let me check if any test would break. Actually, let me reconsider — is it possible a provider sends content AND finish_reason "stop" in the same chunk where the content should NOT be captured? No, content should always be captured. So this is a strict improvement.

    But wait, I want to be careful about the xmlToolCallGate. If content with `

  30. GLM Assistant

    Now let me apply the fix. First, I'll remove the early-return block and the providerFinishReason tracking from their current position (they'll be re-added after delta processing).

  31. GLM Assistant

    Now I need to remove the continue at line 186 so that tool call processing falls through to the finish-reason check. Let me also add a clarifying comment.

  32. GLM Assistant

    My edit accidentally removed the if len(choice.Delta.ToolCalls) > 0 { line. Let me fix that.

  33. GLM Assistant

    Now remove the continue at line 191 so tool calls fall through to the finish-reason check.

  34. GLM Assistant

    Now add the early-return block + providerFinishReason tracking after the content block (before the loop's closing brace).

  35. GLM Assistant

    Now let me build and run my reproduction test.

  36. GLM Assistant

    The reproduction test passes now. Let me run the full runtime test suite to ensure I didn't break anything.

  37. GLM Assistant

    Let me find which test(s) failed.

  38. GLM Assistant

    Let me look at the TestDoCompactAfterHookFires test to understand what changed.

  39. GLM Assistant

    Let me check whether this test was already failing before my change by stashing.

  40. GLM Assistant

    The test TestDoCompactAfterHookFires was already failing before my change — it's a pre-existing failure (likely jq not installed in this environment). My change didn't break it. Let me confirm.

  41. GLM Assistant

    jq is not installed — that's a pre-existing environment issue unrelated to my change. Let me run the full runtime test suite excluding the jq-dependent test to confirm everything else passes.

  42. GLM Assistant

    All runtime tests pass. Let me also run the oaistream tests since they're related to the streaming adapter.

  43. GLM Assistant

    Let me make my reproduction test more thorough, covering edge cases. Let me first look at how tests register tools and verify tool execution.

  44. GLM Assistant

    Let me look at how tests register tool handlers that get executed end-to-end.

  45. GLM Assistant

    Let me look at the contract_test.go for end-to-end tool execution test patterns.

  46. GLM Assistant

    Let me look at the harness_test.go which tests end-to-end tool execution with a registered tool handler.

  47. GLM Assistant

    Let me look at the queueProvider which returns multiple streams, useful for end-to-end tests.

  48. GLM Assistant

    Let me look at how tests add toolsets/tools to agents and register handlers.

  49. GLM Assistant

    Let me look at how registerDefaultTools registers handlers and how custom tool handlers map to tool names. Let me find the registration logic.

  50. GLM Assistant

    Let me look at the toolexec.Dispatcher.Process to understand how handlers are resolved for execution.

  51. GLM Assistant

    Let me check how available is determined for a tool call.

  52. GLM Assistant

    Let me look at how the runtime gathers the agent's tools (getTools) to set up an end-to-end test.

  53. GLM Assistant

    So a.Tools(ctx) returns the agent's tools. Let me look at the agent's Tools method.

  54. GLM Assistant

    Now let me write a comprehensive end-to-end reproduction test that registers a tool handler and verifies the tool gets executed when the tool call arrives in the same chunk as finish_reason: "stop".

  55. GLM Assistant

    Both tests pass. Let me verify that without my fix, the end-to-end test actually catches the bug (to confirm the test is meaningful).

  56. GLM Assistant

    Both tests fail without the fix and pass with it — confirming the fix is meaningful. Now let me also check the Responses API path (response_stream.go) to ensure it doesn't have a similar bug.

  57. GLM Assistant

    The Responses API emits tool calls as separate deltas from the finish_reason, so it's not affected. Let me run the broader test suite and build the whole project to ensure nothing is broken.

  58. GLM Assistant

    A session test failed. Let me check if it's related to my change or pre-existing.

  59. GLM Assistant

    Both pre-existing failures are environment issues (missing jq, tests running as root) unrelated to my change. Now let me remove my temporary reproduction test file since I should not add new tests to the repository.

  60. GLM Assistant

    Let me re-run the runtime tests to confirm everything still passes after removing the repro test.

  61. GLM Assistant

    Now let me review the final diff of my change to make sure it's clean and correct.

  62. GLM Assistant

    The diff looks clean. Let me review the full updated loop once more to ensure the logic is sound.

  63. GLM Assistant

    The logic is sound. Let me reconsider edge cases:

    1. A chunk with tool calls + finish_reason "stop" (the bug case): tool calls processed → finish check fires → returns with toolCalls populated, Stopped=false, finishReason=tool_calls. ✓ FIXED.

    2. A chunk with tool calls only (no finish reason): tool calls processed → finish check (no match) → providerFinishReason tracking (empty) → loop continues. ✓ Same as before.

    3. A chunk with tool calls + finish_reason "tool_calls": tool calls processed → finish check (tool_calls isn't stop/length, no match) → providerFinishReason = "tool_calls" → loop continues. ✓ Same as before (in the original, providerFinishReason was tracked BEFORE the tool call block, so it was also set; same result).

    4. A chunk with content + finish_reason "stop": content processed → finish check fires → returns with content. ✓ (improvement — previously content in same chunk as stop was dropped).

    5. A chunk with content + finish_reason "stop" + usage (trackUsage): the StreamAdapter would set FinishReason based on lastFinishReason... but that's the adapter's job. The handleStream just sees whatever FinishReason the adapter provides. ✓

    6. A chunk with ONLY finish_reason "stop" (no delta): nothing processed → finish check fires → returns. ✓ Same as before.

    7. A chunk with reasoning + finish_reason "stop": reasoning processed → finish check fires. ✓ (improvement).

    8. A chunk with thoughtSignature + finish_reason: thoughtSignature was already captured before (unchanged). ✓

    One concern: the xmlToolCallGate interaction. If content with `

  64. GLM Assistant

    All pass. Let me do a final full build and vet to ensure no compile issues across the project.

  65. GLM Assistant

    Everything builds and vets cleanly. Let me do a final check of git status to ensure only the intended change is present (no leftover repro test).

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