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
I'll start by exploring the repository structure to understand the codebase and then find the relevant code handling subagent tool calls.
Assistant
This is a Go repository. Let me explore the structure more deeply.
Assistant
Let me look at the subagent-related code. Let me search more broadly.
Assistant
Let me look at how subagents are invoked. Let me find the subagent tool definition.
Assistant
Let me look at the agent_delegation.go file, specifically the
runCollectingfunction:Assistant
Now let me look at
GetLastAssistantMessageContentto understand what it returns, especially when the last assistant message has tool_calls:Assistant
Now I understand the core.
GetLastAssistantMessageContentreturns only the text content. When the subagent's last message hastool_callsbut empty content, it returns "". Let me look at how the agent processes tool calls and finish reasons.Assistant
Let me look at the sampling/stream processing to understand how tool calls are extracted from the stream:
Assistant
Let me look at how the stream is processed in the loop - the
fallback.executeand howres.Callsgets populated. Let me look at the fallback execution:Assistant
Assistant
The streaming.go already handles finish_reason "stop" with tool calls. Let me look at the OpenAI provider stream parsing, since LiteLLM is OpenAI-compatible. Let me find the chat package and provider:
Assistant
Now let me look at the OpenAI provider's stream parsing - how SSE chunks become
MessageStreamResponse:Assistant
This is the "Responses API" adapter. Let me look at how the OpenAI client selects the stream type (Chat Completions vs Responses API):
Assistant
Let me look at the oaistream package which handles the Chat Completions stream parsing:
Assistant
I found a critical issue in the streaming flow. Let me examine the order of operations in
handleStream. Let me re-read the key section carefully:Assistant
I've confirmed the bug. The finish reason check (line 132) happens BEFORE the tool call processing (line 159). If a single chunk contains BOTH
finish_reason: "stop"ANDdelta.tool_calls(which is what LiteLLM proxy does), the tool calls are never accumulated. Let me look at the existing tests to understand the test infrastructure and write a reproduction:Assistant
Let me find a mock stream implementation to use for a reproduction test:
Assistant
Now let me find a test that calls
handleStreamdirectly:Assistant
Let me check the Telemetry interface and session creation for writing a reproduction test:
Assistant
Let me look at a test that exercises tool calls through the full runtime to understand the expected behavior:
Assistant
Now let me write a reproduction test. The
TestToolCallSequenceputs tool calls and stop in SEPARATE chunks. The LiteLLM scenario puts them in the SAME chunk. Let me create a temp test file:Assistant
Now let me create a reproduction test file:
Assistant
I need to fix the imports - I used context and time without importing. Let me fix the test file.
Assistant
I've reproduced the bug:
Calls=0 Stopped=true FinishReason=stop— the tool call is lost. Now let me implement the fix. The tool call deltas must be processed BEFORE the finish-reason early-return check. Let me view the exact lines to edit:Assistant
Now I'll restructure the loop to process tool call deltas before the finish-reason early-return check. Let me replace lines 132-212:
Assistant
Let me verify the replacement file uses tabs (not spaces) for proper indentation:
Assistant
The replacement uses tabs. Now let me apply the edit replacing lines 132-212:
Assistant
The edit looks good. Now let me build and run my reproduction test:
Assistant
The fix works:
Calls=1 Stopped=false FinishReason=tool_calls. Now let me run the full runtime test suite to make sure I didn't break anything:Assistant
There are test failures. Let me see which tests fail:
Assistant
Let me check if this test failure is pre-existing (not caused by my change). Let me stash my changes and run it:
Assistant
The
TestDoCompactAfterHookFiresfailure is pre-existing — it fails without my change too. So my change doesn't break it. Let me confirm only that one test fails in the runtime package, and run related tests:Assistant
Only the pre-existing failure. Now let me run related test packages (oaistream, openai provider, agent delegation, chat, session):
Assistant
The
TestNewSQLiteSessionStore_DirectoryNotWritablefailure is environmental (running as root). Let me verify the specific packages that matter for my change passed:Assistant
Let me confirm the session test failure is pre-existing/environmental (running as root):
Assistant
Both pre-existing failures are environmental (running as root) and fail without my change. My fix doesn't introduce any new failures.
Now let me trace why this manifests as "no response from subagent" — let me check
recordAssistantMessageto confirm the tool calls would be recorded:Assistant
The root cause is confirmed. Let me trace the real-world path through the
oaistreamadapter to confirm it produces a chunk with bothfinish_reason: "stop"AND tool call delta (with defaulttrackUsage=true). Let me look at the adapter test:Assistant
Let me write a temporary test in the oaistream package to confirm the adapter produces a chunk with both
finish_reason: "stop"AND the tool call (the real LiteLLM path with defaulttrackUsage=true):Assistant
This confirms the real-world path: with default
trackUsage=true, when LiteLLM sends the complete tool call +finish_reason: "stop"+ usage in a single SSE chunk, the adapter produces a chunk with BOTHfinish_reason: "stop"AND the tool call delta. MyhandleStreamfix now processes the tool call delta first.Let me run the streaming/tool-call related runtime tests to confirm everything passes:
Assistant
All relevant tests pass. Let me verify edge cases — multiple tool calls + stop in same chunk, and the normal
tool_callsfinish reason path still works:Assistant
There's a syntax error in repro2_test.go at line 66. The issue is likely with the nested composite literal. Let me look at line 66.
Line 66 is in
TestReproSplitArgsWithStopOnLastDelta. The issue is probably the deeply nested composite literal wherechat.MessageDelta{ToolCalls: []tools.ToolCall{{...}}}is ambiguous. Let me check.Actually the problem is probably that
chat.MessageStreamChoice{{Index: 0, FinishReason: ..., Delta: ...}}— no wait. Let me look at the exact line.Line 66 corresponds to the third response in TestReproSplitArgsWithStopOnLastDelta. Let me count. Actually the issue might be the
[]tools.ToolCall{{ID: "c1", Type: "function", Function: tools.FunctionCall{Arguments:{"q":"}}}}— the backtick string contains{"q":"which is fine. But the nested literalchat.MessageStreamChoice{{...}}— wait,chat.MessageStreamChoiceis a struct, not a slice. Let me check:Choices: []chat.MessageStreamChoice{{Index: 0, ...}}— that's a slice with one element. The element is{Index: 0, FinishReason: ..., Delta: chat.MessageDelta{ToolCalls: []tools.ToolCall{{ID:...}}}}.Hmm. The composite literal nesting should be fine. Let me look at the actual error line 66.
Assistant
The deeply nested single-line composite literals are error-prone. Let me rewrite the test using clearer construction:
Assistant
Line 68 in the new file. Let me look at it.
Assistant
The inline nested literals have brace-counting errors. Let me rewrite using clearer variable construction to avoid brace miscounting:
Assistant
All edge cases pass. Now let me clean up the temporary test files (I must not add tests to the repo):
Assistant
Now let me review the final diff and confirm the change is clean:
Assistant
The diff is clean. Let me run the build, vet, and the full runtime test suite once more to confirm everything is good:
Assistant
Only the pre-existing
TestDoCompactAfterHookFiresfailure remains (which fails without my change too). Let me run the related provider tests once more to confirm:Assistant
All relevant tests pass. Let me do a final review of the complete modified section to ensure coherence:
Assistant
The change is clean and coherent. Let me confirm there are no leftover temporary files:
Assistant
Only the intended change to
pkg/runtime/streaming.goremains — no temporary files left behind.Let me do a final build/vet check across the repo to besafe:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.