fix(tool_runner): propagate container_id for programmatic tool calling#1150
fix(tool_runner): propagate container_id for programmatic tool calling#1150stephaniepang97 wants to merge 1 commit intomainfrom
Conversation
When using programmatic tool calling (PTC), the API returns a container_id in the response that must be passed in subsequent requests. Without this, the API returns an error: 'container_id is required when there are pending tool uses generated by code execution with tools.' This change updates both sync and async tool runners to extract the container.id from responses and pass it in subsequent API calls.
dtmeadows
left a comment
There was a problem hiding this comment.
This looks good to me and the reasoning makes sense. @karpetrosyan can I leave the final review to you? If it's helpful here's the specific place in the docs about having to pass this: https://platform.claude.com/docs/en/agents-and-tools/tool-use/programmatic-tool-calling#step-3-provide-tool-result
|
LGTM! |
| assert message is not None | ||
|
|
||
| # Update container from response for programmatic tool calling support | ||
| if message.container is not None: |
There was a problem hiding this comment.
@stephaniepang97 Can we, instead of using the container.id from the last API response, rely on the last assistant message (runner._get_last_assistant_message_content)? The user might change the state during the loop (e.g., in a for block via set_messages_params), so we should take the ID from the last message in the current state, not from the last API response
| assert message is not None | ||
|
|
||
| # Update container from response for programmatic tool calling support | ||
| if message.container is not None: |
There was a problem hiding this comment.
Can we add a simple test for this case to make sure we’re sending container.id back? We can use a snapshot with a real example and record it, like we do in the other tests.
Problem
When using programmatic tool calling (PTC) with
tool_runner, the API returns acontainer_idin the response that must be passed in subsequent requests. Without this, the API returns:Solution
Update both sync and async tool runners to extract
message.container.idfrom responses and set it inself._params["container"]for subsequent API calls.Changes
BaseSyncToolRunner.__run__(): Added container propagation after getting messageBaseAsyncToolRunner.__run__(): Added container propagation after getting message (async version)Testing
This enables using
tool_runnerwith programmatic tool calling where client-side tools are called from within code execution. The container lifecycle is now properly managed across requests.Example