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, only submits currently unstaged changes because it uses to get the changes that need to be submitted. - Assistant
I’ll first map the repository and search for subagent response handling, especially logic that treats textual content as the only valid response or gates tool calls on
finish_reason. Then I’ll reproduce the behavior with the narrowest relevant test path, patch it, and run focused plus broader tests. - Assistant
ripgrepis unavailable, so I’ll use recursivegrep. I’ll also read the repository instructions before editing and identify the Go packages that implement subagents and OpenAI-compatible response conversion. - Assistant
The runtime streaming code already contains finish-reason inference, which is likely central: LiteLLM can emit valid tool-call deltas but terminate with
"stop"rather than"tool_calls". I’ll inspect that implementation and its tests, then trace how a child run’s final content is returned to its parent to distinguish “tool call not executed” from “executed but empty final response.” - Assistant
I found a concrete ordering bug that matches LiteLLM’s payload shape:
handleStreamchecksfinish_reason: "stop"before consuming the same choice’sdelta.tool_calls. If the proxy puts tool calls and the terminal reason in one chunk, the runtime returns an empty result immediately. Standard OpenAI streams often separate these into two chunks, hiding the defect.I’ll confirm with a temporary focused test (without adding repository tests, per instruction), and inspect existing test helpers so the reproduction uses the real aggregation path.
- Assistant
The shared OpenAI adapter preserves same-chunk deltas and finish reasons, so the defect reaches
handleStreamexactly as suspected. I’ll create a transient in-package test that sends one chunk containing both a complete function call andFinishReasonStop; it should currently observe zero calls. I’ll remove this temporary test after using it to verify both failure and fix. - Assistant
The reproduction can directly call
handleStreamwith the existing mock stream and no usage metadata (avoiding unrelated telemetry setup). It will assert the intended invariant: tool-call presence must override an incorrect"stop"reason, and the call arguments must survive aggregation. - Assistant
The test did not run because this shell has neither
GOPATHnorGOMODCACHEconfigured; this is an environment issue rather than a behavioral result. I removed the temporary file as planned. I’ll inspect Go’s environment and rerun with an explicit writable module cache, recreating the same transient test. - Assistant
Go 1.26 is present, but blank environment defaults explain the cache error. I’ll use
GOPATH=/gofor all validation commands; the directory already exists and is writable. - Assistant
Dependencies downloaded successfully, but Go then required a build cache because
HOMEis also blank. I’ll set bothGOPATH=/goandGOCACHE=/tmp/go-build; this should finally execute the reproduction rather than fail during setup. - Assistant
The reproduction now fails exactly on
result.Stopped: the same-chunk tool call was skipped. I’ll fix the stream aggregator by processing every delta field before acting on a terminal reason. This also safely handles mixed terminal chunks containing content/reasoning. Provider finish-reason tracking remains unchanged for nonterminal reasons, while the existing normalization converts"stop"plus actual calls to"tool_calls". - Assistant
The patch is minimal and directly addresses ordering. One nearby comment still says terminal reasons are handled “above”; I’ll correct it, then rerun the identical transient reproduction to prove the function call, arguments, normalized reason, and continuation state are all correct.
- Assistant
The same reproduction now passes, confirming LiteLLM’s terminal tool call is retained and will cause the runtime loop to execute tools rather than stop. I’ll run the complete runtime package and OpenAI-stream adapter tests next, since those cover aggregation, tool dispatch, finish reasons, and compatible stream decoding.
- Assistant
The OpenAI adapter suite passed. The runtime suite had one failure in an unrelated compaction-hook test amid many parallel tests; the failure concerns hook summary text, not streaming/tool calls. I’ll rerun that test in isolation to determine whether it is a pre-existing parallel-state flake, then run the existing stream/tool-call tests serially with a focused pattern.
- Assistant
The compaction test also fails alone, so I won’t dismiss it. I’ll inspect its mock response and the compaction flow. If its stream places content in a tool-call chunk, our change could expose an existing assumption; otherwise I’ll establish whether it fails on the untouched baseline without altering tests.
- Assistant
This test does not invoke
handleStreamat all: the before-compaction hook supplies the summary and the provider stream is empty. Its output file exists but is empty, which strongly suggests the externaljqcommand in the test is unavailable. I’ll verify that, then run the focused tests independently (the previous&&correctly prevented them after the unrelated failure). - Assistant
Focused runtime and adapter suites pass. The only package failure is confirmed environmental (
jqis absent, and that test shells out to it). I’ll installjqrather than modify tests, rerun the runtime package, then run the repository’s standard build/test checks if time permits. Before that, I’ll inspect the final adapter usage handling to ensure the same-chunk case is not transformed unexpectedly when usage tracking is enabled. - Assistant
The adapter does preserve the tool-call delta even when it rewrites a usage-bearing terminal reason to
"stop", so the runtime ordering fix covers both usage-tracked and ordinary LiteLLM chunks. Withjqinstalled, I’ll rerun all runtime tests. - Assistant
The complete runtime package now passes. I’ll run the repository-wide Go test suite with the project’s deterministic API-key environment from the Taskfile, and separately compile all packages.
- Assistant
The repository-wide suite progressed through all packages but failed in
pkg/useragentbecause this automated shell has noHOME; this is another environment setup issue, not a code failure. I’ll rerun the failed package withHOME=/root, run the build, and inspect the final diff. A second full suite would repeat a 67-second UI test and is unlikely to add signal after all prior packages passed, but I’ll still ensure the directly affected packages and build are clean. - Assistant
The build succeeds and diff checks clean. The only behavioral expansion beyond the bug is intentional: if a provider combines tool calls with reasoning/content in one delta, all fields are now retained rather than discarding non-tool fields. This follows the aggregator’s contract and avoids another ordering dependency.
I’ll run the project’s custom lint rules and
go veton the affected packages; the configuredgolangci-lintbinary is not installed in this environment, so I’ll check availability first. - Assistant
Validation is clean: custom lint reports no offenses,
go vetpasses, build passes, affected tests pass, and the full suite’s sole environmental failure passes onceHOMEis set. I’ll do one final status/diff review to ensure no transient reproduction files or unrelated changes remain, then submit. Checklist assessment:- Reproduced error: Yes. A transient test modeled a LiteLLM chunk with
tool_callsandfinish_reason: "stop"together; before the patch it returnedStopped=trueand no call. - Confirmed fix: Yes. The identical transient test passed afterward, including function name, JSON arguments, normalized
tool_callsreason, and continuation state. - Considered edge cases: Yes. Separate terminal chunks remain unchanged; same-chunk usage rewriting, content/reasoning, XML fallback, multiple deltas, and
"length"termination continue through the same aggregation path. - Ran affected existing tests: Yes. Full
pkg/runtimeand OpenAI-compatible adapter tests pass. Repository-wide tests passed except initially panicked because this shell lacked ; that package passed with . Build, custom lint, vet, and diff checks pass.
- Reproduced error: Yes. A transient test modeled a LiteLLM chunk with
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.