LangChain.js - AI 代理工具
@tiptap-pro/ai-toolkit-langchain 包提供了可以添加到你使用 LangChain.js 构建的 AI 代理中的工具定义。
模型生成的工具调用随后可以在客户端使用 executeTool 方法 执行。
Example Usage
Install the package.
npm install @tiptap-pro/ai-toolkit-langchainProvide 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.4-mini' })
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-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 兼容的工具定义。
参数 (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 的工具调用系统。有关完整工具列表,请参阅 可用工具 页面。