@@ -177,7 +177,6 @@ class AnthropicTool(TypedDict):
177177_TOOL_TYPE_TO_BETA : dict [str , str ] = {
178178 "web_fetch_20250910" : "web-fetch-2025-09-10" ,
179179 "code_execution_20250522" : "code-execution-2025-05-22" ,
180- "code_execution_20250825" : "code-execution-2025-08-25" ,
181180 "mcp_toolset" : "mcp-client-2025-11-20" ,
182181 "memory_20250818" : "context-management-2025-06-27" ,
183182 "computer_20250124" : "computer-use-2025-01-24" ,
@@ -816,6 +815,15 @@ def _format_messages(
816815 return system , formatted_messages
817816
818817
818+ def _container_id (container : Any ) -> str | None :
819+ """Return the container ID from either accepted `container` shape."""
820+ if isinstance (container , str ):
821+ return container
822+ if isinstance (container , dict ):
823+ return container .get ("id" )
824+ return None
825+
826+
819827def _collect_code_execution_tool_ids (formatted_messages : list [dict ]) -> set [str ]:
820828 """Collect `tool_use` IDs that were called by `code_execution`.
821829
@@ -1255,6 +1263,28 @@ class ChatAnthropic(BaseChatModel):
12551263 [context management](https://platform.claude.com/docs/en/build-with-claude/context-editing).
12561264 """
12571265
1266+ container : dict [str , Any ] | str | None = None
1267+ """Code execution container for the request.
1268+
1269+ Either a container ID from a previous response, or a dict of container
1270+ parameters — notably
1271+ [skills](https://platform.claude.com/docs/en/build-with-claude/skills-guide)
1272+ to load into the container. Skills require a
1273+ [code execution](https://docs.langchain.com/oss/python/integrations/chat/anthropic#code-execution)
1274+ tool to be bound.
1275+
1276+ ```python
1277+ model = ChatAnthropic(
1278+ model="claude-opus-5",
1279+ container={
1280+ "skills": [{"type": "anthropic", "skill_id": "pptx", "version": "latest"}]
1281+ },
1282+ ).bind_tools([{"type": "code_execution_20260521", "name": "code_execution"}])
1283+ ```
1284+
1285+ Can also be passed at call time, which overrides the value set here.
1286+ """
1287+
12581288 reuse_last_container : bool | None = None
12591289 """Automatically reuse container from most recent response (code execution).
12601290
@@ -1582,6 +1612,7 @@ def _get_request_payload(
15821612 "betas" : self .betas ,
15831613 "context_management" : self .context_management ,
15841614 "mcp_servers" : self .mcp_servers ,
1615+ "container" : self .container ,
15851616 "user_profile_id" : self .user_profile_id ,
15861617 "system" : system ,
15871618 ** self .model_kwargs ,
@@ -1667,19 +1698,43 @@ def _get_request_payload(
16671698 output_config = payload .setdefault ("output_config" , {})
16681699 output_config ["format" ] = payload .pop ("output_format" )
16691700
1670- if self .reuse_last_container :
1671- # Check for most recent AIMessage with container set in response_metadata
1672- # and set as a top-level param on the request
1701+ container = payload .get ("container" )
1702+
1703+ if self .reuse_last_container and not _container_id (container ):
1704+ # Reuse the container from the most recent response (code execution)
16731705 for message in reversed (messages ):
16741706 if (
16751707 isinstance (message , AIMessage )
1676- and (container := message .response_metadata .get ("container" ))
1677- and isinstance (container , dict )
1678- and (container_id := container .get ("id" ))
1708+ and isinstance (
1709+ last_container := message .response_metadata .get ("container" ),
1710+ dict ,
1711+ )
1712+ and (container_id := last_container .get ("id" ))
16791713 ):
1680- payload ["container" ] = container_id
1714+ payload ["container" ] = (
1715+ {** container , "id" : container_id }
1716+ if isinstance (container , dict )
1717+ else container_id
1718+ )
16811719 break
16821720
1721+ if (
1722+ isinstance (container , dict )
1723+ and container .get ("skills" )
1724+ and not any (
1725+ isinstance (tool , dict )
1726+ and str (tool .get ("type" , "" )).startswith ("code_execution" )
1727+ for tool in (payload .get ("tools" ) or [])
1728+ )
1729+ ):
1730+ warnings .warn (
1731+ "Skills require a code execution tool to be bound, e.g. "
1732+ '`bind_tools([{"type": "code_execution_20260521", '
1733+ '"name": "code_execution"}])`.' ,
1734+ UserWarning ,
1735+ stacklevel = 2 ,
1736+ )
1737+
16831738 # Note: Beta headers are no longer required for structured outputs
16841739 # (output_config.format or strict tool use) as they are now generally available
16851740 if "tools" in payload and isinstance (payload ["tools" ], list ):
@@ -1731,6 +1786,16 @@ def _get_request_payload(
17311786 else :
17321787 payload ["betas" ] = [required_beta ]
17331788
1789+ # Auto-append required beta for the `updates` thinking display mode
1790+ thinking = payload .get ("thinking" )
1791+ if isinstance (thinking , dict ) and thinking .get ("display" ) == "updates" :
1792+ required_beta = "thinking-display-updates-2026-08-18"
1793+ if payload .get ("betas" ):
1794+ if required_beta not in payload ["betas" ]:
1795+ payload ["betas" ] = [* payload ["betas" ], required_beta ]
1796+ else :
1797+ payload ["betas" ] = [required_beta ]
1798+
17341799 # Auto-append required beta for user_profile_id
17351800 if payload .get ("user_profile_id" ):
17361801 required_beta = "user-profiles-2026-03-24"
0 commit comments