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. Assistant
The issue is about subagent tool_calls not being handled when using LiteLLM proxy. Let me first explore the repository structure to understand the codebase.
Let me start by exploring the repository and understanding its structure.
Assistant
Let me search for the error message and understand the subagent handling code
Assistant
No results. Let me try a broader search.
Assistant
No results with
--include="*.go". Let me try without the include flag.Assistant
Let me search for "subagent" in the codebase
Assistant
Let me look at the agent_delegation.go file and also search for "tool_call"
Assistant
Let me search for the error message more broadly, and also look at the session-related code.
Assistant
Let me search for "tool_calls" and "ToolCall" handling in the codebase to understand how tool calls from LLM responses are processed.
Assistant
Let me look at some key files to understand the flow. First, let's look at the main loop in
pkg/runtime/loop.goand the session for `GetLastAssistantMessageContentAssistant
Let me look at
GetLastAssistantMessageContentin session and the MCP server codeAssistant
Let me look at that function.
Assistant
Let me look at getLastMessageContentByRole.
Assistant
Let me see this function fully.
Assistant
Let me search for "no response" in the entire codebase again without the go filter.
Assistant
Let me try different search patterns
Assistant
Hmm, it seems there's no output. Let me try searching with ripgrep if available, or just grep for "response"
Assistant
Strange that it exits with 0 but no output. Maybe there's something weird with the shell. Let me try using find and xargs.
Assistant
Let me check the MCP server and A2A code.
Assistant
Let me look at the OpenAI client and response stream to understand how tool calls are parsed.
Assistant
Let me look at the oaistream package which handles OpenAI-compatible message streaming.
Assistant
Let me look at the oaistream messages.go which likely handles message parsing including tool calls.
Assistant
Let me look at the adapter.go in oaistream.
Assistant
Now let me look at the runtime's handling of streaming results
Assistant
Let me look at the streaming.go file to understand how tool calls are accumulated.
Assistant
Let me look at the rest of loop.go to understand the main loop and how tool_calls are handled.
Assistant
Let me continue looking at the loop, specifically around the tool execution part.
Assistant
Let me look at the OpenAI response_stream.go
Assistant
Let me look at how the OpenAI client wraps the stream, especially the part that handles the stream adapter.
Assistant
Let me look at the wrap.go and the newStreamAdapter function in the OpenAI client.
Assistant
Let me find the newStreamAdapter function.
Assistant
Let me look at the adapter.go in the OpenAI directory.
Assistant
Let me look at the tool dispatch code to understand how tool calls are executed.
Assistant
Let me check the Gemini adapter and ws_stream for issues with tool_calls handling.
Assistant
Let me look at lines 590-700 of the OpenAI client.
Assistant
Let me look at
runTurnmore fully to see how streamResult is processed.Assistant
Let me see the rest of
runTurn.Assistant
Let me search for any LiteLLM-specific handling in the codebase.
Assistant
Let me look at the fake proxy code.
Assistant
Let me look at the tool_choice tests.
Assistant
Let me look at the Gemini adapter since the user is using gemini-pro via LiteLLM.
Assistant
Let me look at the MCP server context.
Assistant
Let me look at the A2A code.
Assistant
Let me look at the WebSocket streaming code, since it might handle tool_calls differently.
Assistant
Let me check the git log for recent changes related to this issue.
Assistant
Let me look at the recent Gemini-related fix.
Assistant
Let me see the Gemini client fix.
Assistant
Let me see the actual diff.
Assistant
Let me look at the streaming tests and the runtime tests that might be relevant.
Assistant
Let me look at the runtime test for tool calls.
Assistant
Let me look at the stream builder for tests.
Assistant
Let me see the stream builder implementation.
Assistant
Let me search for any specific handling of response formats that LiteLLM might trigger.
Assistant
Let me check the wasm runtime code for finish reason handling.
Assistant
Let me search for recent changes to handleStream and the streaming code.
Assistant
Let me look at a key commit for finish_reason handling.
Assistant
Let me see the diff for streaming.go in that commit.
Assistant
Let me look at how MaxIterations is set for agents.
Assistant
Let me check the agent's MaxIterations default.
Assistant
Let me find where maxIterations default is set.
Assistant
Let me look at the enforceMaxIterations function to understand iteration limiting.
Assistant
Let me look at the enforceMaxIterations function.
Assistant
Let me look at how skill sub-agents are handled.
Assistant
Let me look at skill_runner.go for RunSkillFork.
Assistant
Let me look at the session messages functions.
Assistant
Let me look at GetAllMessages.
Assistant
Let me search for any recent issues or PRs related to this.
Assistant
Let me look at these two critical commits.
Assistant
Now let me look at the LiteLLM temporary hack removal.
Assistant
Let me look at the subagent delegation fix.
Assistant
Let me see the full diff for this subagent delegation fix
Assistant
Let me look at this commit about surfacing tool calls.
Assistant
Let me look at the agent creation defaults.
Assistant
Let me check the agent initialization defaults.
Assistant
Let me look at the toolexec dispatcher to see how tool errors are handled.
Assistant
Let me look at the approveAndRun method in the dispatcher.
Assistant
Let me see the full call.run method.
Assistant
Let me think about this issue from a different perspective. Let me look at what happens when
GetLastAssistantMessageContent()returns empty string.Assistant
Let me check the MessageDelta struct definition.
Assistant
Let me see the full struct.
Assistant
Let me look at the fallback executor.
Assistant
Let me look at the fallback executor's execute method.
Assistant
Let me see the execute method.
Assistant
Let me see the rest of the execute method.
Assistant
Let me search for any remaining LiteLLM-specific code or handling.
Assistant
Let me look at the WebSocket stream test for tool calls.
Assistant
Let me check if FunctionCall is used anywhere in the streaming pipeline.
Assistant
Now I have a good understanding of the issue. Let me implement the fix. Based on my analysis, the key problem is in
handleStreaminpkg/runtime/streaming.go:- The
continuestatement after processing tool calls skips the finish reason tracking and content processing, which can cause issues when a chunk has both tool calls and other data. - The legacy
FunctionCallfield (used by some OpenAI-compatible APIs) is not processed.
Let me fix these issues.
- The
Assistant
Let me open the file properly.
Assistant
Let me see the full file.
Assistant
Now I can see the issue. The early return for
finish_reason: "stop"/"length"(line 132) fires BEFORE the tool calls in the same chunk are processed (line 159). If a chunk has both tool calls and a "stop" finish reason (which can happen with LiteLLM), the tool calls are never accumulated andStoppedis set totrue(sincelen(toolCalls) == 0).The fix is to reorder the checks: process tool calls FIRST, then check for early return. Also, the
continueafter tool call processing should be removed so that finish reason and content processing can still happen.Let me also handle the legacy
FunctionCallfield which is currently not processed byhandleStream.Assistant
Let me use a different approach with the replace command and a simpler edit.
Assistant
Let me read the exact content and create a more precise patch.
Assistant
I see the file uses tabs for indentation. Let me rewrite the script with correct indentation.
Assistant
Now I know the exact line numbers. Let me write the replacement.
Assistant
Let me verify the changes.
Assistant
Let me verify the code compiles.
Assistant
Let me set up the Go environment.
Assistant
Let me set up all Go environment variables.
Assistant
Let me check what's at line 273.
Assistant
Let me check the full file for brace mismatches.
Assistant
I see the issue - there's an extra closing brace at line 245. Let me fix it.
Assistant
Let me verify the build again.
Assistant
The build succeeds. Now let me run the relevant tests.
Assistant
Let me run all the runtime tests.
Assistant
Let me check which test specifically failed.
Assistant
Let me check which test failed.
Assistant
Let me check if this test was already failing before my changes.
Assistant
The test failure is pre-existing and not related to my changes. Let me run the tool call related tests specifically to make sure my changes work correctly.
Assistant
Let me also run the agent delegation tests.
Assistant
Let me also run the OpenAI provider tests.
Assistant
The tests pass. Let me now also run the oaistream tests.
Assistant
All tests pass. Let me verify the final state of the file.
Assistant
The code looks correct. Let me do a final build check.
Assistant
Let me check the diff of my changes.
Assistant
The changes look correct. Let me now submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.