LangChain.js - AI agent tools

The @tiptap-pro/ai-toolkit-langchain package provides tool definitions you can add to your AI agent built with LangChain.js.

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-langchain

Supply the tool definitions to your LangChain.js model.

import { ChatOpenAI } from '@langchain/openai'
import { toolDefinitions } from '@tiptap-pro/ai-toolkit-langchain'

const llm = new ChatOpenAI({ model: 'gpt-5' })
const llmWithTools = llm.bindTools(toolDefinitions())

Combine the tool definitions with your custom tools.

import { ChatOpenAI } from '@langchain/openai'
import { toolDefinitions } from '@tiptap-pro/ai-toolkit-langchain'
import { DynamicStructuredTool } from '@langchain/core/tools'
import { z } from 'zod'

const llm = new ChatOpenAI({ model: 'gpt-4' })

const customTools = [
  new DynamicStructuredTool({
    name: 'weather',
    description: 'Get the weather in a location',
    schema: z.object({
      location: z.string(),
    }),
    func: async ({ location }) => {
      return `The weather in ${location} is sunny with 72°F`
    },
  }),
]

const llmWithTools = llm.bindTools([...toolDefinitions(), ...customTools])

API reference

toolDefinitions

Creates tool definitions for the Tiptap AI Toolkit compatible with LangChain.js.

Parameters (ToolDefinitionsOptions)

  • tools?: EnabledTools - Enable/disable specific tools. All tools are enabled by default.
    • insertContent?: boolean - Enable/disable the insertContent tool (default: true)
    • applyDiff?: boolean - Enable/disable the applyDiff tool (default: true)
    • readFirstChunk?: boolean - Enable/disable the readFirstChunk tool (default: true)
    • readNextChunk?: boolean - Enable/disable the readNextChunk tool (default: true)
    • readPreviousChunk?: boolean - Enable/disable the readPreviousChunk tool (default: true)
    • readSelection?: boolean - Enable/disable the readSelection tool (default: true)

Returns

An array containing the enabled tool definitions that can be used with LangChain.js's tool calling system. The returned array includes:

  • insertContent - Tool for inserting HTML content at a specific position
  • applyDiff - Tool for applying targeted edits via diffs
  • readFirstChunk - Tool for reading the first chunk of the document
  • readNextChunk - Tool for reading the next chunk of the document
  • readPreviousChunk - Tool for reading the previous chunk of the document
  • readSelection - Tool for reading the currently selected content in the editor