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
Let me explore the repository structure to understand the codebase.
Assistant
This is the background agent tool. Let me look at the agent delegation code, which is more relevant to the issue.
Assistant
Now let me look at where the "no response from subagent" message comes from. Let me search for it.
Assistant
Let me look at the GetLastAssistantMessageContent function. The issue is about subagent tool_calls not being handled. Let me look at that function.
Assistant
Let me look at how the messages are stored. Let me look at the Message struct.
Assistant
Let me look at the agent loop to understand the finish_reason handling.
Assistant
Let me look at the runtime loop to understand how the agent processes the response and the finish_reason.
Assistant
Now let me look at the loop_steps.go which probably contains the main loop iteration logic that processes finish_reason and tool calls.
Assistant
Let me look at the main loop logic that processes streamResult and finish_reason. Let me look at the truncated part of loop.go.
Assistant
Now I need to understand how
res.Stoppedis determined. Let me look at the streaming code.Assistant
The streaming code already handles
finish_reason: stopwith tool calls. Let me check the non-streaming path. Let me search for how chat completion responses are converted to a stream.Assistant
Let me look at the adapter.go for oaistream which probably converts the stream to chat.MessageStream.
Assistant
The streaming path seems to handle
finish_reason: stopwith tool calls. Let me check the git history and changelog for hints about this issue.Assistant
The streaming path has a subtle issue. Let me look more carefully at the
handleStreamearly-return logic. When a chunk contains BOTHfinish_reason: stopAND tool call deltas, the finish reason check returns early BEFORE processing the tool calls. Let me look at existing tests for handleStream.Assistant
Let me look at the chat package types and search for direct tests of handleStream.
Assistant
Let me write a reproduction test. First, let me find how
handleStreamis invoked and check existing direct tests.Assistant
Let me write a reproduction test that directly calls
handleStreamwith a stream that sends tool calls andfinish_reason: stopin the same chunk (LiteLLM behavior).Assistant
I need to import "io" in my repro test. Let me fix the test.
Assistant
Now let me run the reproduction test.
Assistant
I've confirmed the bug. When a chunk contains both tool call deltas AND
finish_reason: "stop"in the same chunk (LiteLLM behavior), the early-return on the finish reason happens BEFORE processing the tool call deltas, so the tool calls are lost andStopped=true.Let me look at the full
handleStreamagain to design the fix.Assistant
I've confirmed the bug. Now let me look at the exact lines to refactor. Let me view the closure definitions area.
Assistant
Now let me add the
processToolCallDeltasclosure afterrecordUsage.Assistant
Let me open the streaming.go file and make the edits.
Assistant
Now let me insert the closure after line 105 and modify the loop body. First, insert the closure:
Assistant
Let me add a blank line between the closure and the
forloop.Assistant
Now let me modify the loop body. First, replace the finish reason check and the tool call handling block. Let me view the full range to replace.
Assistant
Now I'll replace the section from line 200 (the finish reason check) to the end of the tool call handling block (line ~269, the
continue+}).Let me identify the exact line range. The block to replace starts at line 200 (
if choice.FinishReason == chat.FinishReasonStop...) and ends at thecontinue+}closing the tool call handling. Let me find the exact end line.Assistant
So the tool call handling block is from line 226 to line 281 (the
continueis at 279, and}closing the if is at 281). Let me check lines 278-282.Assistant
Now I'll replace lines 200:281 with the new logic that processes tool call deltas before the finish reason check.
Assistant
Let me also check the
newStreamAdapterfunction and verify the adapter behavior. Let me check where it's defined.Assistant
Now let me build and run the reproduction test to confirm the fix works.
Assistant
The fix works. Now let me also verify the scenario where tool calls come as separate deltas and finish_reason "stop" comes in a separate chunk (the normal case still works), plus a usage-in-same-chunk scenario. Let me enhance the repro test.
Assistant
The
recordUsageclosure panics becausetelis nil in my test. Let me find a no-op telemetry implementation to use in tests.Assistant
defaultTelemetry{}is a valid implementation. Let me update the repro test to use it.Assistant
All my reproduction tests pass. Now let me run the full runtime test suite to make sure I didn't break anything.
Assistant
There's a test failure. Let me find which test failed.
Assistant
Let me check if this test failure is pre-existing (not related to my change) by stashing my changes.
Assistant
The
TestDoCompactAfterHookFiresfailure is pre-existing — it fails even without my changes. So my change is not the cause. Let me run the rest of the runtime tests, excluding that pre-existing failure.Assistant
All other runtime tests pass. Let me also run the oaistream and openai provider tests to be safe.
Assistant
My fix in
handleStreamis centralized and covers all stream adapters (chat completions AND responses API) since they all flow throughhandleStream. Let me verify the whole project builds and run a broader test.Assistant
Only the pre-existing
TestDoCompactAfterHookFiresfails (unrelated to my change). Let me also run streaming-related tests and the response API test to be thorough.Assistant
All existing tool call tests pass. My refactoring preserved existing behavior. Now let me remove the temporary reproduction test file before submitting, per the instructions.
Assistant
Let me do a final review of the diff.
Assistant
The diff looks clean. Let me view the final state of the modified loop section to ensure correctness.
Assistant
Let me run gofmt and vet to ensure formatting and correctness.
Assistant
gofmt and vet pass. Let me run the e2e tests to make sure nothing breaks there (they may test runtime behavior).
Assistant
e2e tests pass. Let me also run the chatserver, session, and tools/builtin/agent tests since they relate to the subagent delegation flow.
Assistant
There's a session test failure. Let me check if it's pre-existing (unrelated to my change).
Assistant
TestNewSQLiteSessionStore_DirectoryNotWritableis likely failing because tests run as root (directories are always writable). Let me confirm it's pre-existing and unrelated to my change.Assistant
Confirmed pre-existing and unrelated (fails on a clean checkout too — running as root makes "not writable" tests fail). Let me run the session tests excluding that failure.
Assistant
All other session tests pass. Let me confirm the chatserver tests pass.
Assistant
Everything passes except two pre-existing, unrelated failures. Let me do a final review of the complete modified
handleStreamfunction.Assistant
My fix is complete and verified. Let me do a final confirmation of the build and that the temporary test file is removed before submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.