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
Let me start by understanding the repository structure and the issue. The issue is about subagent tool_calls not being handled when using LiteLLM proxy. Let me explore the repository first.
The repository seems to be "cagent" (or "cagent" could be "cagent" - the C implementation of an AI agent). Let me explore the structure.
Actually, looking at the issue description more carefully:
- cagent: v1.19.7
- The subagent returns a valid tool_calls response but the host agent reports "no response from subagent"
Let me explore the repository structure first.
Assistant
This is a Go project. Let me explore the structure more. The issue mentions "subagent" and "tool_calls". Let me search for relevant code.
Assistant
I need to make only one tool call at a time. Let me search for "no response from subagent" first.
Assistant
Let me try broader searches - case-insensitive and partial matches
Assistant
Let me search for "subagent" related code:
Assistant
Let me search for the exact error message or similar messages:
Assistant
Let me look at the agent_delegation.go file - this seems central to the issue
Assistant
Now let me look at the session package, particularly
GetLastAssistantMessageContentAssistant
Let me look at the
GetLastAssistantMessageContentfunction and the flow around it. Also, the issue mentions tool_calls and the "no response from subagent" message. Let me also look at how tool calls are handled in the session loop.Assistant
Let me see the
getLastMessageContentByRolefunction.Assistant
Let me see the full function.
Assistant
Let me search for "no response from subagent" more broadly - it might be constructed dynamically.
Assistant
Let me look at the
RunStreamfunction and how tool calls flow.Assistant
Let me look at the loop.go to understand how RunStream handles tool calls and end conditions
Assistant
Let me see the full runStreamLoop function - the middle part was truncated
Assistant
Let me look at the builtin agent tool package - this is where "run_agent" or similar tool is defined
Assistant
Let me look at how the stream processing handles finish_reason and tool_calls
Assistant
Let me look at the OpenAI stream adapter
Assistant
Let me look at how the loop processes tool calls and handles finish_reason
Assistant
Let me find the
runTurnfunctionAssistant
Let me look at the runTurn function.
Assistant
Let me look at how
streamResultandStoppedare determined in the model streamingAssistant
Let me look at the streaming.go file to understand how
Stoppedis determinedAssistant
Let me look at the OpenAI response handler for non-streaming responses
Assistant
Let me search for where the result of a subagent is processed and where "no response" would be generated
Assistant
Let me look at the
transfertasktoolAssistant
Let me find the file.
Assistant
Let me look at the transfertask.go file.
Assistant
Let me look at how the model call is made and how the response is parsed
Assistant
Let me look at the OpenAI client's
CreateChatCompletionStreamfunctionAssistant
Let me look at the fallback.go to understand the model call flow
Assistant
Let me look at the non-streaming chat completion path
Assistant
Let me search for non-streaming completion
Assistant
Let me look at lines around 940 in client.go for the non-streaming path
Assistant
Let me look at the
trackUsagevariable and how it's setAssistant
Let me search for where "no response" message is generated more broadly
Assistant
Let me search for "no response" in all files including non-Go files
Assistant
Let me look at the non-streaming chat completion path in the OpenAI client
Assistant
Let me look at the
processToolCallsfunctionAssistant
Let me look at the tool_dispatch.go file
Assistant
Let me look at the toolexec dispatcher
Assistant
Let me look at the git log for recent changes related to this issue
Assistant
Let me look at the oaistream adapter test to understand the expected behavior
Assistant
Let me look at the SSE comment test
Assistant
Let me check the git log for changes to the oaistream adapter and handleStream
Assistant
Let me look at the commit "fallback on stream end
Assistant
Let me look at the diff for this commit
Assistant
Let me check the recent commit about message merging in oaistream
Assistant
Let me look at the chat.FinishReason type definition
Assistant
Let me search for any LiteLLM-related code or comments
Assistant
Let me look at the tool_choice code around line 286 in client.go
Assistant
Let me look at the tests for handleStream
Assistant
Let me try a different approach. Let me look at the
handleStreamfunction more carefully and see if there's a case where tool calls are not accumulated whentrackUsageis true.Let me look at the full
handleStreamfunction one more time, focusing on the interaction betweentrackUsage, the early return, and the EOF path.Assistant
Now I think I understand the issue. Let me trace through a specific scenario:
When LiteLLM returns a response with tool_calls AND
finish_reason: "stop"AND usage data in a single chunk, the adapter:- Extracts tool calls from the delta
- Clears the "stop" finish_reason (because
trackUsageis true) - Then the usage block sets
FinishReason: "stop"on the choice
In
handleStream, theFinishReason: "stop"triggers the early return BEFORE the tool calls inchoice.Delta.ToolCallsare processed. The accumulatedtoolCallsis empty, soStoppedistrue, and the loop exits without executing the tool calls.Let me verify this theory by looking at the code flow more carefully:
Assistant
Now I can see the bug clearly. In
handleStream, the early return check forFinishReason: "stop"happens BEFORE the tool call processing. When LiteLLM (or any provider) sends a chunk with both tool calls in the delta ANDfinish_reason: "stop"(or when the adapter's usage chunk setsFinishReason: "stop"on a choice that still has tool calls), the tool calls are never accumulated into thetoolCallsslice. The early return then seeslen(toolCalls) == 0and setsStopped: true, causing the loop to exit without executing the tool calls.The fix is to process tool calls in the delta BEFORE checking the finish reason. Let me implement this:
Assistant
Let me use the special open command to view the file
Assistant
Now I can see the issue. The tool call processing (lines 158-212) happens AFTER the finish reason check (lines 132-149). When a chunk has both tool calls in the delta AND
finish_reason: "stop"(which can happen with LiteLLM or when the adapter's usage chunk sets the finish reason on a choice that still has tool calls), the early return is triggered before the tool calls are processed, causinglen(toolCalls)to be 0 andStoppedto betrue.The fix is to move the tool call processing BEFORE the finish reason check. Let me implement this:
Assistant
I need to use the
<< 'EOF'syntax for multi-line edits. Let me try again:Assistant
Good, the edit looks correct. Now let me verify it compiles and the tests pass:
Assistant
Let me check the Go
Assistant
Let me set up the Go environment and try building
Assistant
Let me set up the Go environment properly
Assistant
The code compiles. Now let me run the tests for the runtime package:
Assistant
Good, the tests pass. Let me run the full test suite for the runtime package:
Assistant
There's a test failure. Let me check which tests failed
Assistant
Let me get the test results summary more specifically
Assistant
Let me check if the test failure is pre-existing by reverting my change temporarily and running the test
Assistant
Good, the test failure is pre-existing and not caused by my change. Let me restore my changes:
Assistant
Good. The pre-existing test failure is not related to my change. Let me verify the final state of my changes
Assistant
The diff looks correct. Let me also run the oaistream tests to make sure nothing is broken there:
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 →
- 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 →