Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions libs/providers/langchain-anthropic/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export interface ChatAnthropicCallOptions
* when making a request.
*/
headers?: Record<string, string>;
/**
* Container ID for file persistence across turns with code execution.
* Used with the code_execution_20250825 tool.
*/
container?: string;
}

function _toolsInParams(
Expand Down Expand Up @@ -856,6 +861,7 @@ export class ChatAnthropicMessages<
tool_choice,
thinking: this.thinking,
...this.invocationKwargs,
container: options?.container,
};
}
return {
Expand All @@ -870,6 +876,7 @@ export class ChatAnthropicMessages<
tool_choice,
thinking: this.thinking,
...this.invocationKwargs,
container: options?.container,
};
}

Expand Down
38 changes: 38 additions & 0 deletions libs/providers/langchain-anthropic/src/tests/chat_models.test.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

am fine to keep this, but as commentary I'm not sure how much benefit we get from testing invocationParams directly (it's only part of the messages + options -> sdk payload "chain")

ideal state is the conversion logic of messages + options is collapsed into something like getRequestPayload and that's what we test (this is how python does it iirc). Not needed for this PR though.

ok I'll get off my soap box now

Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,41 @@ test("Can properly format anthropic messages when given two tool results", async
system: undefined,
});
});

test("invocationParams includes container when provided in call options", () => {
const model = new ChatAnthropic({
modelName: "claude-3-haiku-20240307",
temperature: 0,
anthropicApiKey: "testing",
});

const params = model.invocationParams({ container: "container_123" });

expect(params.container).toBe("container_123");
});

test("invocationParams does not include container when not provided", () => {
const model = new ChatAnthropic({
modelName: "claude-3-haiku-20240307",
temperature: 0,
anthropicApiKey: "testing",
});

const params = model.invocationParams({});

expect(params.container).toBeUndefined();
});

test("invocationParams includes container with thinking enabled", () => {
const model = new ChatAnthropic({
modelName: "claude-3-haiku-20240307",
temperature: 1,
anthropicApiKey: "testing",
thinking: { type: "enabled", budget_tokens: 1000 },
});

const params = model.invocationParams({ container: "container_456" });

expect(params.container).toBe("container_456");
expect(params.thinking).toEqual({ type: "enabled", budget_tokens: 1000 });
});