Skip to content

fix(toolRunner): propagate container.id across iterations#974

Open
claygeo wants to merge 1 commit intoanthropics:mainfrom
claygeo:fix/tool-runner-container-propagation
Open

fix(toolRunner): propagate container.id across iterations#974
claygeo wants to merge 1 commit intoanthropics:mainfrom
claygeo:fix/tool-runner-container-propagation

Conversation

@claygeo
Copy link
Copy Markdown

@claygeo claygeo commented Apr 3, 2026

Summary

Closes #964 (Bug 1)

When using toolRunner with code_execution_20260120 and client-side tools (betaTool), the container.id from the API response was not forwarded to the next iteration, causing:

container_id is required when there are pending tool uses generated by code execution with tools.

Root cause

BetaToolRunner.ts:209 extracted only { role, content } from the response message, discarding the container field. The next API call was made without container.id, even though the server requires it for container reuse.

Fix

After extracting the response message, propagate container.id to the next iteration's params:

const message = await this.#message;
const { role, content } = message;
this.#state.params.messages.push({ role, content });

// Propagate container.id for code_execution tool reuse
if (message.container?.id) {
  this.#state.params.container = message.container.id;
}

Uses the string form of the container param (one of the accepted types: BetaContainerParams | string | null).

Scope

This addresses Bug 1 from the issue (missing container.id propagation). Bug 2 (setMessagesParams infinite loop) has a different root cause and should be tracked separately.

Test plan

  • With container in response → container.id is set on params for next iteration
  • Without container in response → params unchanged (existing behavior preserved)
  • Matches how the runner already stitches tool_use/tool_result message pairs between iterations

When using toolRunner with code_execution and client-side tools,
the container.id from the API response was not forwarded to the
next iteration, causing "container_id is required" errors.

Now extracts container.id from the response message and sets it
on the params for the next API call, matching how the runner
already stitches tool_use/tool_result message pairs.

Closes anthropics#964
@claygeo claygeo requested a review from a team as a code owner April 3, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: toolRunner does not propagate container.id across iterations, and setMessagesParams causes duplicate tool call loops

1 participant