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 then find the relevant code related to subagent handling and tool_calls.
Assistant
Let me search for relevant code related to subagent handling and "no response from subagent".
Assistant
I need to only make one tool call at a time.
Assistant
Let me search more broadly for subagent-related code.
Assistant
Let me look at agent_delegation.go since that seems most relevant to subagent handling.
Assistant
Let me search for "no response" more
Assistant
Let me look at the agent_delegation.go file more carefully
Assistant
Let me use the correct syntax for opening a file.
Assistant
Let me search for where "no response" could be generated - it might be in the session or streaming
Assistant
Let me try again differently.
Assistant
Let me look at
GetLastAssistantMessageContentand related functions.Assistant
Let me look at the session's
GetLastAssistantMessageContentand the MCP server referenceAssistant
Let me find
getLastMessageContentByRoleAssistant
Let me see that function.
Assistant
Let me look at the MCP server reference and other places that check for empty content
Assistant
Let me search more specifically for this exact phrase or close
Assistant
Let me look at how the runtime processes LLM responses and handles
Assistant
Let me look for the runtime stream processing
Assistant
Let me look at loop.go around the tool call processing and how the stream is processed
Assistant
Let me look at
processToolCallsin loopAssistant
Let me search for it differently.
Assistant
Let me find where processToolCalls is
Assistant
Let me look at
tool_dispatch.goto understand how tool calls areAssistant
Let me look at the toolexec dispat
Assistant
Let me look at
dispatcher.goAssistant
Now let me look at how
RunStreamprocesses responses, particularly around tool call handling:Assistant
Let me look at the sampling code, especially around
FinishReasonToolCallsAssistant
Let me look at the loop.go streaming processing
Assistant
Let me see the continuation of run
Assistant
Let me look at the fallback execution to understand how the stream result is built
Assistant
Let me find
handleStreamand thestreamResulttypeAssistant
Let me look at
streaming.gofrom the beginningAssistant
Let me look at the chat message structure and how tool calls are represented
Assistant
Let me look at chat
Assistant
Let me look at the provider implementations, especially for OpenAI-compatible APIs
Assistant
Let me look at the OpenAI stream implementation
Assistant
Let me look at the streaming implementations in the OpenAI provider
Assistant
Let me look at the chat completions event stream
Assistant
Let me look at the Chat Completions streaming implementation for OpenAI
Assistant
Let me look at the oaistream package which likely handles the Chat Completions streaming
Assistant
Let me look at
adapter.goAssistant
Let me look at the main loop logic to understand when it stops
Assistant
Let me search for "no response" more broadly
Assistant
Let me look at
recordAssistantMessageAssistant
Let me check where
trackUsageis set and how it affects the streamAssistant
Let me look at
runStreamLoopto understand the full loop flowAssistant
Let me look at the test files for oaistream adapter
Assistant
Let me look at recent git log for relevant commits
Assistant
Let me look at the git log for commits related to tool calls or streaming
Assistant
Let me look at how
NonInteractiveaffects the run loopAssistant
Let me look at the elicitation code to understand how non-interactive affects tool approval
Assistant
Let me look at the toolexec permissions
Assistant
Let me look at the
approveAndRunmethod in the dispatcher to understand the approval flowAssistant
Let me look at
approveAndRunandaskUserAssistant
Let me look at how the result of
runForwardingis used by the callerAssistant
Let me look for where the tool call result from subagent is processed when content is
Assistant
Now I have a clear hypothesis about the bug. Let me re-examine the
handleStreamfunction to confirm my finding about the early return happening before tool calls from the same chunk are processedAssistant
Now I can see the bug clearly. In
handleStream, the early return forFinishReasonStop/FinishReasonLengthat line 131 fires before the tool call processing at line 155. When a chunk contains both a finish reason ("stop"or"length") AND tool calls inDelta.ToolCalls, the tool calls from that chunk are never processed.For LiteLLM proxy specifically, this can happen because LiteLLM might send
finish_reason: "stop"in the same chunk as the tool calls, unlike standard OpenAI which separates them via the usage-chunk pattern.The fix is to move the tool call processing block before the early return check. Let me implement
Assistant
Now I'll implement the fix. The issue is that the early return for
FinishReasonStop/FinishReasonLengthhappens before tool calls from the same chunk are processed. I need to move the tool call processing block before the finish reasonAssistant
Now let me apply the fix. I need to edit the file to move the tool call processing before the finish reason check:
Assistant
Let me open the file first
Assistant
Let me view the exact section I need to edit:
Assistant
Now I'll make the edit. I need to reorder the blocks so tool call processing happens before the finish reason
Assistant
There's an extra
}at line 213. Let me check the context around that areaAssistant
Let me remove the extra
}at line 213Assistant
The file looks correct now. Let me verify the changes compile and run
Assistant
Let me check the Go setup
Assistant
Let me set the Go environment and try
Assistant
Let me check if there are build scripts or try with GOCACHE set
Assistant
The build succeeds. Now let me run the relevant tests
Assistant
Let me run all runtime tests
Assistant
Let me see which test
Assistant
Let me check if
TestDoCompactAfterHookFiresis related to my changes by looking at itAssistant
Let me check if this test was failing before my changes by running just that
Assistant
Let me check if this test was already failing before my changes
Assistant
The test was already failing before my changes. Let me restore my
Assistant
Now let me also check the streaming-related tests in the oaistream package
Assistant
Let me also run the e2e tests to verify no regressions
Assistant
All e2e tests pass. Let me verify the final state of my changes
Assistant
The diff looks correct. Let me do a final build check and run the runtime tests (excluding the pre-existing failure
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.