Skip to content

Commit 7e02057

Browse files
committed
fix: skip unknown tool_use blocks in Anthropic adapter to prevent crashes (CopilotKit#2504)
1 parent 789ab17 commit 7e02057

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

packages/runtime/src/service-adapters/anthropic/anthropic-adapter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ export class AnthropicAdapter implements CopilotServiceAdapter {
244244
forwardedParameters,
245245
} = request;
246246
const tools = actions.map(convertActionInputToAnthropicTool);
247+
const knownActionNames = new Set(actions.map((a) => a.name));
247248

248249
const messages = [...rawMessages];
249250

@@ -381,6 +382,11 @@ export class AnthropicAdapter implements CopilotServiceAdapter {
381382
filterThinkingTextBuffer.reset();
382383
mode = "message";
383384
} else if (chunk.content_block.type === "tool_use") {
385+
if (!knownActionNames.has(chunk.content_block.name)) {
386+
// Unknown tool - skip execution to prevent crashes
387+
mode = null;
388+
continue;
389+
}
384390
currentToolCallId = chunk.content_block.id;
385391
eventStream$.sendActionExecutionStart({
386392
actionExecutionId: currentToolCallId,

0 commit comments

Comments
 (0)