---
title: "LangChain.js - AI 代理工具"
description: "使用适用于 LangChain.js 的工具定义，让 AI 代理读取并编辑 Tiptap 文档。"
canonical_url: "https://tiptap.zhcndoc.com/ai/ai-toolkit/client/agents/tools/langchain-js"
---

# LangChain.js - AI 代理工具

使用适用于 LangChain.js 的工具定义，让 AI 代理读取并编辑 Tiptap 文档。

`@tiptap-pro/ai-toolkit-langchain` 包提供了可以添加到你使用 [LangChain.js](https://js.langchain.com/) 构建的 AI 代理中的工具定义。

模型生成的工具调用随后可以在客户端使用 [`executeTool` 方法](https://tiptap.zhcndoc.com/ai/ai-toolkit/client/api-reference/execute-tool.md) 执行。

## Example Usage

Install the package.

```bash
npm install @tiptap-pro/ai-toolkit-langchain
```

Provide the tool definitions to your LangChain.js model.

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

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

Combine the tool definitions with your custom tools.

```ts
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-5.4-mini' })

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

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

## API 参考

### `toolDefinitions`

为 Tiptap AI 工具包创建与 [LangChain.js](https://js.langchain.com/) 兼容的工具定义。

#### 参数 (`ToolDefinitionsOptions`)

- `tools?`: `EnabledTools` - 通过将值设置为 `true`（启用）或 `false`（禁用）来启用或禁用特定工具。
  - `tiptapRead?`: `boolean` - 启用/禁用 `tiptapRead` 工具（默认：`true`）
  - `tiptapEdit?`: `boolean` - 启用/禁用 `tiptapEdit` 工具（默认：`true`）
  - `tiptapReadSelection?`: `boolean` - 启用/禁用 `tiptapReadSelection` 工具（默认：`true`）
  - `getThreads?`: `boolean` - 启用/禁用 `getThreads` 工具（默认：`false`）
  - `editThreads?`: `boolean` - 启用/禁用 `editThreads` 工具（默认：`false`）

#### 返回值

一个包含已启用工具定义的数组，可用于 [LangChain.js](https://js.langchain.com/) 的工具调用系统。有关完整工具列表，请参阅 [可用工具](https://tiptap.zhcndoc.com/ai/ai-toolkit/client/agents/tools.md) 页面。
