Mastra - AI agent tools
The @tiptap-pro/ai-toolkit-ai-sdk
package provides tool definitions you can add to your AI agent built with the Mastra AI Agent framework.
The tool calls generated by the model can then be executed using the executeTool
method.
Example usage
Install the package.
npm install @tiptap-pro/ai-toolkit-ai-sdk
Supply the tool definitions to the tools
parameter of your Mastra Agent.
import { Agent } from '@mastra/core/agent'
import { openai } from '@ai-sdk/openai'
import { toolDefinitions } from '@tiptap-pro/ai-toolkit-ai-sdk'
const agent = new Agent({
name: 'Tiptap AI Agent',
instructions: 'You are an AI assistant that can read and edit Tiptap documents.',
model: openai('gpt-4o-mini'),
tools: toolDefinitions(),
})
const result = await agent.generate('Read the document and summarize it')
Combine the tool definitions with your custom tools.
import { Agent } from '@mastra/core/agent'
import { openai } from '@ai-sdk/openai'
import { createTool } from '@mastra/core/tools'
import { toolDefinitions } from '@tiptap-pro/ai-toolkit-ai-sdk'
import { z } from 'zod'
// Custom weather tool using Mastra's createTool
const weatherTool = createTool({
id: 'Get Weather Information',
description: 'Get the weather in a location',
inputSchema: z.object({
location: z.string().describe('The location to get weather for'),
}),
outputSchema: z.object({
temperature: z.number(),
}),
execute: async ({ context: { location } }) => ({
temperature: 72,
}),
})
const agent = new Agent({
name: 'Tiptap AI Agent with Weather',
instructions:
'You are an AI assistant that can read and edit Tiptap documents and get weather information.',
model: openai('gpt-4o-mini'),
tools: {
// Tool definitions from the AI Toolkit
...toolDefinitions(),
// Custom weather tool
weather: weatherTool,
},
})
const result = await agent.generate('Read the document and get the weather in New York')
API reference
toolDefinitions
Creates tool definitions for the Tiptap AI Toolkit compatible with Mastra.
Parameters (ToolDefinitionsOptions
)
tools?
:EnabledTools
- Enable/disable specific tools by setting the value totrue
(enabled) orfalse
(disabled).insertContent?
:boolean
- Enable/disable theinsertContent
tool (default:true
)applyPatch?
:boolean
- Enable/disable theapplyPatch
tool (default:true
)readNodeRange?
:boolean
- Enable/disable thereadNodeRange
tool (default:true
)readSelection?
:boolean
- Enable/disable thereadSelection
tool (default:true
)
Returns
An object containing the enabled tool definitions that can be used with Mastra's tool calling system. The returned object includes:
insertContent
- Tool for inserting HTML content at a specific positionapplyPatch
- Tool for applying small precise edits to the documentreadNodeRange
- 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