Skip to content

Commit 0ea1111

Browse files
authored
feat(anthropic): Add support for container reuse for code execution (#9109)
1 parent 073e977 commit 0ea1111

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

libs/providers/langchain-anthropic/src/chat_models.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ export interface ChatAnthropicCallOptions
6363
* when making a request.
6464
*/
6565
headers?: Record<string, string>;
66+
/**
67+
* Container ID for file persistence across turns with code execution.
68+
* Used with the code_execution_20250825 tool.
69+
*/
70+
container?: string;
6671
}
6772

6873
function _toolsInParams(
@@ -868,6 +873,7 @@ export class ChatAnthropicMessages<
868873
thinking: this.thinking,
869874
context_management: this.contextManagement,
870875
...this.invocationKwargs,
876+
container: options?.container,
871877
};
872878
}
873879
return {
@@ -883,6 +889,7 @@ export class ChatAnthropicMessages<
883889
thinking: this.thinking,
884890
context_management: this.contextManagement,
885891
...this.invocationKwargs,
892+
container: options?.container,
886893
};
887894
}
888895

libs/providers/langchain-anthropic/src/tests/chat_models.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,44 @@ test("Can properly format anthropic messages when given two tool results", async
192192
});
193193
});
194194

195+
test("invocationParams includes container when provided in call options", () => {
196+
const model = new ChatAnthropic({
197+
modelName: "claude-3-haiku-20240307",
198+
temperature: 0,
199+
anthropicApiKey: "testing",
200+
});
201+
202+
const params = model.invocationParams({ container: "container_123" });
203+
204+
expect(params.container).toBe("container_123");
205+
});
206+
207+
test("invocationParams does not include container when not provided", () => {
208+
const model = new ChatAnthropic({
209+
modelName: "claude-3-haiku-20240307",
210+
temperature: 0,
211+
anthropicApiKey: "testing",
212+
});
213+
214+
const params = model.invocationParams({});
215+
216+
expect(params.container).toBeUndefined();
217+
});
218+
219+
test("invocationParams includes container with thinking enabled", () => {
220+
const model = new ChatAnthropic({
221+
modelName: "claude-3-haiku-20240307",
222+
temperature: 1,
223+
anthropicApiKey: "testing",
224+
thinking: { type: "enabled", budget_tokens: 1000 },
225+
});
226+
227+
const params = model.invocationParams({ container: "container_456" });
228+
229+
expect(params.container).toBe("container_456");
230+
expect(params.thinking).toEqual({ type: "enabled", budget_tokens: 1000 });
231+
});
232+
195233
test("Can properly format messages with container_upload blocks", async () => {
196234
const messageHistory = [
197235
new HumanMessage({

0 commit comments

Comments
 (0)