ISSUE DESCRIPTION Subagent toolcalls not handled when using LiteLLM proxy Summary When…
- 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_callsresponse, 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_callsentry. The requested tool call is not executed.Minimal reproduction
- Configure cagent to use LiteLLM as the model provider (OpenAI-compatible API).
- Run a workflow where the subagent is asked to use tools.
- The subagent returns a tool call (e.g.,
company_searchwith JSON arguments) and finishes withfinish_reason: "stop". - 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 usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto 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-$
Assistant
Build succeeds. Now let's run the relevant tests.
Assistant
Pre-existing failure, unrelated to my change. Let's restore my changes.
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.
Assistant
Let's check for mock stream implementations used in tests elsewhere (e.g., fake package).
Assistant
Good, use
EventSinkFuncanddefaultTelemetry{}. Let's fix the test file.Assistant
Test passes with the fix. Let's confirm it fails without the fix (revert temporarily).
Assistant
Confirmed the bug reproduces without the fix. Now restore the fix and remove the temp test file.
Assistant
Now let's run the full test suite for the runtime package and related ones to ensure nothing else broke.
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.
Assistant
All pass. Let's view the final diff for review.
Assistant
This looks good. Let's do a final full build/test sanity check and clean up temp files.
Assistant
Build and vet are clean, only the intended file is modified. Now going through the checklist:
Assistant
Summary
Root cause: In
pkg/runtime/streaming.go,handleStreamcheckedchoice.FinishReason == stop/lengthbefore processing the current chunk'schoice.Delta.ToolCalls. Native OpenAI streams always send tool-call argument deltas across several chunks and terminate with a separate, delta-less chunk carryingfinish_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 andfinish_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 accumulatedtoolCallsslice used in the early return didn't yet include the current chunk's delta,res.Callscame back empty,Stoppedwas computed astrue, 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
FinishReasoncheck (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_callsdelta +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. Rango build ./...and the fullpkg/runtime/...andpkg/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
handleStreamscenario 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=falseso 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 anelsebranch 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.
- Reproduced the error: built a minimal
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →