Skip to content

fix: support multiple client tool calls per agent turn - #52287

Closed
charzhou wants to merge 2 commits into
openclaw:mainfrom
charzhou:fix/multi-client-tool-calls
Closed

charzhou wants to merge 2 commits into
openclaw:mainfrom
charzhou:fix/multi-client-tool-calls

Conversation

@charzhou

@charzhou charzhou commented Mar 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • The client tool call pipeline only captured a single tool call per agent turn (last-write-wins variable). When the LLM called multiple client tools in one turn, only the last one was returned to the caller.
  • Changed clientToolCallDetected from a single-value variable to an array that accumulates all calls
  • Updated all 4 layers: attempt.ts (detection), types.ts (type), run.ts (pendingToolCalls construction), openresponses-http.ts (non-stream + stream output)

Root cause

In attempt.ts, the onClientToolCall callback overwrote a single variable on each invocation:

// Before: last-write-wins
let clientToolCallDetected = null;
clientToolCallDetected = { name: toolName, params: toolParams };

// After: accumulate all calls
const clientToolCallsDetected = [];
clientToolCallsDetected.push({ name: toolName, params: toolParams });

Downstream, run.ts wrapped this single value into a 1-element pendingToolCalls array, and openresponses-http.ts only read pendingToolCalls[0].

Test plan

  • Send a /v1/responses request with instructions to call 3 client tools in one turn
  • Verify all 3 function_call items appear in the response (non-stream)
  • Verify all 3 function_call SSE events are emitted (stream)
  • Verify single tool call behavior is unchanged
  • Existing test updated to match new array field shape

The client tool call pipeline only captured a single tool call per turn
(last-write-wins). When the LLM called multiple client tools in one
turn, only the last one was returned.

- attempt.ts: change clientToolCallDetected from single value to array
- types.ts: clientToolCall → clientToolCalls (array)
- run.ts: build pendingToolCalls from full array
- openresponses-http.ts: emit all function_call items in both
  non-stream and stream paths
- Update test to match new array shape
@greptile-apps

greptile-apps Bot commented Mar 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a bug where only the last client tool call was returned to the caller when the LLM invoked multiple client tools in a single agent turn. The fix changes the internal detection mechanism from a single-value overwrite pattern to an array accumulation pattern across all 4 relevant layers.

Changes:

  • attempt.ts: clientToolCallDetected (single variable, last-write-wins) → clientToolCallsDetected (array that accumulates all calls via .push())
  • types.ts: clientToolCall? field updated from a single object to clientToolCalls?: Array<...>
  • run.ts: pendingToolCalls construction now maps over the full array instead of wrapping a single value; each call receives its own unique id
  • openresponses-http.ts: Both non-stream and stream response paths iterate over all pendingToolCalls instead of only reading index [0]; the streaming path correctly tracks outputIndex per call
  • Test updated to match the new array field shape (clientToolCalls: [...])

Confidence Score: 5/5

  • This PR is safe to merge — it is a clean, well-scoped bug fix with no regressions and consistent behaviour for the single-call case.
  • The root cause is clearly identified and the fix is applied consistently across all 4 layers. Single-call behaviour is preserved (the array mapping is functionally equivalent to the previous 1-element array construction). Existing tests are correctly updated and no new issues are introduced. The only pre-existing rough edge (non-stream path omitting status: "completed" on function_call output items, and streaming path using the non-completed item in the final outputItems snapshot) is not a regression from this PR.
  • No files require special attention.

Reviews (1): Last reviewed commit: "fix: support multiple client tool calls ..." | Re-trigger Greptile

@charzhou

Copy link
Copy Markdown
Contributor Author

@joshavant Could you please take a look and merge this PR if it looks good?

@charzhou charzhou closed this Apr 11, 2026
@charzhou
charzhou deleted the fix/multi-client-tool-calls branch April 11, 2026 16:50
@bonelli

bonelli commented Apr 15, 2026

Copy link
Copy Markdown

@charzhou what happened? i still have the issue on the latest release, what happened with your fix proposal?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants