ai icon indicating copy to clipboard operation
ai copied to clipboard

Support for Anthropic-defined tools

Open Kitenite opened this issue 1 year ago • 10 comments

Feature Description

Anthropic provider has defined tools that can be passed in the following format:

tools: [
      {
        type: "computer_20250124",
        name: "computer",
        display_width_px: 1024,
        display_height_px: 768,
        display_number: 1,
      },
      {
        type: "text_editor_20250124",
        name: "str_replace_editor"
      },
      {
        type: "bash_20250124",
        name: "bash"
      },
// Other tools
]

https://docs.anthropic.com/en/docs/agents-and-tools/computer-use#understand-anthropic-defined-tools

Is there a way to pass type and name similarly and still define the tool handler?

Use Cases

Useful for using Anthropic-defined tools like computer use, bash, text editing while still using vercel AI SDK

Additional context

https://docs.anthropic.com/en/docs/agents-and-tools/computer-use#combine-computer-use-with-other-tools

Kitenite avatar Mar 15 '25 07:03 Kitenite

@Kitenite Hi, just ran recently into the same. Here you go - https://sdk.vercel.ai/docs/guides/computer-use#get-started-with-computer-use

Basically, its a bit abstracted, so should make it easier to use

Necromant1k avatar Mar 15 '25 07:03 Necromant1k

@Necromant1k You're a lifesaver. I've been trying to get this working all night!

Kitenite avatar Mar 15 '25 07:03 Kitenite

Seems like no support for text_editor_20250124 for claude 3.7 just yet?

Kitenite avatar Mar 15 '25 08:03 Kitenite

@Kitenite There is, make sure you update to 1.1.17 of anthropic sdk.

Secondly, i found that when you have maxSteps set, 3.7 not able to work properly. So i went with text_editor_2024... and 3.5 sonnet. Works so far

Necromant1k avatar Mar 15 '25 08:03 Necromant1k

Ah I see, I updated ai but not @ai-sdk/anthropic. Much appreciated, @Necromant1k !

Kitenite avatar Mar 15 '25 08:03 Kitenite

Seems like the implementation for text_editor_20250124 is incorrect.

The parameters passed in to the tool calls are:

 {
         "name": "strReplaceEditor",
          "type": "text_editor_20250124"
  }

Whereas it should be:

 {
         "name": "str_replace_editor",
          "type": "text_editor_20250124"
  }

Which is causing an error from Anthropic:

"error": {
         "type": "invalid_request_error",
         "message": "tools.2.text_editor_20250124.name: Input should be 'str_replace_editor'"
  }

Kitenite avatar Mar 15 '25 08:03 Kitenite

@Kitenite Do it like so

const result = await generateText({
      maxSteps: 5,
      // other props
      tools: {
        str_replace_editor: textEditorTool,
      },
    });

Necromant1k avatar Mar 15 '25 08:03 Necromant1k

I see, my mistake. Thanks again haha I owe you a beer for all this :D @Necromant1k

Kitenite avatar Mar 15 '25 08:03 Kitenite

Thanks @Necromant1k !

There are also additional docs here in case it's helpful: https://sdk.vercel.ai/providers/ai-sdk-providers/anthropic#computer-use

lgrammel avatar Mar 17 '25 08:03 lgrammel

Identify issue type

Identified as None
Confidence: High

Rationale

This is a support/configuration question about an already supported capability, not a product defect or request for new functionality.

Evidence

  • The reporter asks how to configure Anthropic-defined tools while retaining tool handlers.
  • Comments point to existing AI SDK computer-use and Anthropic provider documentation.
  • The reported text-editor naming error was resolved by using the tool key str_replace_editor; the reporter acknowledged it was their mistake.

lgrammel avatar Jul 22 '26 15:07 lgrammel