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
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.
- Assistant
Let me explore the repository more broadly to understand its structure.
- Assistant
This is a Go repository. Let me explore the pkg directory to understand the structure better.
- Assistant
This is a Go repository. Let me understand the structure better and find where subagent tool_calls are handled.
- Assistant
Let me search for "no response from subagent" to understand where this error is reported.
- Assistant
Let me search more broadly for "subagent" related terms.
- Assistant
The issue mentions "no response from subagent" - let me search for "No response from agent" since that's what appears in the code.
- Assistant
Let me examine the relevant files to understand the subagent handling:
- Assistant
Let me search for the "No response from agent" message more carefully.
- Assistant
Let me search for how the runtime processes LLM responses and handles tool_calls:
- Assistant
Let me look at the runtime loop to understand how tool calls are processed:
- Assistant
Let me look at the streaming code to understand how tool calls are extracted from LLM responses:
- Assistant
Let me look at the rest of the loop code to understand how tool calls are processed:
- Assistant
Let me examine the rest of the runStreamLoop function.
- Assistant
Let me look at how the subagent response is processed in
runForwarding: - Assistant
Let me examine
GetLastAssistantMessageContentin the session package: - Assistant
Let me search more carefully for the "no response" message. It might be in a different form:
- 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:
- Assistant
Let me look at
GetLastAssistantMessageContentmore carefully: - Assistant
Let me look at the main loop's handling of tool calls and the
processToolCallsfunction: - Assistant
Let me find and examine the
processToolCallsfunction: - Assistant
Let me examine the tool_dispatch.go file:
- Assistant
Now let me look at how the
Stoppedfield is used in the main loop: - Assistant
Let me see the full context around the
Stoppedhandling: - Assistant
Let me search for the exact error message "no response from subagent":
- Assistant
The exact message "no response from subagent" doesn't appear in the code. Let me look at the transfer_task tool implementation:
- Assistant
Let me look at the model providers, especially how they handle streaming and tool_calls:
- Assistant
Let me look at the model provider directory.
- Assistant
Let me focus on the core issue. Let me look at the OpenAI streaming provider and how it handles tool_calls:
- Assistant
Let me examine the response_stream.go to see how tool calls are parsed from streaming:
- Assistant
Now let me look at the chat completions streaming adapter:
- Assistant
Let me look at the oaistream package which handles the chat completions streaming:
- Assistant
Let me look at the messages.go file in oaistream which handles the chat completions API:
- Assistant
Let me look at the adapter.go to understand how streaming works:
- Assistant
Let me understand the flow better. Let me look at how the
StreamAdapteris used and howtrackUsageis set: - Assistant
Let me look at how the OpenAI client decides which stream format to use (chat completions vs responses API):
- Assistant
Let me look at the full stream creation logic:
- Assistant
Let me understand the full flow better. Let me look at how
GetLastAssistantMessageContentworks and trace the delegation path: - Assistant
Let me look at the chat types to understand finish reasons:
- Assistant
Let me look at the complete flow more carefully. Let me trace the exact execution path in
handleStreamwhen LiteLLM sends tool_calls with finish_reason "stop". Let me look at how the adapter handles the finish_reason clearing: - Assistant
Now let me look at how the
Stoppedflag affects the tool call execution flow. Let me look at therunTurncode afterprocessToolCalls: - Assistant
Now I have a good understanding of the flow. Let me look at the
runForwardingfunction more closely. The key issue is likely that when a subagent's model returns tool_calls withfinish_reason: "stop"(as LiteLLM does), something goes wrong. Let me look at therunForwardingpath and theGetLastAssistantMessageContentfunction: - Assistant
Let me look at the agent tool implementation for subagents:
- Assistant
Let me read the agent.go file:
- Assistant
Now I understand the issue. Let me trace through the exact flow to identify the root cause. Let me look at the
handleStreamfunction more closely, specifically the order of processing: - Assistant
Now I can see the issue clearly. In the
handleStreamfunction, the order of processing is:- Check
choice.FinishReason == FinishReasonStop→ early return - 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 incompletetoolCallsslice.With LiteLLM proxy and
trackUsageenabled (the default), the adapter:- Clears
finish_reason: "stop"from the choice to empty - Processes tool call deltas normally
- When usage is present (same chunk), re-injects
FinishReasonStopintoChoices[0].FinishReason
So the response from the adapter has BOTH
Choices[0].Delta.ToolCallsANDChoices[0].FinishReason = "stop". ThenhandleStreamsees 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:
- Check
- Assistant
Let me look at the existing tests for the streaming code:
- Assistant
Let me look at the existing tests for the handleStream function:
- Assistant
Let me look at the test files to understand how handleStream is tested:
- Assistant
Let me look at the adapter tests for the oaistream package:
- Assistant
Let me look at turn_end_test.go:
- Assistant
Now I can see the bug clearly! In
handleStream(streaming.go), the order of processing is:- Check
FinishReasonStoporFinishReasonLength→ early return - 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 andtrackUsageis enabled), the tool calls from that chunk are never accumulated. The function returns early with an empty or incompletetoolCallsslice.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. - Check
- Assistant
Now I understand the root cause. Let me look at the full order of processing in
handleStreammore carefully: - Assistant
Now I have a clear understanding of the issue. Let me create a reproduction script first to confirm the problem:
- Assistant
Let me look at the streamBuilder more to understand the test patterns:
- 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:
- Assistant
Now I have a clear picture. Let me now understand the exact bug:
In
handleStream(streaming.go), the processing order is:- Check
FinishReasonStop/FinishReasonLength→ early return (line 132-149) - Process
choice.Delta.ToolCalls(line 160+)
When LiteLLM proxy sends tool_calls AND
finish_reason: "stop"in the same chunk (which happens because theoaistream.StreamAdapterre-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 meanstoolCallsis empty (or missing the calls from the final chunk), andStoppedistrue.The fix is to move the tool call delta processing before the finish_reason check.
Let me now implement the fix:
- Check
- 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 andfinish_reason: "stop"in the same chunk (via the adapter's usage re-injection), the current order causes tool calls to be lost. - Assistant
Now let me implement the fix. The cleanest approach is to move the tool call delta processing before the finish_reason check:
- Assistant
Now let me verify the fix was applied correctly:
- Assistant
The fix looks correct. Now let me run the existing tests to make sure the fix doesn't break anything:
- Assistant
Let me set up the Go environment:
- Assistant
The go environment needs GOPATH or GOMODCACHE to be set. Let me try setting that.
- Assistant
Let me fix the Go environment:
- Assistant
Good, the existing tests pass. Let me run all the runtime tests:
- Assistant
Let me check if the failure is from my changes or pre-existing:
- Assistant
Let me check if this test was already failing before my changes:
- Assistant
Good, the test failure
TestDoCompactAfterHookFiresis a pre-existing failure, not related to my change. Let me restore my fix: - Assistant
Now let me run all the tests except the pre-existing failure:
- Assistant
The bash shell is interpreting the
!. Let me escape it or use a different approach. - Assistant
All non-broken tests pass. Let me also run the specific tests that exercise streaming and tool calls:
- Assistant
All tests pass. Let me also run the adapter tests:
- 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:
- Assistant
I need to add the
AddToolCallAndStopInSameChunkmethod to thestreamBuilder. Let me look at how to properly structure the test: - Assistant
Let me check what's available in the runtime test package:
- Assistant
Let me check how the runtime tests set up their test infrastructure:
- Assistant
Let me create a proper test that uses the existing test infrastructure. I'll add the test to the existing test file:
- 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.
- Assistant
Let me create a temporary test file to verify the fix, then delete it:
- Assistant
Let me check if the noopTel struct needs the context import:
- Assistant
Let me check the Telemetry interface:
- Assistant
I need to update the test file to implement all methods of the Telemetry interface:
- Assistant
Let me check the full Telemetry interface:
- Assistant
Good, the interface matches. Now let me run the tests:
- Assistant
I need to remove the unused
tmvariable. - Assistant
Let me also check if we need the team import at all:
- Assistant
Let me simplify the test by removing the unnecessary team import:
- Assistant
Let me check if
NewChannelSinkexists: - Assistant
Good. Now let me run the tests:
- 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:
- 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: - Assistant
Now let me verify the fix works again:
- Assistant
The fix works. Now let me remove the temporary test file and run all existing tests one final time:
- Assistant
Now let me run all existing tests to make sure everything is good:
- Assistant
All tests pass. Let me clean up the backup file and verify the final state:
- Assistant
Let me verify no temporary test files remain:
- Assistant
Good. Let me also run the adapter tests one more time:
- Assistant
Let me view the final diff to verify the change:
- Assistant
The diff looks clean. Let me verify there are no other changes:
- 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:
- Assistant
The only failure is the pre-existing
TestDoCompactAfterHookFirestest which was already broken before my change. All other tests pass. Let me verify this one more time: - Assistant
Good, the only failure is the pre-existing
TestDoCompactAfterHookFires. Let me also make sure the entire project builds: - Assistant
Good, the build succeeded. Let me also run the linter to make sure my change follows the project's style:
- Assistant
Let me run
go vetto check for any issues: - Assistant
All checks pass. Let me now review the complete change one final time and submit:
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 →
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 →