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 uses to get the changes that need to be submitted. Assistant
Let me start by understanding the repository structure and the issue. The issue is about subagent
tool_callsnot being handled when using a LiteLLM proxy. The host agent reports "no response from subagent" even though the subagent response contains validtool_calls.Let me explore the repository structure first.
Assistant
Let me search for the "no response from subagent" message and understand the code flow
Assistant
No results. Let me search more broadly.
Assistant
Let me search for "subagent" in the codebase.
Assistant
Let me look at the key files related to subagent handling
Assistant
Let me see the rest of this file, particularly the parts that handle subagent responses.
Assistant
Let me continue scrolling down to find the response handling code.
Assistant
Let me continue scrolling to see the rest of the runForwarding function
Assistant
Let me search for "no response" in a broader way - maybe it's constructed dynamically.
Assistant
Let me search for "response" and "subagent" together.
Assistant
Let me search in the tools directory for agent-related tool handling
Assistant
Let me search for "no response" across all Go files.
Assistant
Let me look at the session package to find
GetLastAssistantMessageContent.Assistant
Found it! Let me look at the MCP server code.
Assistant
Let me try again.
Assistant
Let me look at the agent tool handling in
pkg/tools/builtin/agent/Assistant
Let me look at the agent.go file for the tool handling.
Assistant
Let me look at
handleTaskTransferandhandleRunAgentfunctions.Assistant
Let me look at
handleTaskTransferin agent_delegation.goAssistant
Let me open agent_delegation.go at line 394.
Assistant
Now let me look at session.go to understand
GetLastAssistantMessageContent.Assistant
Let me search for "no response from" more broadly.
Assistant
Let me try a different grep approach.
Assistant
Strange, let me try a simpler grep.
Assistant
Let me try using a different approach to search.
Assistant
Let me look at both files for the "no response" text.
Assistant
Let me try more explicitly.
Assistant
Let me look at the a2a.go file around line 244.
Assistant
Let me search for "No response" case-insensitively.
Assistant
Let me look at the main loop to understand how tool calls are processed.
Assistant
Let me search for tool call handling in the loop.
Assistant
Let me look at the main loop processing logic, particularly around line 580.
Assistant
Let me look at the OpenAI provider client code for how finish_reason and tool_calls are handled.
Assistant
Let me search for "FinishReason" in the OpenAI client.
Assistant
Let me search for FinishReason across the codebase.
Assistant
Let me look at the streaming.go file to understand how finish_reason and tool calls are handled.
Assistant
Let me read the rest of streaming.go.
Assistant
Let me continue reading the rest of streaming.go.
Assistant
Let me see the final part.
Assistant
Let me look at the oaistream adapter which handles OpenAI-compatible streaming.
Assistant
Let me see the rest of the adapter.
Assistant
Let me look at how the OpenAI client creates the streaming adapter and whether trackUsage is true.
Assistant
Let me look at the newStreamAdapter function.
Assistant
Let me search in the oaistream package for newStreamAdapter.
Assistant
Let me look at the OpenAI adapter.go.
Assistant
Let me look at the OpenAI response_stream.go to see if there's a different handling path.
Assistant
Let me continue reading.
Assistant
Let me continue reading.
Assistant
Let me see the rest of the response_stream.go.
Assistant
Let me search more broadly for the error message.
Assistant
Let me look at how the model provider chooses between Chat Completions and Responses API.
Assistant
Let me look at lines 190-240 of the OpenAI client.
Assistant
Let me check which models auto-select the Responses API.
Assistant
Let me look at autoSelectsResponsesAPI.
Assistant
Let me look at the main loop in loop.go more fully to understand how
Stoppedaffects the flow.Assistant
Let me search for "no response from" in all files, including non-Go files.
Assistant
Let me try alternative approach.
Assistant
Let me check if there's a separate Gemini provider.
Assistant
Let me look at the agent tool and how it handles the subagent result.
Assistant
Let me look at the handler for
run_background_agent.Assistant
Let me look at the HandleRun function.
Assistant
Let me read the HandleRun function.
Assistant
Let me look at the git log for recent changes related to streaming, tool calls, or subagents.
Assistant
Let me look at the fix for "route Responses-only models on custom OpenAI providers".
Assistant
Let me look at SupportsResponsesAPI.
Assistant
Let me look at the defaults.go file to see how it handles custom providers.
Assistant
Let me look at mergeFromProviderConfig.
Assistant
Let me look at the handleStream function more carefully for the specific scenario where finish_reason is "stop" and there are tool calls in the same chunk.
Assistant
Now I understand the bug. Let me look at the
handleStreamfunction. The issue is that when a chunk has bothfinish_reason="stop"and tool calls in the delta, the early return at line 132 prevents the tool calls from that chunk from being processed (lines 159-211). The tool calls are lost because theFinishReasoncheck happens BEFORE theDelta.ToolCallsprocessing.Let me create a test to confirm this issue.
Assistant
Let me look at the existing tests for streaming.
Assistant
Let me search for streaming-related tests.
Assistant
Let me look at how mock streams are implemented.
Assistant
Now I've identified the bug. The issue is in
pkg/runtime/streaming.goin thehandleStreamfunction. When a stream chunk has bothFinishReason == "stop"ANDDelta.ToolCallswith tool calls, the early return at line 132 fires BEFORE the tool calls from that chunk are processed (lines 159-211). This causes the tool calls to be lost, andStoppedis set totrue(sincelen(toolCalls) == 0when no previous tool calls were accumulated).This happens when:
trackUsageisfalseand a chunk hasfinish_reason="stop"with tool calls.trackUsageistrue(default) and a chunk has both usage AND tool calls (the adapter synthesizes "stop" from emptylastFinishReasonand returns early).
The fix is to process the current chunk's tool calls BEFORE checking the finish reason for early return. Let me implement this.
Assistant
Now I'll implement the fix. I need to move the tool call processing (lines 158-211) before the early return check (lines 132-148). This ensures that when a chunk has both
finish_reason="stop"and tool calls, the tool calls are accumulated before checkinglen(toolCalls)for theStoppedcondition.Assistant
Let me try using the heredoc syntax for the edit command.
Assistant
Let me try a different approach. I'll write a script to make the change.
Assistant
Let me check the current state of the file.
Assistant
Let me see the rest of the file after the tool call processing.
Assistant
I see the problem - I lost the early return check for "stop"/"length" finish reason and the providerFinishReason tracking. I need to add them back after the tool call processing block. Let me fix this.
Assistant
Let me verify the file looks correct now.
Assistant
Let me verify the rest of the file.
Assistant
The code looks correct. Let me verify it compiles.
Assistant
Let me check the Go environment.
Assistant
Let me check the Go environment setup.
Assistant
Let me set up the Go module cache.
Assistant
Let me try building now.
Assistant
Let me set up all the Go environment variables.
Assistant
The code compiles. Now let me also check if there's a similar issue in
response_stream.gowhere theresponse.completedevent should include tool calls in its choice delta.Assistant
Let me also fix the
response.completedhandler to extract tool calls from the output, in case they weren't streamed as individual events. But first, let me check the structure of the output items.Assistant
Let me check the OpenAI responses library type for output items.
Assistant
Let me also fix the
response.completedhandler inresponse_stream.goto extract tool calls from the output into the choice delta. This is a defensive fix for providers that might not stream individual tool call events.Assistant
Let me verify the response_stream.go change.
Assistant
Let me verify both changes compile.
Assistant
Let me check the type of
output.Arguments.Assistant
Let me look at how the output items work in the OpenAI responses library.
Assistant
Let me look at the ResponseFunctionToolCall struct to understand the Arguments field.
Assistant
Let me look at the ResponseOutputItemUnion type.
Assistant
Let me check the union arguments type.
Assistant
I need to fix the argument extraction. The
Argumentsfield is a union type, and I need to useOfString.Assistant
Let me compile again.
Assistant
Both changes compile. Let me run the existing tests for the affected packages.
Assistant
Let me run the tests more quickly with just the relevant test files.
Assistant
Let me check which test failed.
Assistant
Let me check if this test failure is related to my change or pre-existing.
Assistant
Let me check if this test was failing before my change by reverting and testing.
Assistant
The test was already failing before my change - it's a pre-existing issue. Let me restore my changes.
Assistant
Let me run the tests excluding the pre-existing failure to check that my changes don't break anything else.
Assistant
Let me escape the pattern properly.
Assistant
Now let me run the OpenAI model provider tests.
Assistant
Let me also run the oaistream tests.
Assistant
All tests pass. Let me review my changes with git diff.
Assistant
Let me do a full build of the project to make sure everything compiles.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.