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 start by exploring the repository structure to understand the
Assistant
Let me look at the project structure to understand the codebase.
Assistant
Let me search for "no response from subagent" in the codebase.
Assistant
Let me look at the runtime, specifically agent_delegation.go and tools for subagent handling.
Assistant
Let me look at the agent_delegation.go file which seems to be the main file for subagent delegation.
Assistant
me look at
GetLastAssistantMessageContentand see how the session handles tool_calls.Assistant
me search for the "no response from" text.
Assistant
Let me look at the A2A tool to see how it handles the response:
Assistant
Let me look at how
GetLastAssistantMessageContentworks in the session package.Assistant
let me look at where tool calls are processed in the runtime. Let me look at the tool_dispatch.go and loop.go files.
Assistant
me look at loop_steps.go which seems to contain the core streaming logic.
Assistant
Let me look at streaming.go and see how the model provider works:
Assistant
Let me look at the OpenAI provider to see how it processes tool calls:
Assistant
Let me look at the SSE stream adapter:
Assistant
Let me search for the specific issue in the codebase:
Assistant
me look at the loop.go's main streaming logic to see how tool calls are processed:
Assistant
Let me look more carefully at how subagent calls are handled and what triggers the "no response" message:
Assistant
The issue title says "Subagent tool_calls not handled when using LiteLLM proxy". Let me see if there's a chat package or model package related issue. Let me look at how OpenAI tool calls are parsed.
Assistant
me look at the chat.go to understand the FinishReason values:
Assistant
Let me look at runtime.go to see if there's a "no response from subagent" type message:
Assistant
Let me look at the streaming adapter test:
Assistant
Let me look at the streaming adapter behavior with tool calls more carefully:
Assistant
look at the OpenAI streaming tests to see how they handle the tool call case:
Assistant
Let me write a test to verify the streaming adapter behavior with tool calls and finish_reason "stop":
Assistant
let me write a temporary test script to simulate LiteLLM behavior:
Assistant
Let me test with trackUsage set to false:
Assistant
Let me test a different scenario where the tool call is sent in the SAME chunk as the finish_reason:
Assistant
me look at how the transfer_task tool processes the result and find tests:
Assistant
Let me look at how transfer_task is tested:
Assistant
Let me look at how the host handles the response of a subagent tool call:
Assistant
Let me write a test to actually run the runtime with the LiteLLM scenario and see what happens:
Assistant
Let me look at how to properly mock a provider for this test:
Assistant
Let me write the test in a Go test file inside the package and run it:
Assistant
I see the issue - the host agent needs to register the tools. Let me look at how tools are added:
Assistant
Let me look at how the existing tests work and find where transfer_task gets registered:
Assistant
Let me look at how tools are registered for the agent:
Assistant
Let me look at how the runtime registers the default tools:
Assistant
update the test to include the proper tools:
Assistant
Let me check the subagent's loop after the tool call. The mock only has 2 responses but the subagent needs more after the tool result:
Assistant
me check the default value of trackUsage:
Assistant
Let me look at the actual response format from LiteLLM. Let me look at the openai-go SDK source:
Assistant
OK, so the SDK reads
finish_reasonas a string from the JSON. If the JSON chunk doesn't havefinish_reason, it would be empty string.Let me look at how
choice.FinishReasonis read:Assistant
Let me trace through what happens when the subagent's stream only has the tool call and finish_reason "stop", and then the loop makes another LLM call:
Assistant
Let me look at the runStreamLoop function and trace through the iteration:
Assistant
Let me write a test to see what actually happens with only the tool call and finish_reason "stop" in one chunk:
Assistant
Now let me trace through handleStream for all these scenarios:
Assistant
Let me look at how usage is handled in the adapter:
Assistant
Let me create a more specific test that simulates LiteLLM sending usage in the same chunk as the finish_reason:
Assistant
Let me look at the loop detector:
Assistant
Let me look at the loop logic in loop.go more carefully:
Assistant
Let me look at the SDK's stream handling:
Assistant
Let me look at the OpenAI tests for tool calls:
Assistant
me look at what the host agent does with the transfer_task response:
Assistant
Let me search for code that filters based on finish_reason:
Assistant
look at recent commits and CHANGELOG:
Assistant
Let me look at recent changes to streaming and tool_calls:
Assistant
Let me look at the issue differently. Let me see what happens when LiteLLM returns a tool call with finish_reason "stop":
Assistant
Let me look at how the subagent's tool results are stored in the session:
Assistant
OK, the tool messages are stored with role
chat.MessageRoleTool. Let me look at the session.go to see how messages are addedAssistant
Let me look at how the tool results are stored:
Assistant
Let me look at how the openai-go SDK uses the NewStreaming function:
Assistant
me re-read the loop logic to check if tool calls are processed before checking
Stopped:Assistant
Let me look at the full loop iteration:
Assistant
Let me write a more thorough test to simulate the exact LiteLLM scenario with usage in the same chunk:
Assistant
Now I understand the issue! The subagent's last assistant message has only a tool call (no content), so
GetLastAssistantMessageContent()returns empty. The host agent sees an empty response and says "no response from subagent".Let me look at how to retrieve tool results from the session:
Assistant
Let me look at the GetAllMessages and the message format:
Assistant
Now I understand the issue clearly. The subagent's last assistant message has only a tool call (no content), so the result returned to the host agent is empty. The fix is to handle this case by including the tool results.
Let me first verify my understanding by looking at the runForwarding logic and looking for similar patterns:
Assistant
Let me look at the session structure to understand how to get the tool results:
Assistant
Let me check if there's already a similar helper for handling tool results:
Assistant
Now let me design the fix. Let me look at how the tool result messages look:
Assistant
Now let me implement the fix. I'll:
- Add a helper method to
Sessionto get the last assistant response (content or tool results) - Update
runForwardingto use this helper
- Add a helper method to
Assistant
Now let me add a helper method to the Session struct. I'll add it after
GetLastAssistantMessageContent:Assistant
Now I need to add the
fmtimport to the session.go file:Assistant
Now let me update the
runForwardingfunction to use the new helper:Assistant
Now let me update both
runForwardingandrunCollectingto use the new helper:Assistant
I see there's a duplicate
}after my edit. Let me fix it:Assistant
I see there's a duplicated comment. Let me fix this:
Assistant
Now let me also update
runCollectingto use the new helper:Assistant
Now let me build the code and test:
Assistant
a leftover. Let me fix this:
Assistant
me clean up the duplicate lines:
Assistant
The code builds. Let me now run my test to verify the fix:
Assistant
The fix works! Now the response is
company_search: search resultsinstead of empty. Let me run the existing tests to make sure I didn't break anything:Assistant
me check if this test failure is related to my changes:
Assistant
check if this test fails before my changes too:
Assistant
Good, the test fails even before my changes - so it's unrelated. Let me run the rest of the session tests:
Assistant
the pre-existing test failure remains. Let me now run the runtime tests:
Assistant
test also fails before my changes. Let me check what other tests are failing:
Assistant
Only one test failing. Let me check the count of tests:Only one test failing. Let me check the count of tests:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cd /docker-agent && export HOME=/root && go test ./pkg/runtime/... -timeout 120s -v 2>&1 | grep -E "^--- PASS|^--- FAIL" | wc -l]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Let me retry with a proper tool call:
Assistant
337 tests, only 1 failing (pre-existing). Let me also check the broader test suite:
Assistant
1 pre-existing failure. My new test passes! Let me now add proper tests for the new function in the session package:
Assistant
Let me delete my reproduction test and instead write proper tests for the new GetLastAssistantResponse function. Let me first remove my reproduction test:Let me write proper tests for the new function. First let me remove the reproduction test:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[rm /docker-agent/pkg/runtime/repro_litellm_test.go && ls /docker-agent/pkg/runtime/repro_litellm_test.go 2>&1]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Let me try again with a single, simple tool call.
Assistant
Good, the test file is deleted. Now let me add proper tests for the new function. Let me write tests in the session_test.go:
Assistant
Let me create a separate test file for the new function. This is cleaner than modifying the existing test file:
Assistant
an issue with the file content. Let me check what happened:
Assistant
The file is empty. Let me delete it and try again:
Assistant
All tests pass. Let me also verify that the broader session test suite still passes (excluding the pre-existing failure):All tests pass. Let me also verify that the broader session test suite still passes (excluding the pre-existing failure):]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cd /docker-agent && export HOME=/root && go test ./pkg/session/... -v 2>&1 | grep -E "^--- FAIL" | head -10]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Only the pre-existing failure remains. Let me also run the runtime tests to verify everything still works:
Assistant
Only the pre-existing failure. Let me also write an integration test for the transfer_task flow to verify the end-to-end behavior. Let me add a runtime test that simulates the exact scenario:
Assistant
Let me add an end-to-end test that simulates the LiteLLM scenario:
Assistant
a separate test file for the LiteLLM scenario, keeping it clean:
Assistant
The session.Item.Message is a *session.Message which has a Message field that is chat.Message. Let me fix this:Let me fix the type issue:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[sed -i 's|m := sess.Messages[i].Message|m := sess.Messages[i].Message.Message|; s|toolResult := &m|toolResult = &m|; s|var toolResult *chat.Message|var toolResult chat.Message|; s|m := sess.Messages[i].Messagem|g' pkg/runtime/litellm_subagent_test.go]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
The test passes. Let me also verify the broader runtime tests still work:
Assistant
Only the pre-existing failure. Let me also verify related packages work:
Assistant
All affected packages pass. Let me also check the chat and model packages:
Assistant
All tests pass. Let me look at my final diff:
Assistant
Let me also verify the test files are well-formed:
Assistant
Let me verify everything still works after gofmt:
Assistant
Let me also verify the final diff one more time:
Assistant
The changes are minimal and focused:
pkg/session/session.go: Added a new methodGetLastAssistantResponse()that handles the case where the last assistant message has only tool calls.pkg/runtime/agent_delegation.go: Changed two call sites to use the new method.pkg/session/session_response_test.go: New test file with 10 unit tests for the new method.pkg/runtime/litellm_subagent_test.go: New test file with the end-to-end regression test.
Let me also think about edge cases I should consider:
- What if the session has no messages at all? - The function returns "" (handled).
- What if the last assistant message has only whitespace content? - The function falls through to the tool call handling (good).
Assistant
I notice that
runCollectingstill usesGetLastAssistantMessageContentfor the subagent_stop hook. Let me update that for consistency:Assistant
Only the pre-existing failure remains. Let me also run my tests multiple times to ensure stability:
Assistant
Let me check the final diff one more time:
Assistant
Let me also check the test files:
Assistant
Both pre-existing failures exist before my changes (I verified with
git stash). My new tests all pass.Let me verify the test files look good:
Assistant
Let me also verify the unit test file:
Assistant
Let me run my new tests one more time to confirm they all pass:
Assistant
All my tests pass. Let me also do a broader sanity check:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.