Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-sonnet-5· anthropicHugging 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. Claude Assistant

    Build succeeds. Now let's run the relevant tests.

  3. Claude Assistant

    Pre-existing failure, unrelated to my change. Let's restore my changes.

  4. Claude Assistant

    Good, confirmed pre-existing failure unrelated to my change. Now let's run the full runtime test suite again plus streaming-specific tests and check for any existing test file for streaming.go.

  5. Claude Assistant

    Let's check for mock stream implementations used in tests elsewhere (e.g., fake package).

  6. Claude Assistant

    Good, use EventSinkFunc and defaultTelemetry{}. Let's fix the test file.

  7. Claude Assistant

    Test passes with the fix. Let's confirm it fails without the fix (revert temporarily).

  8. Claude Assistant

    Confirmed the bug reproduces without the fix. Now restore the fix and remove the temp test file.

  9. Claude Assistant

    Now let's run the full test suite for the runtime package and related ones to ensure nothing else broke.

  10. Claude Assistant

    Only the pre-existing unrelated failure remains (confirmed earlier that it fails identically on the unmodified codebase). Let's also run the broader test suite for provider packages (openai, oaistream) to be safe.

  11. Claude Assistant

    All pass. Let's view the final diff for review.

  12. Claude Assistant

    This looks good. Let's do a final full build/test sanity check and clean up temp files.

  13. Claude Assistant

    Build and vet are clean, only the intended file is modified. Now going through the checklist:

  14. Claude Assistant

    Summary

    Root cause: In pkg/runtime/streaming.go, handleStream checked choice.FinishReason == stop/length before processing the current chunk's choice.Delta.ToolCalls. Native OpenAI streams always send tool-call argument deltas across several chunks and terminate with a separate, delta-less chunk carrying finish_reason: "tool_calls". However, some OpenAI-compatible gateways — notably LiteLLM proxying providers like Gemini, as described in the issue — can emit the tool call payload and finish_reason: "stop" in the very same chunk. Because the finish-reason check ran first and returned immediately, that chunk's tool call was silently dropped: the accumulated toolCalls slice used in the early return didn't yet include the current chunk's delta, res.Calls came back empty, Stopped was computed as true, and the sub-agent's tool call was never executed — matching the "no response from subagent" / dropped tool-call behavior reported.

    Fix: Reordered the loop body so the current chunk's delta (tool calls, reasoning, content) is always processed first, and the FinishReason check (early return / provider-finish-reason tracking) happens afterward. This preserves all existing behavior for the normal multi-chunk streaming case while correctly handling gateways that bundle the tool call and terminal finish reason into a single chunk.

    Verification: Added a temporary test simulating the exact LiteLLM-style single-chunk scenario (tool_calls delta + finish_reason: "stop" in one chunk), confirmed it failed before the fix (0 tool calls recorded) and passed after the fix (1 tool call, Stopped=false, FinishReason=tool_calls), then removed the temporary test file per instructions. Ran go build ./... and the full pkg/runtime/... and pkg/model/... test suites — all pass except one pre-existing, unrelated failure (TestDoCompactAfterHookFires) which I confirmed also fails identically on the unmodified codebase (a pre-existing issue unrelated to this fix).

    Checklist review

    • Reproduced the error: built a minimal handleStream scenario mirroring the issue's payload (tool call + finish_reason: "stop" in one chunk) and confirmed it caused the tool call to be lost (0 calls returned instead of 1).
    • Confirmed the fix resolves it: same scenario now returns the tool call, with Stopped=false so the runtime dispatches it.
    • Considered edge cases: preserved original behavior for split-chunk streams (tool call deltas across multiple chunks, final chunk with only finish_reason), for pure-content streams, for reasoning/thinking-signature chunks, and for chunks with no choices/usage-only chunks — only the ordering of "process delta" vs "check finish reason" changed, using an else branch so a chunk with tool-call deltas still skips content/reasoning processing exactly as before.
    • Ran existing tests (pkg/runtime/..., pkg/model/...): all pass except one pre-existing unrelated failure verified to exist independently of this change.

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