Execute tool (AI agents)
Use executeTool
to apply a tool call from your AI agent to the editor.
Once you've added tool definitions to your AI agent, the AI agent will generate tool calls. Use the executeTool
method to apply the tool calls to the editor.
executeTool
Executes a supported tool by name and input.
Parameters
options
(ExecuteToolOptions
): Configuration for tool executiontoolName
(string
): Tool to execute. Can be one of the available tools.input
(unknown
): Tool-specific input payloadcurrentChunk
(number
): Current chunk index when reading/editing chunked contentreviewOptions?
(ReviewOptions
): Control preview/review behaviormode?
('disabled' | 'review' | 'preview'
): Whether to review the changes before or after applying them.'disabled'
means no review,'review'
means review after applying,'preview'
means preview before applying. Default:'disabled'
showDiff?
(boolean
): Whether to diff the documents before and after the change to display the change as a detailed diff. Default:false
displayOptions?
(DisplayOptions<{ suggestion: Suggestion }>
): Customize how suggestions are displayedshowAsDiff?
(boolean
): Whether to show the suggestion as a diff where inserted and original content are displayed side by side. Default:true
diffPosition?
('before' | 'after'
): The position of the diff relative to the suggestion. Default:'before'
attributes?
(Record<string, any>
): Extra HTML attributes to be added to the suggestionrenderDecorations?
(RenderDecorations<{ suggestion: Suggestion }>
): A function to render the suggestion as ProseMirror decorations
Returns (ExecuteToolResult
)
output
(string
): Response message from the tool execution, to be read by the AI agent.hasError
(boolean
): Whether there was an error during executioncurrentChunk
(number
): The current chunk index after execution, may be updated by some toolsunknownTool
(boolean
): Whether thetoolName
is not recognized by the AI ToolkitdocChanged
(boolean
): Whether the tool call modifies the document.
Example
// Handle the insertContent tool call
const result = toolkit.executeTool({
toolName: 'insertContent',
input: {
html: '<p>Inserted content</p>',
position: 'documentEnd',
},
currentChunk: 0,
})
For a complete hands-on tutorial, see the AI agent chatbot guide.