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 uses to get the changes that need to be submitted. Assistant
Let me start by exploring the repository structure to understand the codebase and find the relevant code that handles subagent responses and tool calls.
Assistant
This is a Go repository, not Python. Let me explore the structure more to find where subagent responses are handled.
Assistant
The system requires me to use a specific tool format. Let me try using the bash_terminal tool properly.
Assistant
Let me search for files related to "subagent" or "tool_calls" handling.
Assistant
I need to use the bash_terminal tool properly with the function call format. Let me search for relevant files in the repository.
Assistant
Let me search for files related to "tool_calls" or "tool" handling in the codebase, particularly related to subagents.
Assistant
The message "no response from subagent" wasn't found with that exact wording. Let me search for related terms.
Assistant
Let me try using the bash_terminal function to search for files.
Assistant
No output from grep. Let me search for "response" and "subagent" related code.
Assistant
So the key files related to subagents are:
- /docker-agent/pkg/runtime/hooks.go
- /docker-agent/pkg/runtime/agent_delegation.go
Let me explore these files to understand how subagent responses are handled.
Assistant
Let me look at the key runtime files to understand how tool calls are processed.
Assistant
This file is about delegation, but it doesn't seem to be the one handling tool_calls. Let me look at the loop.go and streaming.go files, which seem more likely to be related to processing tool_calls.
Assistant
The tool call was not invoked. Let me try again with the proper format for bash_terminal.
Assistant
Let me search for where tool calls are processed and specifically look for code handling subagent responses.
Assistant
Let me look at the streaming.go file to understand how tool calls are processed:
Assistant
Let me continue looking at the streaming.go file and search for how the model provider handles tool_calls, especially when dealing with LiteLLM or OpenAI-compatible APIs.
Assistant
I need to search for relevant files related to the issue. Let me use bash_terminal to search for code handling subagent responses and tool calls.
Assistant
Let me look at the model provider code to understand how tool_calls are processed:
Assistant
Let me look at the openai provider since LiteLLM is an OpenAI-compatible API:
<tool_call> <function=bash_terminal> <parameter=command> ls -la /docker-agent/pkg/model/provider/openai/ </tool_call>
Assistant
The tool call wasn't invoked properly. Let me try again using the bash_terminal function.
Assistant
Let me look at the openai adapter.go and response_stream.go files to understand how tool_calls are handled.
Assistant
Now let me look at the oaistream adapter to understand how the stream is processed:
Assistant
Now let me look at how the streaming response is handled in the loop.go and see how tool_calls are checked:
Assistant
Let me look at the chat.MessageStreamResponse structure and how it's used to understand how tool_calls are processed.
Assistant
Let me search for the code that handles tool calls from subagents and see how the issue might occur:
Assistant
Let me look at the gemini adapter since the issue mentions using gemini-pro via LiteLLM proxy:
Assistant
Let me search for where the issue might be occurring when handling tool_calls from subagents. The issue mentions that when a subagent returns tool_calls, the host agent doesn't recognize them. Let me look at how tool calls are executed in the runtime loop.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "res.Calls|Calls" /docker-agent/pkg/runtime/loop.go | head -50 </tool_call>
Assistant
Let me search for how tool calls are handled in the loop.go file.
Assistant
Let me look at the
processToolCallsfunction to understand how tool calls are processed.<tool_call> <function=bash_terminal> <parameter=command> grep -n "processToolCalls" /docker-agent/pkg/runtime/loop.go -A 30 | head -50 </tool_call>
Assistant
The tool call format wasn't properly invoked. Let me try again to use bash_terminal to search for processToolCalls function.
Assistant
The grep command exited with code 1, which means the function wasn't found in loop.go. Let me search for processToolCalls in the entire runtime package.
Assistant
Now let me look at the tool_dispatch.go file to see how tool calls are processed.
Assistant
Now let me look at the toolexec.Dispatcher to understand how tool calls are processed:
<tool_call> <function=bash_terminal> <parameter=command> cat /docker-agent/pkg/runtime/toolexec/dispatcher.go </tool_call>
Assistant
The tool call wasn't invoked properly. Let me use bash_terminal to search for the toolexec.Dispatcher code.
Assistant
Let me search for the issue in the repository to understand what the problem is. I'll look at the git log and search for related fixes.
Assistant
The grep command returned exit code 0 with no output, which means the message "no response" was not found. Let me search for the actual issue in the codebase. The issue description mentions that when a subagent returns a tool call, the host agent reports "no response from subagent". Let me search for this message.
<tool_call> <function=bash_terminal> <parameter=command> grep -rn "response.*subagent|subagent.response" /docker-agent/pkg --include=".go" 2>/dev/null | head -20 </tool_call>
Assistant
Let me search for the issue in the codebase related to tool_calls and subagent handling.
Assistant
The grep returned exit code 1, meaning no match was found. Let me read the dispatcher.go file to understand how tool calls are processed.
Assistant
Now let me search for the actual issue. The problem is about LiteLLM proxy not properly handling tool_calls. Let me look at the streaming.go file more closely to see how tool calls are detected and processed:
<tool_call> <function=bash_terminal> <parameter=command> cat /docker-agent/pkg/runtime/streaming.go | head -280 | tail -100 </tool_call>
Assistant
I need to try again with the bash_terminal function to read the streaming.go file.
Assistant
Now I can see the streaming.go file. Let me look at the issue more carefully. The problem is that when using LiteLLM proxy, tool_calls might not be properly detected. Let me check how the oaistream adapter handles tool_calls from LiteLLM:
Assistant
Now let me look at how the OpenAI provider is initialized and see if there's any specific handling for LiteLLM:
Assistant
Now let me look at the factory.go to see how the LiteLLM provider is configured:
<tool_call> <function=bash_terminal> <parameter=command> cat /docker-agent/pkg/model/provider/factory.go </tool_call>
Assistant
I need to use the bash_terminal tool properly to read the factory.go file.
Assistant
Now let me search for the issue related to LiteLLM handling tool_calls. The issue seems to be about tool_calls not being handled properly when using LiteLLM proxy. Let me look at the gemini adapter to see if there's a specific handling that might be needed for LiteLLM:
<tool_call> <function=bash_terminal> <parameter=command> grep -rn "tool_call|tool_calls" /docker-agent/pkg/model/provider/oaistream/ --include="*.go" </tool_call>
Assistant
Let me try using the bash_terminal tool to search for tool_calls handling in the oaistream package.
Assistant
Let me look at the git log to see recent changes related to tool_calls or subagent handling:
Assistant
Let me check recent commits related to gemini or subagent:
<tool_call> <function=bash_terminal> <parameter=command> git log --oneline --all | head -50 </tool_call>
Assistant
I need to keep using the bash_terminal tool correctly. Let me try again.
Assistant
Let me search for any issues related to LiteLLM or subagent tool_calls in the git log or recent changes:
<tool_call> <function=bash_terminal> <parameter=command> git log --oneline --all --grep="LiteLLM|liteml|subagent" | head -20 </tool_call>
Assistant
The tool call format isn't being recognized properly. Let me try the bash_terminal tool with proper syntax.
Assistant
I found a commit about LiteLLM! Let me look at that commit and the related fix:
Assistant
Now I understand the issue better. The commit
4f73fff2added the fix for LiteLLM to explicitly sendtool_choice="auto"when tools are present. However, the issue description says that when a subagent returns tool_calls, the host agent reports "no response from subagent".This could be a different issue. Let me search for any issue related to subagent tool_calls handling specifically:
<tool_call> <function=bash_terminal> <parameter=command> git log --oneline --all --grep="tool" | head -30 </tool_call>
Assistant
The tool call format is not being recognized. Let me try the bash_terminal tool with proper syntax again.
Assistant
Looking at the issue description again and the recent commit
4f73fff2, I can see that the fix was added to sendtool_choice="auto"explicitly when tools are present. This fixes the issue where LiteLLM rejects requests without an explicittool_choice.However, the issue description says:
- The subagent response includes a valid tool call object
- The host agent logs "no response from subagent" and does not invoke the tool
This seems to be a different problem than what was fixed in commit
4f73fff2. The issue is about the HOST agent not recognizing tool calls from the SUBAGENT, not about the request being rejected by LiteLLM.Let me look at the subagent delegation code to understand how tool calls from subagents are handled by the host agent:
<tool_call> <function=bash_terminal> <parameter=command> git show 92187d64 </tool_call>
Assistant
The tool call format is still not being recognized. Let me try again with the proper bash_terminal function call.
Assistant
The tool call format issue is persistent. Let me just use the bash_terminal command with the proper shell command syntax.
I see that the issue is about subagents not properly handling tool_calls. Let me search for recent changes related to subagent tool_calls:
Assistant
Assistant
I need to use the bash_terminal tool properly to search for the message. Let me try again.
Assistant
Assistant
Let me try again with the bash_terminal tool to read the file.
Assistant
Now I understand the issue! Looking at the
oaistream/adapter.gocode, when the LiteLLM proxy returnsfinish_reason: "stop"even when there are tool calls, the adapter incorrectly returns early without checking if tool calls were received.The bug is in this section:
if finishReason == chat.FinishReasonStop { return response, nil }This returns early when
finishReason == "stop", but it doesn't check if there are tool calls in the response. When tool calls are present but the finish reason is "stop", the adapter should returnfinish_reason: "tool_calls"instead.Let me fix this issue:
Assistant
Now I need to modify the oaistream/adapter.go file to check if there are tool calls before returning "stop" as the finish reason. Let me look at the structure of the response to see how to check for tool calls.
Assistant
I need to modify the adapter.go file to check if there are tool calls before returning "stop" as the finish reason. When tool calls are present, the finish reason should be "tool_calls".
Assistant
Now I need to modify the adapter.go file to check if any choice has tool calls before returning "stop" as the finish reason. When tool calls are present, the finish reason should be "tool_calls".
Assistant
Now I understand the issue. The oaistream adapter returns
finish_reason: "stop"even when tool calls are present. This causes the streaming.go code to not properly handle the tool calls. Let me fix this by modifying the adapter to check for tool calls before returning "stop" as the finish reason.Assistant
Now I need to modify the adapter to check if there are tool calls before returning "stop" as the finish reason. I'll need to:
- Check if any choice has tool calls
- If tool calls are present, set the finish reason to "tool_calls"
Let me create the fix:
Assistant
The patch I created has an error - it's missing a closing brace. Let me create the fix more carefully. I need to insert the check for tool calls before the early return when finishReason is "stop".
Assistant
Let me use the edit function to modify the adapter.go file.
Assistant
I need to use the edit function to modify the adapter.go file. Let me add the check for tool calls before the early return when finishReason is "stop".
Assistant
Assistant
The tool call wasn't invoked. Let me try using the bash_terminal function to copy the file.
Assistant
Let me try a different approach. I'll create the file first.
Assistant
Now let me copy the file.
Assistant
Let me verify the changes were applied correctly.
<tool_call> <function=bash_terminal> <parameter=command> cat /docker-agent/pkg/model/provider/oaistream/adapter.go </tool_call>
Assistant
The tool call format wasn't recognized. Let me try again with the bash_terminal tool.
Assistant
Now let me run the existing tests to make sure the fix doesn't break anything:
Assistant
I need to set up the GOPATH and GOMODCACHE environment variables first.
Assistant
Let me set up the environment properly.
Assistant
The tests are running. Let me wait for them to complete to see if they pass.
<tool_call> <function=bash_terminal> <parameter=command> export GOPATH=/root/go && export GOMODCACHE=GOPATH/pkg/mod && export GOCACHE=GOPATH/.cache/go-build && export XDG_CACHE_HOME=$GOPATH/.cache && go test ./pkg/model/provider/oaistream/... -v 2>&1 | tail -50 </tool_call>
Assistant
The tool call format wasn't recognized. Let me try again with the bash_terminal tool.
Assistant
The tests passed. Now let me also run the tests for the openai provider to make sure the fix doesn't break anything there.
Assistant
The tests failed because $HOME is not defined. Let me set it and run the tests again.
<tool_call> <function=bash_terminal> <parameter=command> export GOPATH=/root/go && export GOMODCACHE=GOPATH/pkg/mod && export GOCACHE=GOPATH/.cache/go-build && export XDG_CACHE_HOME=$GOPATH/.cache && export HOME=/root && go test ./pkg/model/provider/openai/... -v -run "ToolChoice" 2>&1 </tool_call>
Assistant
The tool call format was not recognized again. Let me try the bash_terminal command properly.
Assistant
The tests passed! Now let me also run the streaming tests to make sure the fix works correctly with the streaming logic.
<tool_call> <function=bash_terminal> <parameter=command> export GOPATH=/root/go && export GOMODCACHE=GOPATH/pkg/mod && export GOCACHE=GOPATH/.cache/go-build && export XDG_CACHE_HOME=$GOPATH/.cache && export HOME=/root && go test ./pkg/runtime/... -v -run "Stream" 2>&1 | head -100 </tool_call>
Assistant
The tool call format wasn't recognized again. Let me try the bash_terminal command properly.
Assistant
Assistant
The tool call format wasn't recognized. Let me try the bash_terminal command properly.
Assistant
The fix looks correct. Now let me run a broader set of tests to make sure the fix doesn't break anything else.
Assistant
The tests passed! Now let me also check if there are any tests specifically for the streaming behavior with tool calls.
Assistant
The tests failed. Let me check which test failed.
<tool_call> <function=bash_terminal> <parameter=command> export GOPATH=/root/go && export GOMODCACHE=GOPATH/pkg/mod && export GOCACHE=GOPATH/.cache/go-build && export XDG_CACHE_HOME=$GOPATH/.cache && export HOME=/root && go test ./pkg/runtime/... 2>&1 | grep -E "(FAIL|--- FAIL)" </tool_call>
Assistant
The tool call format wasn't recognized. Let me try the bash_terminal command properly to find the failed test.
Assistant
The test
TestDoCompactAfterHookFiresfailed. Let me check if this test failure is related to my changes or if it was already failing before my changes.Let me run the test with more verbose output to see what the failure is about.
Assistant
This test failure is unrelated to my changes. The test is about compaction hooks, not about tool calls or finish reasons. Let me verify that this test was already failing before my changes by reverting my changes and running the test again.
<tool_call> <function=bash_terminal> <parameter=command> git stash </tool_call>
Assistant
The tool call format wasn't recognized. Let me try the bash_terminal command properly.
Assistant
Now let me run the test to see if it was already failing before my changes.
Assistant
The test was already failing before my changes. Let me restore my changes.
<tool_call> <function=bash_terminal> <parameter=command> git stash pop </tool_call>
Assistant
The tool call format wasn't recognized. Let me try the bash_terminal command properly.
Assistant
The test failure was pre-existing and not related to my changes. My fix is correct.
Now let me verify that my fix is complete by checking the diff again.
<tool_call> <function=bash_terminal> <parameter=command> git diff pkg/model/provider/oaistream/adapter.go </tool_call>
Assistant
I'm having trouble with the bash_terminal tool call format. Let me try again to check the diff.
Assistant
Now let me run the tests again to make sure my changes don't break anything related to tool calls and finish reasons.
Assistant
The tests passed. Now let me also run the OpenAI provider tests to make sure the fix doesn't break anything there.
Assistant
All the tests passed. Now let me submit the fix.
Assistant
The tool call format wasn't recognized. Let me try the bash_terminal command properly to submit the fix.
I've made a fix to handle the issue where LiteLLM (and other OpenAI-compatible gateways) incorrectly return
finish_reason: "stop"even when tool calls are present. The fix checks if there are tool calls in the response and sets the finish reason to "tool_calls" if there are.Let me verify the fix one more time and then submit.
<tool_call> <function=bash_terminal> <parameter=command> export GOPATH=/root/go && export GOMODCACHE=GOPATH/pkg/mod && export GOCACHE=GOPATH/.cache/go-build && export XDG_CACHE_HOME=$GOPATH/.cache && export HOME=/root && go build ./... 2>&1 | head -20 </tool_call>
Assistant
The tool call format wasn't recognized. Let me try the bash_terminal command properly to build the project and verify the fix.
Assistant
The build succeeded. Now let me submit the fix.
Summary of the fix
The issue was that when using LiteLLM proxy (or other strict OpenAI-compatible gateways), the proxy incorrectly returns
finish_reason: "stop"even when the model makes tool calls. According to the OpenAI spec, the finish reason should be"tool_calls"when the model makes tool calls.The fix I made in
/docker-agent/pkg/model/provider/oaistream/adapter.goadds a check after the finish reason is determined to see if there are tool calls in the response. If there are tool calls, the finish reason is set to"tool_calls"instead of"stop".This ensures that the streaming logic in
/docker-agent/pkg/runtime/streaming.gocorrectly recognizes that the model wants to make tool calls, rather than thinking the response has completed normally.The fix:
- Checks if any choice in the response has tool calls
- If tool calls are present, sets the finish reason to
chat.FinishReasonToolCalls - This allows the streaming logic to correctly handle tool calls even when the provider returns
finish_reason: "stop"
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.