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 structure to understand the codebase and locate the relevant code for handling subagent tool calls.
Assistant
Good! The main file for subagent handling seems to be
agent_delegation.go. Let me examine it.Assistant
Let me open the agent_delegation.go file to understand the subagent handling logic:
Assistant
Now let me search for where the subagent response is processed, particularly looking for "tool_calls":
Assistant
Now let me check the session.go file to see how
GetLastAssistantMessageContentis implemented:Assistant
Now let me understand how the messages are structured. Let me look for how tool_calls are stored in messages:
Assistant
Let me look at how the runtime processes the stream and handles tool calls:
Assistant
Let me look at the main loop where tool calls are processed:
Assistant
Let me look at the loop.go file:
Assistant
Let me continue reading the loop:
Assistant
Now let me look for where tool calls from the model response are processed:
Assistant
More specifically, I need to see how
res.Callsis populated. Let me look for the stream processing.Assistant
Now let me look at where
res.Callsis populated. Let me search for the stream response:Assistant
Now I need to see how the stream response is built. Let me search for where
resis constructed:Assistant
/ ____| ____/ ____|/ _ \ | |/ __ )/ ____|/ _ \ |_ _| | (___ | |__ | (___ | | | | | / __'| (___| | | | | | \___ \|___| \____| |_| |_|_|_____(_)_____|_|_|_| |_| ____ ___ _ ___ ____ _ ___ ____ _ _/ | _| |/ _ _ | |/| __ ) |/ |
___ | || | | | || | ' / _ | _ \ /
) | || || || | || () | __/ |\ \
|/|_/ || ||_/|/| _|Assistant
I received an error because I included some random text instead of a proper tool call. Let me continue investigating the issue by looking at the fallback.go file to understand how the stream response is built.
Assistant
Now I need to look at the
handleStreamfunction to see how it processes the stream and builds the streamResult with tool calls.Assistant
Now I understand the issue better. Let me examine how the tool call results are structured:
Assistant
I need to make an actual tool call. Let me search for ToolCallResult to understand the return type structure.
Assistant
Let me look at the tools.go file to understand ToolCallResult structure.
Assistant
Let me look more carefully at how the stream processes responses and check if there's a non-delta path for tool calls:
Assistant
Let me investigate the OpenAI provider to see how it handles non-streaming responses, since LiteLLM uses an OpenAI-compatible API:
Assistant
Let me search for the actual error message more carefully - it might use different wording:
Assistant
Let me look at the issue description again - it says "no response from subagent". Let me search in a broader scope:
Assistant
Assistant
The user is reminding me that I need to use tool calls properly. Let me issue the command correctly.
Assistant
Looking at the ResponseStreamAdapter, I can see that when "response.done" or "response.completed" events are received, it checks for tool calls and sets the finish reason accordingly. However, this is for the OpenAI Responses API.
The issue mentions LiteLLM proxy with an OpenAI-compatible API. Let me look for the regular OpenAI chat completion stream adapter, which is more likely what LiteLLM would use.
Assistant
Let me check the adapter.go and event_stream.go files to see how the OpenAI chat completion streaming works.
Assistant
OK, so that's just an interface definition for the Responses API. Let me look at the adapter.go to see how regular chat completions are handled.
Assistant
Now let me look at the oaistream package to see how the stream adapter works for regular chat completions:
Assistant
Let me check the oaistream adapter.go file:
Assistant
Looking at this code, I can see that in the
handleStreamfunction, when a finish reason of "stop" or "length" is encountered, the function returns early. But if LiteLLM sends the tool calls in the same chunk as the finish_reason, they won't be processed yet, and they'll be lost!Let me create a test script to confirm this issue:
Assistant
<tool_call> <function=bash_terminal> <parameter=command> export GOCACHE=/tmp/go-cache && go run /tmp/test_tool_calls.go </tool_call>
Assistant
I need to use a proper tool call. Let me analyze the issue more carefully by looking at the streaming.go code where the bug is.
Assistant
Now let me carefully examine the streaming.go code to understand the exact bug:
Assistant
Now I can see the bug! The issue is in the order of operations in
handleStream:- Line 132: Check if
choice.FinishReason == chat.FinishReasonStop || chat.FinishReasonLength - Line 138: Return early with the current
toolCalls - Line 157+: Process tool calls from
choice.Delta.ToolCalls
When LiteLLM sends tool calls in the same chunk as the finish_reason, the code returns BEFORE processing those tool calls, so they're lost!
Let me verify this by looking at the complete flow:
- Line 132: Check if
Assistant
Perfect! I've found the bug!
The Bug: In
handleStreamfunction in/docker-agent/pkg/runtime/streaming.go, when a finish reason of "stop" or "length" is received, the function returns immediately at line 148 before processing any tool calls that might be in the same chunk (lines 158-185).This is a problem because some providers (like LiteLLM proxy) may send the tool calls in the same chunk as the finish_reason: "stop", rather than sending them in separate chunks first and then sending the finish_reason in a final chunk.
The Fix: We need to process the tool calls from
choice.Delta.ToolCallsbefore checking the finish reason and returning.Let me create the fix:
Assistant
Now I need to fix the bug. The issue is that when finish_reason is "stop" or "length", the function returns early before processing tool calls that might be in the same chunk.
Let me look at the entire streaming.go file to understand the structure better:
Assistant
Now I understand the bug clearly. The issue is in the
handleStreamfunction at line 132. When a finish reason of "stop" or "length" is received, the function returns early before processing the tool calls that might be in the same chunk.The fix is to process tool calls from
choice.Delta.ToolCallsbefore checking the finish reason and returning.Let me create the fix:
Assistant
The patch approach failed. Let me use the edit tool to make the changes directly to the streaming.go file. I need to move the tool call processing block to before the finish reason check.
Let me first view the current state of the file to understand the exact line numbers and structure.
Assistant
I need to continue fixing the bug. The issue is clear: tool calls must be processed before checking the finish reason, otherwise tool calls sent in the same chunk as
finish_reason: "stop"are lost.Let me edit the streaming.go file to fix this:
Assistant
Now I need to move the tool call processing block to before the finish reason check. The key is to:
- Move the tool call processing (lines 158-211) to before the finish reason check (lines 132-148)
- Remove the
continuestatement at line 211 so the code flows through to check the finish reason after processing tool calls
Let me use the open and edit commands to make this change:
Assistant
I need to continue working on the fix. The issue is clear - tool calls need to be processed before checking the finish reason. Let me use the edit command to make the necessary changes.
Assistant
Sorry, the edit got corrupted due to bash escaping issues. Let me restore the file and try a different approach.
Assistant
Let me use a different approach - I'll create a script to make the edit properly:
Assistant
Let me verify the changes were applied correctly:
Assistant
Perfect! The changes look good. The tool call processing block is now before the finish reason check. Let me verify the rest of the file to make sure everything is correct:
Assistant
Great! The fix looks good. The tool call processing is now done before checking the finish reason. Let me verify the code compiles and then run the existing tests:
Assistant
The user is telling me that my previous action was not parsed properly. Let me check what happened - it seems the go build command is still running and downloading dependencies. I should wait for it to complete or check if there was an issue. Let me just continue and check the build status.
Assistant
Great! The build succeeded. Now let me run the tests to make sure the fix doesn't break anything. Let me first find and run tests related to streaming:
Assistant
Let me search for test files that might test the streaming functionality.
Assistant
Good! The tests are passing. Now let me create a test to verify that my fix actually works for the scenario described in the issue - when tool calls are sent in the same chunk as finish_reason:
Assistant
The test file wasn't added to the package. Let me add it properly:
Assistant
Let me fix the test:
Assistant
Let me look at how other tests in the same directory create agents and telemetry:
Assistant
Let me look at one of the test files to see how they set up test fixtures:
Assistant
Let me check how agents are built in the test helpers:
Assistant
I see - they use
agent.New(). Let me simplify my test by not testing the full handleStream function, but instead just verifying that the fix works by examining the code flow. Let me remove the test file and instead write a simpler verification script that demonstrates the bug was fixed:Assistant
Let me verify the fix is correct by reviewing the changed code once more and then run the existing tests to make sure nothing broke:
Assistant
Perfect! The diff shows the fix clearly:
- Tool calls are now processed before checking the finish reason
- The
continuestatement was removed, so the code now flows through to check the finish reason after processing tool calls - This ensures that when LiteLLM sends tool calls in the same chunk as
finish_reason: "stop", the tool calls are captured before returning
Now let me run the existing runtime tests to make sure the fix doesn't break anything:
Assistant
Good! The tests are passing. Let me wait for all tests to complete:
Assistant
.let me check what test failed
Assistant
Let me see more details about this failing test:
Assistant
Let me look at this test to understand what it's testing:
Assistant
This test is failing because it expects the after_compaction hook to receive the summary, but it's getting an empty string. This suggests that the summary is not being captured correctly. However, this test failure might be unrelated to my change. Let me check if this test was passing before my change by reverting and testing:
Assistant
The user is reminding me that I need to use tool calls properly. I had issued a git stash command, and it appears to have succeeded. Let me continue testing whether the failing test was already failing before my change.
Assistant
Great! The test was already failing before my change. This confirms that my fix didn't break anything - this test was already broken in the original codebase. Let me restore my changes:
Assistant
You're right, I need to use a proper tool call. Let me verify my fix is in place and summarize what I've done:
Assistant
Perfect! My fix is in place. Now let me run all the runtime tests again to confirm that the only failing test is the pre-existing one:
Assistant
Let me check which tests are failing to ensure my change doesn't introduce new failures:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.