工具体系 (Tools)
将 Deep Agents 连接到自定义函数、API、数据库和任何 MCP 服务器
Deep Agents 可以调用你定义的任何工具、任何 LangChain 工具 以及来自任何 MCP 服务器 的工具。 通过 tools= 参数将它们传递给 create_deep_agent,与用于文件管理和子智能体衍生的内置运行框架工具并排工作。
import { createDeepAgent } from "deepagents";
const agent = await createDeepAgent({
model: "google:gemini-3.6-flash",
tools: [search, fetchUrl, runQuery],
});自定义工具 (Custom tools)
将任何可调用对象(例如普通函数、经 LangChain tool 包装的函数或工具对象)直接传递给 tools=。 Deep Agents 会从函数签名和 Zod Schema 中推导工具模式,因此在大多数情况下你无需单独编写繁琐的模式描述。
import { createDeepAgent } from "deepagents";
const agent = await createDeepAgent({
model: "openai:gpt-5.5",
tools: [search, fetchUrl, runQuery],
});MCP 工具 (MCP tools)
Deep Agents 原生完全支持模型上下文协议(Model Context Protocol, MCP)工具。 安装 @langchain/mcp-adapters 并使用 MultiServerMCPClient 连接到本地或远程 MCP 服务器:
import { createDeepAgent } from "deepagents";
const agent = await createDeepAgent({
model: "anthropic:claude-sonnet-5",
tools: [search, fetchUrl, runQuery],
});内置运行框架工具 (Built-in harness tools)
Deep Agents 默认内置了一组文件系统工具和子智能体衍生工具:
| 工具名称 | 描述说明 |
|---|---|
ls | 列出目录中的文件及其大小、修改时间等元数据 |
read_file | 读取文件内容并附带行号,大文件支持 offset/limit 切片读取,支持多模态内容 |
write_file | 创建或完全覆盖写入文件 |
edit_file | 对目标文件执行精确的字符串替换(支持多处替换模式) |
glob | 按照 Glob 模式递归搜索文件路径匹配 |
grep | 搜索文件内容,支持正则和行号定位 |
execute | 在隔离环境中执行 Shell 命令(仅在配置了沙箱后端时可用) |
task | 衍生短暂子智能体,用于隔离执行耗时或并行的繁重子任务 |
若要自定义或隐藏某些默认工具,请参阅框架配置文件 (Harness profiles)。
多模态工具输出 (Multimodal tool outputs)
工具不仅可以返回文本字符串,还可以直接返回图像、音频、视频或文件等富媒体内容。 有关如何从自定义工具返回多模态数据块并在前端流式渲染,请参阅多模态输入与输出。
import { createDeepAgent } from "deepagents";
const agent = await createDeepAgent({
model: "openrouter:z-ai/glm-5.2",
tools: [search, fetchUrl, runQuery],
});import { createDeepAgent } from "deepagents";
const agent = await createDeepAgent({
model: "fireworks:accounts/fireworks/models/glm-5p2",
tools: [search, fetchUrl, runQuery],
});import { createDeepAgent } from "deepagents";
const agent = await createDeepAgent({
model: "baseten:zai-org/GLM-5.2",
tools: [search, fetchUrl, runQuery],
});import { createDeepAgent } from "deepagents";
const agent = await createDeepAgent({
model: "ollama:north-mini-code-1.0",
tools: [search, fetchUrl, runQuery],
});Custom tools
Pass any callable, such as plain functions, LangChain @tool-decorated functions, or tool dicts—directly to tools=. Deep Agents infers the tool schema from the function signature and docstring, so you don't need to define a separate schema in most cases.
import { tool } from "langchain";
import { TavilySearch } from "@langchain/tavily";
import { createDeepAgent } from "deepagents";
import { z } from "zod";
const internetSearch = tool(
async ({
query,
maxResults = 5,
topic = "general",
includeRawContent = false,
}: {
query: string;
maxResults?: number;
topic?: "general" | "news" | "finance";
includeRawContent?: boolean;
}) => {
const tavilySearch = new TavilySearch({
maxResults,
tavilyApiKey: process.env.TAVILY_API_KEY,
includeRawContent,
topic,
});
return await tavilySearch._call({ query });
},
{
name: "internet_search",
description: "Run a web search",
schema: z.object({
query: z.string().describe("The search query"),
maxResults: z.number().optional().default(5),
topic: z
.enum(["general", "news", "finance"])
.optional()
.default("general"),
includeRawContent: z.boolean().optional().default(false),
}),
},
);
const agent = createDeepAgent({
model: "google:gemini-3.6-flash",
tools: [internetSearch],
});import { tool } from "langchain";
import { TavilySearch } from "@langchain/tavily";
import { createDeepAgent } from "deepagents";
import { z } from "zod";
const internetSearch = tool(
async ({
query,
maxResults = 5,
topic = "general",
includeRawContent = false,
}: {
query: string;
maxResults?: number;
topic?: "general" | "news" | "finance";
includeRawContent?: boolean;
}) => {
const tavilySearch = new TavilySearch({
maxResults,
tavilyApiKey: process.env.TAVILY_API_KEY,
includeRawContent,
topic,
});
return await tavilySearch._call({ query });
},
{
name: "internet_search",
description: "Run a web search",
schema: z.object({
query: z.string().describe("The search query"),
maxResults: z.number().optional().default(5),
topic: z
.enum(["general", "news", "finance"])
.optional()
.default("general"),
includeRawContent: z.boolean().optional().default(false),
}),
},
);
const agent = createDeepAgent({
model: "openai:gpt-5.5",
tools: [internetSearch],
});import { tool } from "langchain";
import { TavilySearch } from "@langchain/tavily";
import { createDeepAgent } from "deepagents";
import { z } from "zod";
const internetSearch = tool(
async ({
query,
maxResults = 5,
topic = "general",
includeRawContent = false,
}: {
query: string;
maxResults?: number;
topic?: "general" | "news" | "finance";
includeRawContent?: boolean;
}) => {
const tavilySearch = new TavilySearch({
maxResults,
tavilyApiKey: process.env.TAVILY_API_KEY,
includeRawContent,
topic,
});
return await tavilySearch._call({ query });
},
{
name: "internet_search",
description: "Run a web search",
schema: z.object({
query: z.string().describe("The search query"),
maxResults: z.number().optional().default(5),
topic: z
.enum(["general", "news", "finance"])
.optional()
.default("general"),
includeRawContent: z.boolean().optional().default(false),
}),
},
);
const agent = createDeepAgent({
model: "anthropic:claude-sonnet-5",
tools: [internetSearch],
});import { tool } from "langchain";
import { TavilySearch } from "@langchain/tavily";
import { createDeepAgent } from "deepagents";
import { z } from "zod";
const internetSearch = tool(
async ({
query,
maxResults = 5,
topic = "general",
includeRawContent = false,
}: {
query: string;
maxResults?: number;
topic?: "general" | "news" | "finance";
includeRawContent?: boolean;
}) => {
const tavilySearch = new TavilySearch({
maxResults,
tavilyApiKey: process.env.TAVILY_API_KEY,
includeRawContent,
topic,
});
return await tavilySearch._call({ query });
},
{
name: "internet_search",
description: "Run a web search",
schema: z.object({
query: z.string().describe("The search query"),
maxResults: z.number().optional().default(5),
topic: z
.enum(["general", "news", "finance"])
.optional()
.default("general"),
includeRawContent: z.boolean().optional().default(false),
}),
},
);
const agent = createDeepAgent({
model: "openrouter:z-ai/glm-5.2",
tools: [internetSearch],
});import { tool } from "langchain";
import { TavilySearch } from "@langchain/tavily";
import { createDeepAgent } from "deepagents";
import { z } from "zod";
const internetSearch = tool(
async ({
query,
maxResults = 5,
topic = "general",
includeRawContent = false,
}: {
query: string;
maxResults?: number;
topic?: "general" | "news" | "finance";
includeRawContent?: boolean;
}) => {
const tavilySearch = new TavilySearch({
maxResults,
tavilyApiKey: process.env.TAVILY_API_KEY,
includeRawContent,
topic,
});
return await tavilySearch._call({ query });
},
{
name: "internet_search",
description: "Run a web search",
schema: z.object({
query: z.string().describe("The search query"),
maxResults: z.number().optional().default(5),
topic: z
.enum(["general", "news", "finance"])
.optional()
.default("general"),
includeRawContent: z.boolean().optional().default(false),
}),
},
);
const agent = createDeepAgent({
model: "fireworks:accounts/fireworks/models/glm-5p2",
tools: [internetSearch],
});import { tool } from "langchain";
import { TavilySearch } from "@langchain/tavily";
import { createDeepAgent } from "deepagents";
import { z } from "zod";
const internetSearch = tool(
async ({
query,
maxResults = 5,
topic = "general",
includeRawContent = false,
}: {
query: string;
maxResults?: number;
topic?: "general" | "news" | "finance";
includeRawContent?: boolean;
}) => {
const tavilySearch = new TavilySearch({
maxResults,
tavilyApiKey: process.env.TAVILY_API_KEY,
includeRawContent,
topic,
});
return await tavilySearch._call({ query });
},
{
name: "internet_search",
description: "Run a web search",
schema: z.object({
query: z.string().describe("The search query"),
maxResults: z.number().optional().default(5),
topic: z
.enum(["general", "news", "finance"])
.optional()
.default("general"),
includeRawContent: z.boolean().optional().default(false),
}),
},
);
const agent = createDeepAgent({
model: "baseten:zai-org/GLM-5.2",
tools: [internetSearch],
});import { tool } from "langchain";
import { TavilySearch } from "@langchain/tavily";
import { createDeepAgent } from "deepagents";
import { z } from "zod";
const internetSearch = tool(
async ({
query,
maxResults = 5,
topic = "general",
includeRawContent = false,
}: {
query: string;
maxResults?: number;
topic?: "general" | "news" | "finance";
includeRawContent?: boolean;
}) => {
const tavilySearch = new TavilySearch({
maxResults,
tavilyApiKey: process.env.TAVILY_API_KEY,
includeRawContent,
topic,
});
return await tavilySearch._call({ query });
},
{
name: "internet_search",
description: "Run a web search",
schema: z.object({
query: z.string().describe("The search query"),
maxResults: z.number().optional().default(5),
topic: z
.enum(["general", "news", "finance"])
.optional()
.default("general"),
includeRawContent: z.boolean().optional().default(false),
}),
},
);
const agent = createDeepAgent({
model: "ollama:north-mini-code-1.0",
tools: [internetSearch],
});For full details on defining and using LangChain tools (tool dicts, StructuredTool, return types, error handling, and more), see Tools.
MCP tools
NOTE
Deep Agents fully support Model Context Protocol (MCP), the open standard for connecting agents to external services. Load tools from any MCP server and pass them directly to create_deep_agent.
MCP is an open protocol that lets agents connect to a growing ecosystem of servers—databases, APIs, file systems, browsers, and more—through a standard interface. Instead of writing custom integration code for each service, you point Deep Agents at an MCP server and it gets all the tools that server exposes.
Install @langchain/mcp-adapters to connect to MCP servers:
npm install @langchain/mcp-adaptersimport { createDeepAgent } from "deepagents";
const { MultiServerMCPClient } = await import("@langchain/mcp-adapters");
const client = new MultiServerMCPClient({
my_server: {
transport: "http",
url: "http://localhost:8000/mcp",
},
});
const tools = await client.getTools();
const agent = await createDeepAgent({
model: "google:gemini-3.6-flash",
tools,
});
const result = await agent.invoke({
messages: [{ role: "user", content: "Use the MCP server to help me." }],
});import { createDeepAgent } from "deepagents";
const { MultiServerMCPClient } = await import("@langchain/mcp-adapters");
const client = new MultiServerMCPClient({
my_server: {
transport: "http",
url: "http://localhost:8000/mcp",
},
});
const tools = await client.getTools();
const agent = await createDeepAgent({
model: "openai:gpt-5.5",
tools,
});
const result = await agent.invoke({
messages: [{ role: "user", content: "Use the MCP server to help me." }],
});import { createDeepAgent } from "deepagents";
const { MultiServerMCPClient } = await import("@langchain/mcp-adapters");
const client = new MultiServerMCPClient({
my_server: {
transport: "http",
url: "http://localhost:8000/mcp",
},
});
const tools = await client.getTools();
const agent = await createDeepAgent({
model: "anthropic:claude-sonnet-5",
tools,
});
const result = await agent.invoke({
messages: [{ role: "user", content: "Use the MCP server to help me." }],
});import { createDeepAgent } from "deepagents";
const { MultiServerMCPClient } = await import("@langchain/mcp-adapters");
const client = new MultiServerMCPClient({
my_server: {
transport: "http",
url: "http://localhost:8000/mcp",
},
});
const tools = await client.getTools();
const agent = await createDeepAgent({
model: "openrouter:z-ai/glm-5.2",
tools,
});
const result = await agent.invoke({
messages: [{ role: "user", content: "Use the MCP server to help me." }],
});import { createDeepAgent } from "deepagents";
const { MultiServerMCPClient } = await import("@langchain/mcp-adapters");
const client = new MultiServerMCPClient({
my_server: {
transport: "http",
url: "http://localhost:8000/mcp",
},
});
const tools = await client.getTools();
const agent = await createDeepAgent({
model: "fireworks:accounts/fireworks/models/glm-5p2",
tools,
});
const result = await agent.invoke({
messages: [{ role: "user", content: "Use the MCP server to help me." }],
});import { createDeepAgent } from "deepagents";
const { MultiServerMCPClient } = await import("@langchain/mcp-adapters");
const client = new MultiServerMCPClient({
my_server: {
transport: "http",
url: "http://localhost:8000/mcp",
},
});
const tools = await client.getTools();
const agent = await createDeepAgent({
model: "baseten:zai-org/GLM-5.2",
tools,
});
const result = await agent.invoke({
messages: [{ role: "user", content: "Use the MCP server to help me." }],
});import { createDeepAgent } from "deepagents";
const { MultiServerMCPClient } = await import("@langchain/mcp-adapters");
const client = new MultiServerMCPClient({
my_server: {
transport: "http",
url: "http://localhost:8000/mcp",
},
});
const tools = await client.getTools();
const agent = await createDeepAgent({
model: "ollama:north-mini-code-1.0",
tools,
});
const result = await agent.invoke({
messages: [{ role: "user", content: "Use the MCP server to help me." }],
});For detailed configuration options—including stdio servers, OAuth authentication, tool filtering, and stateful sessions—see the full MCP guide.
Built-in harness tools
In addition to the tools you provide, every Deep Agent comes with a built-in set of tools from the harness:
| Tool | Description |
|---|---|
ls | List files in a directory. |
read_file | Read file contents (with pagination and multimodal support). |
write_file | Create new files. |
edit_file | Perform exact string replacements in files. |
glob | Find files matching a glob pattern. |
grep | Search file contents. |
execute | Run shell commands (sandbox backends only). |
task | Spawn a subagent to handle a delegated task. |
To add structured task planning with write_todos, opt in with TodoListMiddleware. See Task planning.
For a full breakdown of what each built-in tool does, see Harness overview.
Multimodal tool outputs
Custom tools can return plain text or standard content blocks (text, images, audio, video, and files) when the selected model supports multimodal tool results. The built-in read_file tool also returns multimodal blocks for supported non-text file types.
Return a string for text-only results, or an ordered list of content blocks for text plus media or interleaved multimodal output. See Multimodal and Tool return values for examples and context-compression considerations.
Connect these docs to your agent of choice via MCP for real-time answers.
