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 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 exploring the repository structure to understand the codebase.
Assistant
This is a Go repository. Let me search for "no response from subagent" to find the relevant code.
Assistant
Let me search for "no response" more broadly, perhaps in case it's worded differently.
Assistant
Let me look for subagent tool handling code.
Assistant
Let me look at the agent delegation code and how subagent responses are processed.
Assistant
Now let me look at the GetLastAssistantMessageContent function in session.go, which is the key function that returns the subagent's response. The issue is that the subagent returns tool_calls but the host agent reports "no response from subagent". This suggests
GetLastAssistantMessageContentreturns empty content when the last assistant message contains tool_calls instead of content.Let me look at session.go.
Assistant
Found it. The
getLastMessageContentByRolefunction returns only the content of the last assistant message, ignoring tool calls. Let me see the full function.Assistant
Let me look at the chat package to understand how streaming messages and tool calls are processed.
Assistant
Now let me look at the runtime loop that processes model streaming responses and tool calls. Let me find the main run loop.
Assistant
Let me look at the stream processing and recordAssistantMessage, processToolCalls functions.
Assistant
Let me look at the stream processing into streamResult, particularly how
StoppedandCallsare set.Assistant
Let me look at the loop logic around
Stoppedand how the loop decides to continue or exit.Assistant
Let me look at the OpenAI provider's stream parsing for tool calls.
Assistant
Let me look at the response_stream.go which seems to handle the new "responses" API and the event_stream.go. But wait, the issue is about LiteLLM proxy as an OpenAI-compatible API. Let me look at the response_stream.go around lines 240-270, where it sets the finish reason.
Assistant
That's the "responses" API. LiteLLM uses the chat completions API. Let me look at event_stream.go which handles the chat completions SSE stream.
Assistant
Let me look at how the chat completions stream is created in client.go.
Assistant
Let me look at the StreamAdapter Recv function fully.
Assistant
Let me look at
processToolCallsto understand when tool calls are not processed.Assistant
Let me look at existing tests for getLastMessageContentByRole / GetLastAssistantMessageContent to understand expected behavior.
Assistant
Let me check the git log for recent changes to relevant files.
Assistant
Let me look at loop_steps.go for max-iterations and non-interactive handling.
Assistant
Let me look at the existing tests for handleStream / streaming to understand the test setup.
Assistant
Let me look at TestToolCallSequence and the runSession helper fully.
Assistant
I believe I've found the bug. In
handleStream, the early-return check forFinishReasonStop/FinishReasonLengthhappens BEFORE processing the tool call deltas in the same chunk. If a provider (like LiteLLM) sends tool calls in the same chunk as the finish_reason, those tool calls are dropped.Let me write a reproduction test to confirm.
Assistant
Let me simplify the reproduction test using existing helpers.
Assistant
GOMODCACHE and GOPATH are empty. Let me set them explicitly.
Assistant
I've reproduced the bug. The early-return on
FinishReasonStopfires before processing tool call deltas in the same chunk. Let me view the exact code structure to design a clean fix.Assistant
Now I understand the full structure. The fix: move the delta processing (tool calls, reasoning, content) BEFORE the finish-reason early-return check. But the tool call processing block ends with
continue, which would skip the finish-reason check. So I need to remove thatcontinueand instead, after processing tool calls, fall through to the finish-reason check.Let me restructure. The cleanest approach: extract the finish-reason early-return to AFTER all the delta processing. So:
choice := response.Choices[0] if len(choice.Delta.ThoughtSignature) > 0 { thoughtSignature = choice.Delta.ThoughtSignature } // Handle tool calls if len(choice.Delta.ToolCalls) > 0 { // process tool calls (remove the `continue`) } // reasoning if choice.Delta.ReasoningContent != "" { ... } // thinking signature if choice.Delta.ThinkingSignature != "" { thinkingSignature = ... } // content if choice.Delta.Content != "" { ... } // Now check finish reason for early return (after processing the delta, // so tool calls/content in the same chunk as finish_reason are captured) if choice.FinishReason == chat.FinishReasonStop || choice.FinishReason == chat.FinishReasonLength { recordUsage() applyXMLFallback() finishReason := choice.FinishReason if finishReason == chat.FinishReasonStop && len(toolCalls) > 0 { finishReason = chat.FinishReasonToolCalls } return streamResult{...}, nil } // Track the provider's explicit finish reason (e.g. tool_calls) if choice.FinishReason != "" { providerFinishReason = choice.FinishReason }Wait, but the
providerFinishReasontracking is currently AFTER the early-return. If I move the early-return to after delta processing, I need to keepproviderFinishReasontracking after the early-return. That's fine.But there's a subtle issue: the original code tracks
providerFinishReasonfor non-stop/length finish reasons (like "tool_calls"). With my restructure, the early-return handles stop/length. For "tool_calls" finish reason, the early-return doesn't fire, and we trackproviderFinishReason = "tool_calls". Good, that's preserved.However, there's a concern about the
continueafter tool calls. Currently, when a chunk has tool calls, it processes them andcontinues (skipping reasoning/content). If I remove thecontinueand there's no finish reason, it falls through to reasoning/content processing (which are empty) and then to the finish-reason check (no early return) and providerFinishReason tracking. That's fine.But if a chunk has tool calls AND a finish reason "stop", removing the
continuemeans after processing tool calls, it falls through to reasoning/content (empty), then hits the early-return.Now, there's another concern: the order of the early-return check vs the
providerFinishReasontracking. In the original, for stop/length, the early-return fires andproviderFinishReasonis NOT updated (which is fine, since stop/length are handled by early return). For "tool_calls",providerFinishReasonis set. With my restructure, same behavior.Let me now also consider: what about content being processed before the early-return when finish_reason is "stop"? Currently content in the same chunk as stop is dropped. With my fix, it's captured. Let me check if any test would break. Actually, let me reconsider — is it possible a provider sends content AND finish_reason "stop" in the same chunk where the content should NOT be captured? No, content should always be captured. So this is a strict improvement.
But wait, I want to be careful about the
xmlToolCallGate. If content with `Assistant
Now let me apply the fix. First, I'll remove the early-return block and the
providerFinishReasontracking from their current position (they'll be re-added after delta processing).Assistant
Now I need to remove the
continueat line 186 so that tool call processing falls through to the finish-reason check. Let me also add a clarifying comment.Assistant
My edit accidentally removed the
if len(choice.Delta.ToolCalls) > 0 {line. Let me fix that.Assistant
Now remove the
continueat line 191 so tool calls fall through to the finish-reason check.Assistant
Now add the early-return block +
providerFinishReasontracking after the content block (before the loop's closing brace).Assistant
Now let me build and run my reproduction test.
Assistant
The reproduction test passes now. Let me run the full runtime test suite to ensure I didn't break anything.
Assistant
Let me find which test(s) failed.
Assistant
Let me look at the TestDoCompactAfterHookFires test to understand what changed.
Assistant
Let me check whether this test was already failing before my change by stashing.
Assistant
The test
TestDoCompactAfterHookFireswas already failing before my change — it's a pre-existing failure (likelyjqnot installed in this environment). My change didn't break it. Let me confirm.Assistant
jqis not installed — that's a pre-existing environment issue unrelated to my change. Let me run the full runtime test suite excluding the jq-dependent test to confirm everything else passes.Assistant
All runtime tests pass. Let me also run the oaistream tests since they're related to the streaming adapter.
Assistant
Let me make my reproduction test more thorough, covering edge cases. Let me first look at how tests register tools and verify tool execution.
Assistant
Let me look at how tests register tool handlers that get executed end-to-end.
Assistant
Let me look at the contract_test.go for end-to-end tool execution test patterns.
Assistant
Let me look at the harness_test.go which tests end-to-end tool execution with a registered tool handler.
Assistant
Let me look at the
queueProviderwhich returns multiple streams, useful for end-to-end tests.Assistant
Let me look at how tests add toolsets/tools to agents and register handlers.
Assistant
Let me look at how
registerDefaultToolsregisters handlers and how custom tool handlers map to tool names. Let me find the registration logic.Assistant
Let me look at the toolexec.Dispatcher.Process to understand how handlers are resolved for execution.
Assistant
Let me check how
availableis determined for a tool call.Assistant
Let me look at how the runtime gathers the agent's tools (getTools) to set up an end-to-end test.
Assistant
So
a.Tools(ctx)returns the agent's tools. Let me look at the agent's Tools method.Assistant
Now let me write a comprehensive end-to-end reproduction test that registers a tool handler and verifies the tool gets executed when the tool call arrives in the same chunk as
finish_reason: "stop".Assistant
Both tests pass. Let me verify that without my fix, the end-to-end test actually catches the bug (to confirm the test is meaningful).
Assistant
Both tests fail without the fix and pass with it — confirming the fix is meaningful. Now let me also check the Responses API path (response_stream.go) to ensure it doesn't have a similar bug.
Assistant
The Responses API emits tool calls as separate deltas from the finish_reason, so it's not affected. Let me run the broader test suite and build the whole project to ensure nothing is broken.
Assistant
A session test failed. Let me check if it's related to my change or pre-existing.
Assistant
Both pre-existing failures are environment issues (missing
jq, tests running as root) unrelated to my change. Now let me remove my temporary reproduction test file since I should not add new tests to the repository.Assistant
Let me re-run the runtime tests to confirm everything still passes after removing the repro test.
Assistant
Now let me review the final diff of my change to make sure it's clean and correct.
Assistant
The diff looks clean. Let me review the full updated loop once more to ensure the logic is sound.
Assistant
The logic is sound. Let me reconsider edge cases:
-
A chunk with tool calls + finish_reason "stop" (the bug case): tool calls processed → finish check fires → returns with toolCalls populated, Stopped=false, finishReason=tool_calls. ✓ FIXED.
-
A chunk with tool calls only (no finish reason): tool calls processed → finish check (no match) → providerFinishReason tracking (empty) → loop continues. ✓ Same as before.
-
A chunk with tool calls + finish_reason "tool_calls": tool calls processed → finish check (tool_calls isn't stop/length, no match) → providerFinishReason = "tool_calls" → loop continues. ✓ Same as before (in the original, providerFinishReason was tracked BEFORE the tool call block, so it was also set; same result).
-
A chunk with content + finish_reason "stop": content processed → finish check fires → returns with content. ✓ (improvement — previously content in same chunk as stop was dropped).
-
A chunk with content + finish_reason "stop" + usage (trackUsage): the StreamAdapter would set FinishReason based on lastFinishReason... but that's the adapter's job. The handleStream just sees whatever FinishReason the adapter provides. ✓
-
A chunk with ONLY finish_reason "stop" (no delta): nothing processed → finish check fires → returns. ✓ Same as before.
-
A chunk with reasoning + finish_reason "stop": reasoning processed → finish check fires. ✓ (improvement).
-
A chunk with thoughtSignature + finish_reason: thoughtSignature was already captured before (unchanged). ✓
One concern: the
xmlToolCallGateinteraction. If content with `-
Assistant
All pass. Let me do a final full build and vet to ensure no compile issues across the project.
Assistant
Everything builds and vets cleanly. Let me do a final check of git status to ensure only the intended change is present (no leftover repro test).
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
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →