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.
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. - Assistant
I'll start by exploring the repository to understand the structure and locate relevant code related to subagent tool_calls handling. Let me first get an overview.
- Assistant
Let me get a broader view of the repository structure and then search for the specific issue.
- Assistant
Let me search for the error message "no response from subagent" to understand where this is being reported.
- Assistant
No results for the exact phrase. Let me try searching for similar messages.
- Assistant
Let me look at the A2A (Agent-to-Agent) code since that's likely where subagent communication happens.
- Assistant
Let me look at the builtin agent tool since that seems to be the key file for agent delegation.
- Assistant
Let me look at the agent delegation code and the runtime that runs subagents.
- Assistant
Now let me look at how the runtime processes responses from the LLM, particularly how it handles tool calls from subagents. Let me look at the main runtime code.
- Assistant
Let me search for the issue more broadly.
- Assistant
Let me search more broadly.
- Assistant
Let me look at the runtime code that processes LLM responses and handles tool calls.
- Assistant
Let me look at the main runtime loop where tool calls are processed.
- Assistant
Let me look at how the LLM response is parsed and how tool calls are processed. Let me search for the streaming response handling code.
- Assistant
Let me look at how the streamResult is built and how tool calls are processed. I need to understand the full flow.
- Assistant
Let me look at the streaming.go file to understand how tool calls are handled in the stream processing.
- Assistant
Now let me look at the
processToolCallsfunction to understand how tool calls are being processed: - Assistant
Let me search for the processToolCalls function definition.
- Assistant
Let me search across all files for this function.
- Assistant
Let me look at the tool_dispatch.go file to understand how tool calls are processed:
- Assistant
Let me look at the main runtime loop to understand the control flow after receiving a stream result:
- Assistant
Now let me look at what
GetLastAssistantMessageContent()does, since that's used to get the subagent's response: - Assistant
Let me look at
GetLastAssistantMessageContent: - Assistant
Now let me look at the chat message types to understand how tool calls are structured:
- Assistant
Let me look at how the OpenAI streaming response parsing works. The issue is about LiteLLM proxy returning tool_calls with finish_reason: "stop". Let me check if there's a specific issue with how finish_reason is handled when tool_calls are present.
- Assistant
Now let me look at the streaming code more carefully to understand the issue:
- Assistant
Now I see the bug clearly. Let me look at the order of operations in the streaming loop:
choice.FinishReason == chat.FinishReasonStopcheck fires before tool_calls processing- When LiteLLM sends finish_reason: "stop" in the same chunk as tool_call deltas, those tool_calls are never accumulated into the
toolCallsslice len(toolCalls) == 0→Stopped: true→ runtime treats it as normal stop, no tool execution
Standard OpenAI API sends tool_call deltas in separate chunks with finish_reason in a final chunk. But LiteLLM (and other OpenAI-compatible proxies) can bundle the finish_reason with the last tool_call delta chunk.
The fix: move tool_calls delta processing above the finish_reason check so tool_call deltas are always accumulated regardless of whether a finish_reason is present in the same chunk.
Let me first create a test to verify the bug:
- Assistant
Let me find any existing tests for streaming.
- Assistant
Let me check the runtime tests:
- Assistant
Let me look at the e2e tests and how they test streaming to understand the test patterns:
- Assistant
Now I understand the bug. Let me look at the critical section of the streaming code more carefully:
- Assistant
Now I can clearly see the bug. The
FinishReasoncheck on line 133 happens BEFORE tool call processing on line 162. When LiteLLM sends the final chunk with bothfinish_reason: "stop"andtool_callsdeltas in the same chunk, the finish_reason check triggers an early return before the tool call deltas are accumulated.This means:
toolCallsis empty (the current chunk's tool_calls were never processed)Stopped: len(toolCalls) == 0→true- Runtime treats it as normal completion, no tool execution happens
- Sub-agent returns empty/no content → "no response from subagent"
The fix: Move tool call processing before the
FinishReasoncheck so that tool call deltas are always accumulated, even whenfinish_reasoncomes in the same chunk.Let me implement the fix:
- Assistant
Let me look at the full file to understand the exact structure and make the edit correctly.
- Assistant
Now I can see the exact issue. Looking at the loop in
handleStream(lines 107-238):- Line 132: Check for
FinishReasonStop/FinishReasonLength→ returns early - Line 159: Handle tool call deltas
When LiteLLM sends a streaming chunk with both
finish_reason: "stop"ANDtool_callsdeltas in the same chunk, the code at line 132 returns early before reaching line 159. The tool calls from that chunk are never accumulated, sotoolCallsis empty,Stopped: true, and the subagent appears to have no response.Let me fix this by moving the tool call delta processing before the finish reason check:
- Line 132: Check for
- Assistant
Now let me apply the fix. I need to move the tool call processing (lines 158-212) to before the finish_reason check (lines 131-149):
- Assistant
Let me check the actual whitespace in the file:
- Assistant
Let me use the
openandeditcommands to make the changes: - Assistant
Let me open the file and use the edit command:
- Assistant
Now I need to replace lines 132-212 with a reordered version where tool calls are processed before the finish reason check. Let me do this edit:
- Assistant
The edit looks correct. Let me verify the full file is consistent:
- Assistant
The file looks correct. Now let me verify the fix compiles and run existing tests:
- Assistant
Let me check the Go environment:
- Assistant
Let me set up the Go environment:
- Assistant
Let me set up the Go environment properly:
- Assistant
The build succeeded. Now let me run the existing tests to make sure I didn't break anything:
- Assistant
Tests seem to be passing. Let me see if they all pass by running the full test suite for the runtime package.
- Assistant
There's a failing test. Let me see which test is failing:
- Assistant
Let me look at the actual failures.
- Assistant
Let me check if this test failure is pre-existing by reverting my changes and running the test:
- Assistant
The test
TestDoCompactAfterHookFiresis already failing before my change. This is a pre-existing issue. Let me restore my changes: - Assistant
Good, the test failure is pre-existing and not related to my change. Let me verify my change didn't break any previously passing tests by running the full test suite and comparing:
- Assistant
Only
TestDoCompactAfterHookFiresfails, and it was already failing before my change. All other tests pass. Now let me write a test to verify the fix for the LiteLLM scenario. Let me create a temporary test file to verify the fix works: - Assistant
Let me look at the existing test for tool calls to understand the test pattern:
- Assistant
Let me look at how tool call tests work.
- Assistant
Let me look at the stream builder to understand how to create test streams:
- Assistant
Let me look at the streamBuilder implementation:
- Assistant
Now I understand the stream builder pattern. Let me create a temporary test file to verify the fix works for the LiteLLM scenario:
- Assistant
The file has
_test.gosuffix. Let me rename it. - Assistant
Let me fix the verification script.
- Assistant
The verification script confirms the fix:
-
Test 1 (LiteLLM scenario): Tool call name in chunk 1, arguments + finish_reason in same chunk 2
- OLD: Arguments from final chunk are lost (empty
company_search()) - NEW: Arguments correctly accumulated (
company_search({"query": "test"}))
- OLD: Arguments from final chunk are lost (empty
-
Test 3 (All in single chunk): Complete tool call + finish_reason in one chunk
- OLD:
Stopped=true,Calls=0— complete bug, everything lost - NEW:
Stopped=false,Calls=1— correctly processes
- OLD:
Now let me clean up and also write a proper Go test for this:
-
- Assistant
Let me also verify there's no similar issue in the
runCollectingflow. Let me look at what happens whenStoppedis true but there are tool calls: - Assistant
Let me look at how
Stoppedaffects the run loop to make sure the fix is complete: - Assistant
Let me look at the full context around
res.Stopped: - Assistant
Good. The fix is correct and complete. Let me run a broader set of tests to make sure nothing is broken:
- Assistant
Let me check which tests failed:
- Assistant
Let me check if these are pre-existing failures:
- Assistant
All test failures are pre-existing. Let me restore my changes:
- Assistant
Let me review the final state of the file one more time:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.