Anthropic - AI agent tools
The @tiptap-pro/ai-toolkit-anthropic
package provides tool definitions you can add to your AI agent built with Anthropic's JavaScript SDK.
The tool calls generated by the model can then be executed in the client-side using the executeTool
method.
Example usage
Install the package.
npm install @tiptap-pro/ai-toolkit-anthropic
Supply the tool definitions to your Anthropic model.
import Anthropic from '@anthropic-ai/sdk'
import { toolDefinitions } from '@tiptap-pro/ai-toolkit-anthropic'
const anthropic = new Anthropic()
const response = await anthropic.messages.create({
model: 'claude-sonnet-4-5',
max_tokens: 2048,
system: 'You are a helpful assistant that can edit rich text documents.',
messages: [{ role: 'user', content: 'Help me edit this document' }],
tools: toolDefinitions(),
})
Combine the tool definitions with your custom tools.
import Anthropic from '@anthropic-ai/sdk'
import { toolDefinitions } from '@tiptap-pro/ai-toolkit-anthropic'
const anthropic = new Anthropic()
const customTools = [
{
name: 'get_weather',
description: 'Get the weather in a location',
input_schema: {
type: 'object',
properties: {
location: {
type: 'string',
description: 'The city and state, e.g. San Francisco, CA',
},
},
required: ['location'],
},
},
]
const response = await anthropic.messages.create({
model: 'claude-sonnet-4-5',
max_tokens: 1024,
messages: [{ role: 'user', content: 'What is the weather like and help me edit this document' }],
tools: [...toolDefinitions(), ...customTools],
})
API reference
toolDefinitions
Creates tool definitions for the Tiptap AI Toolkit compatible with Anthropic's Messages API.
Parameters (ToolDefinitionsOptions
)
tools?
:EnabledTools
- Enable/disable specific tools by setting the value totrue
(enabled) orfalse
(disabled).insertContent?
:boolean
- Enable/disable theinsertContent
tool (default:true
)applyDiff?
:boolean
- Enable/disable theapplyDiff
tool (default:true
)readNodeRange?
:boolean
- Enable/disable thereadNodeRange
tool (default:true
)readSelection?
:boolean
- Enable/disable thereadSelection
tool (default:true
)
Returns
An array containing the enabled tool definitions that can be used with Anthropic's Messages API. The returned array includes:
insertContent
- Tool for inserting HTML content at a specific positionapplyDiff
- Tool for applying targeted edits via diffsreadNodeRange
- Tool for reading part of the document by specifying a range of top-level nodesreadSelection
- Tool for reading the currently selected content in the editor