Skip to content

Commit bc20385

Browse files
committed
fix: do not set anthropic tool choice without tools
Makes sure to not hand over the 'tool_choice' parameter to the anthropic SDK if there are no tools to choose from. The SDK will throw an error otherwise. fixes #15327
1 parent f87cbfb commit bc20385

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/ai-anthropic/src/node/anthropic-language-model.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export class AnthropicModel implements LanguageModel {
155155
max_tokens: this.maxTokens,
156156
messages: [...messages, ...(toolMessages ?? [])],
157157
tools,
158-
tool_choice: { type: 'auto' },
158+
tool_choice: tools ? { type: 'auto' } : undefined,
159159
model: this.model,
160160
...(systemMessage && { system: systemMessage }),
161161
...settings
@@ -266,6 +266,9 @@ export class AnthropicModel implements LanguageModel {
266266
}
267267

268268
private createTools(request: LanguageModelRequest): Anthropic.Messages.Tool[] | undefined {
269+
if (request.tools?.length === 0) {
270+
return undefined;
271+
}
269272
return request.tools?.map(tool => ({
270273
name: tool.name,
271274
description: tool.description,

0 commit comments

Comments
 (0)