Skip to content

Commit 6c7eb84

Browse files
authored
fix(anthropic): fix sonnet-4.5 thinking (#9073)
1 parent 23a92ed commit 6c7eb84

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

.changeset/nice-memes-judge.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@langchain/anthropic": patch
3+
---
4+
5+
fix sonnet-4.5 thinking

libs/langchain-anthropic/src/chat_models.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ export class ChatAnthropicMessages<
849849
throw new Error("topK is not supported when thinking is enabled");
850850
}
851851
if (
852-
this.model.includes("opus-4-1")
852+
this.model.includes("opus-4-1") || this.model.includes("sonnet-4-5")
853853
? this.topP !== undefined
854854
: this.topP !== -1
855855
) {

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,4 +1503,20 @@ describe("Sonnet 4.5", () => {
15031503
);
15041504
expect(response.content.length).toBeGreaterThan(0);
15051505
});
1506+
1507+
it("works with streaming and thinking", async () => {
1508+
const model = new ChatAnthropic({
1509+
model: "claude-sonnet-4-5-20250929",
1510+
thinking: {
1511+
type: "enabled",
1512+
budget_tokens: 1024,
1513+
},
1514+
});
1515+
1516+
const response = await model.invoke(
1517+
"Please respond to this message simply with: Hello"
1518+
);
1519+
1520+
expect(response.content.length).toBeGreaterThan(0);
1521+
});
15061522
});

0 commit comments

Comments
 (0)