Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit889cb6c

Browse files
authored
properly convert custom / mcp tools to anthropic cua format (#1103)
WhyCustom AI SDK tools and MCP integrations weren't working properly withAnthropic CUA - parameters were empty {} and tools weren't tracked.What Changed- Convert Zod schemas to JSON Schema before sending to Anthropic (usingzodToJsonSchema)- Track custom tool calls in the actions array- Silence "Unknown tool name" warnings for custom toolsTest PlanTested with examples file. Parameters passed correctly ({"city":"San Francisco"} instead of {})Custom tools execute and appear in actions arrayNo warnings
1 parente0e6b30 commit889cb6c

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

‎.changeset/short-mirrors-switch.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand":patch
3+
---
4+
5+
patch custom tool support in anthropic cua client

‎lib/agent/AnthropicCUAClient.ts‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { LogLine } from "@/types/log";
1313
import{AgentScreenshotProviderError}from"@/types/stagehandErrors";
1414
importAnthropicfrom"@anthropic-ai/sdk";
1515
import{ToolSet}from"ai";
16+
import{zodToJsonSchema}from"zod-to-json-schema";
1617
import{AgentClient}from"./AgentClient";
1718
import{mapKeyToPlaywright}from"./utils/cuaKeyMapping";
1819
import{compressConversationImages}from"./utils/imageCompression";
@@ -275,6 +276,12 @@ export class AnthropicCUAClient extends AgentClient {
275276
level:2,
276277
});
277278
stepActions.push(action);
279+
}elseif(this.tools&&toolUseItem.nameinthis.tools){
280+
stepActions.push({
281+
type:"custom_tool",
282+
tool:toolUseItem.name,
283+
input:toolUseItem.input,
284+
}asAgentAction);
278285
}
279286
}elseif(block.type==="text"){
280287
// Safe to cast here since we've verified it's a text block
@@ -436,17 +443,16 @@ export class AnthropicCUAClient extends AgentClient {
436443
if(this.tools&&Object.keys(this.tools).length>0){
437444
constcustomTools=Object.entries(this.tools).map(([name,tool])=>{
438445
// Convert Zod schema to proper JSON schema format for Anthropic
439-
letinputSchema=tool.parameters;
440-
441-
// Ensure the schema has the required 'type' field at root level
442-
if(typeofinputSchema==="object"&&inputSchema!==null){
443-
if(!("type"ininputSchema)){
444-
inputSchema={
445-
type:"object",
446-
...inputSchema,
447-
};
448-
}
449-
}
446+
constjsonSchema=zodToJsonSchema(tool.parameters)as{
447+
properties?:Record<string,unknown>;
448+
required?:string[];
449+
};
450+
451+
constinputSchema={
452+
type:"object",
453+
properties:jsonSchema.properties||{},
454+
required:jsonSchema.required||[],
455+
};
450456

451457
return{
452458
name,
@@ -890,6 +896,8 @@ export class AnthropicCUAClient extends AgentClient {
890896
type:name,
891897
params:input,
892898
};
899+
}elseif(this.tools&&nameinthis.tools){
900+
returnnull;
893901
}
894902

895903
console.warn(`Unknown tool name:${name}`);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp