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.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 its structure and locate relevant code. Let's first get an overview.
- Assistant
The repository seems to be a Rust project. Let me look at the overall structure.
- Assistant
This is a Go project. Let me explore further to understand the structure, especially related to LiteLLM proxy, subagent tool calls, and the OpenAI-compatible API handling. Let me look at the README and main packages.
- Assistant
Let me explore the repository structure more and look for where subagents and tool_calls handling happens.
- Assistant
This is a Go project. The issue is about subagent tool_calls not being handled when using LiteLLM proxy. Let me look at the agent and subagent-related code.
- Assistant
Let me look at the agent delegation code since that's likely where the subagent tool calls are processed.
- Assistant
Let me search for related terms.
- Assistant
Let me search more broadly.
- Assistant
The error message mentioned in the issue description is "no response from subagent". Let me search more broadly.
- Assistant
So the issue is about "No response from agent" messages. Let me look at these files to understand the flow.
- Assistant
Now let me look at the error message in the issue description: "no response from subagent". Let me search for that pattern more broadly.
- Assistant
The issue is about tool_calls from subagents not being handled when using LiteLLM proxy. The key part is that the subagent returns a valid tool_calls response, but the host agent reports "no response from subagent" and does not execute the tool call.
Let me look at the model/provider layer to understand how responses are processed, particularly around tool_calls handling.
- Assistant
The error message is "No response from agent", not "no response from subagent". Let me look at how the tool_calls are handled. The issue says that subagent returns valid
tool_callsresponse but the host agent reports "no response from subagent". Let me search for how the response content is extracted. - Assistant
Let me look at the session.go file to understand how GetLastAssistantMessageContent works.
- Assistant
Let me look at the
GetLastAssistantMessageContentmethod to understand how it works: - Assistant
Let me check that function to see what it does.
- Assistant
Now I see the issue! The
GetLastAssistantMessageContent()returnsContentfield only, notToolCalls. When the subagent returns onlytool_calls(emptyContent), this function returns an empty string.Let me look at the runtime loop to understand how tool calls are processed.
- Assistant
Let me look at the runtime loop more closely to see where tool calls are handled. Let me look at the main loop structure.
- Assistant
Let me look at the rest of the loop to understand how tool calls are handled. Y
- Assistant
Let me look at the loop code to understand how tool calls are handled.
- Assistant
Let me see the rest of the loop to understand how tool calls are processed.
- Assistant
Let me continue reading the runTurn function to understand how tool calls are handled.
- Assistant
Let me continue reading the runTurn function to see how tool calls are processed.
- Assistant
Now let me look at the MCP server to understand the "No response from agent" message:
- Assistant
Now I understand the issue better. Looking at the flow:
- The subagent returns a response with
tool_calls(and empty text content) - The tool calls should be executed within the subagent's own loop
- After the subagent completes,
GetLastAssistantMessageContent()returns the last assistant message's text content
But the issue says the host agent reports "no response from subagent" and does not execute the tool call. This suggests that the subagent's tool calls are NOT being executed. Let me check how
res.Stoppedis determined, because if the model reportsfinish_reason: "stop"even when there are tool calls, the loop might stop before executing them. - The subagent returns a response with
- Assistant
Now let me look at the
streamResulttype and howStoppedis set: - Assistant
Let me look at the streamResult type and how Stopped is set.
- Assistant
Now let me look at how the OpenAI provider handles streaming and check for LiteLLM-specific issues:
- Assistant
Now let me look at the OpenAI adapter to understand how tool calls are processed:
- Assistant
Let me look at the streaming adapter to see how it converts OpenAI responses to chat.Message.
- Assistant
Let me look at the streaming adapter:
- Assistant
Now let me understand the key flow. Let me check the
response_stream.gofor non-streaming responses: - Assistant
Let me now look at how
Stoppedis used in therunTurnfunction more carefully: - Assistant
Now I need to understand the flow. The key issue is likely around how
finish_reasonis handled. Let me look at howFinishReasonStopis defined: - Assistant
Now let me look at
processToolCallsto understand how tool calls are executed: - Assistant
Let me look at the tool dispatch code:
- Assistant
Let me look at the
handleStreamfunction more carefully to understand when it setsStoppedtotruewhen tool calls are present. The key issue may be in the OpenAI adapter's handling offinish_reason: "stop"with tool calls: - Assistant
Now I understand the issue! Let me trace through the exact flow. In
handleStream(streaming.go), the finish_reason is checked BEFORE tool calls are processed from the current chunk. When LiteLLM sends tool calls andfinish_reason: "stop"in the SAME chunk, the tool calls from that chunk are never processed because the early return fires first.Let me verify this by looking at the exact ordering in
handleStream: - Assistant
Now I have a clear understanding of the bug. Let me look at the full
handleStreamfunction to see the exact order of operations: - Assistant
Now I understand the root cause. In
handleStream(streaming.go), when a chunk contains BOTHtool_callsANDfinish_reason: "stop", the finish reason check fires BEFORE the tool call processing, causing the tool calls to be lost. This is exactly what happens with LiteLLM proxy.Let me first create a reproduction script to confirm the bug:
- Assistant
Let me examine more closely what happens when LiteLLM sends a response. Let me look at how the OpenAI SDK handles the conversion:
- Assistant
Let me look at the exact flow in
handleStreammore carefully. The key issue is the ordering - when LiteLLM sends bothtool_callsandfinish_reason: "stop"in the SAME streaming chunk, the finish_reason check happens before tool_calls are accumulated: - Assistant
Now I can see the bug clearly. When LiteLLM sends a chunk with BOTH
tool_callsinchoice.Delta.ToolCallsANDfinish_reason: "stop"in the SAME chunk, the code hits theFinishReason == "stop"check FIRST (line 132) and returns immediately. The tool calls from that chunk (line 155) are NEVER processed because they come AFTER the early return. Sincelen(toolCalls) == 0at that point,Stoppedis set totrueand the tool calls are lost.The fix is to process tool calls BEFORE checking the finish reason. Let me implement this:
- Assistant
Now I understand the bug completely. The fix is to move the tool call processing BEFORE the finish reason check. Let me implement the fix:
- Assistant
The indentation is wrong - it's missing the leading tab for the loop body. Let me fix it:
- Assistant
I need to fix the indentation. The code inside the
forloop needs two tabs. Let me fix this: - Assistant
Good. Now let me verify the rest of the file is clean - there should be no duplicate tool call processing code after the new blocks:
- Assistant
There's a duplicate - the old code was left behind. I need to remove the old blocks (lines 215-292):
- Assistant
I see there's broken code around lines 212-215. Let me fix the leftover junk:
- Assistant
I still see a structural issue. Lines 203-212 have the return statement with missing
}, niland there's leftover code. Let me fix the remaining issue: - Assistant
Now the file looks correct. Let me verify the full file structure is correct:
- Assistant
Good. The file looks clean. Now let me verify the changes compile correctly:
- Assistant
Let me set up the Go environment:
- Assistant
Let me try to set up the Go environment properly.
- Assistant
Let me set up the environment properly:
- Assistant
Good, the build succeeds. Now let me run the existing tests to make sure the changes don't break anything:
- Assistant
Let me run the full test suite for the streaming module:
- Assistant
Let me check if there are specific handleStream tests:
- Assistant
Let me search for tests that test
handleStreamdirectly: - Assistant
Let me look at the streaming-related tests:
- Assistant
Let me search for the handleStream tests:
- Assistant
Let me search for existing tests related to handleStream with tool calls:
- Assistant
Let me check the existing tests to see if any test the streaming tool_calls behavior:
- Assistant
Now let me run the full test suite for the runtime package to verify my changes don't break anything:
- Assistant
Let me see which tests failed:
- Assistant
The test
TestDoCompactAfterHookFiresis failing. Let me check if this is related to my change: - Assistant
This test failure looks like it might be pre-existing or related to session compaction. Let me check if it was already failing before my change:
- Assistant
Good - this test was already failing before my change (pre-existing issue). Let me restore my changes and run all other tests:
- Assistant
Let me run all the runtime tests excluding the pre-existing failing one:
- Assistant
The
!in the regex is causing bash issues. Let me escape it. - Assistant
All tests pass (except the pre-existing failure). Let me also run the streaming-specific tests:
- Assistant
Good. Let me now also check that the existing tests that specifically test tool_calls and handleStream behavior pass:
- Assistant
All tool-call related tests pass. Let me also run tests for the full project (excluding slow tests):
- Assistant
Let me check if the config failure is pre-existing:
- Assistant
Good - the config failure is pre-existing (failing without my changes too). Let me restore my changes:
- Assistant
Good. Now let me run the streaming-related tests specifically to make sure my changes work correctly:
- Assistant
All tool-call related tests pass. Let me also run the oaistream adapter tests:
- Assistant
All tests pass. Let me now review the final state of my changes:
- Assistant
The diff looks clean and correct. Let me now verify the full file is syntactically correct by building:
- Assistant
Good, build succeeds. Let me also run the full runtime tests one more time to be sure:
- Assistant
Let me verify the only failure is the pre-existing one:
- Assistant
The only failure is the pre-existing
TestDoCompactAfterHookFires. My change is clean.Now let me verify the complete diff one more time and review the logic:
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
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →