Skip to content

Commit 4215a94

Browse files
authored
Merge pull request #1104 from narengogi/fix/anthropic-multi-turn-tool-calls
fix multi turn tool calling for anthropic when arguments to the tool call is an empty object
2 parents 219ac9d + 51adaf8 commit 4215a94

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/providers/anthropic/chatComplete.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ interface AnthropicTool extends PromptCache {
3232
}
3333
>;
3434
required: string[];
35+
$defs: Record<string, any>;
3536
};
3637
type?: string;
3738
display_width_px?: number;
@@ -134,7 +135,9 @@ const transformAssistantMessage = (msg: Message): AnthropicMessage => {
134135
type: 'tool_use',
135136
name: toolCall.function.name,
136137
id: toolCall.id,
137-
input: JSON.parse(toolCall.function.arguments),
138+
input: toolCall.function.arguments?.length
139+
? JSON.parse(toolCall.function.arguments)
140+
: {},
138141
});
139142
});
140143
}
@@ -340,6 +343,7 @@ export const AnthropicChatCompleteConfig: ProviderConfig = {
340343
type: tool.function.parameters?.type || 'object',
341344
properties: tool.function.parameters?.properties || {},
342345
required: tool.function.parameters?.required || [],
346+
$defs: tool.function.parameters?.['$defs'] || {},
343347
},
344348
...(tool.cache_control && {
345349
cache_control: { type: 'ephemeral' },

0 commit comments

Comments
 (0)