本页还没有译文
本页 22 段还没译成한국어,下面显示的是英文原文。Tools
还没翻译译自英文(docs.langchain.com)本页 22 段都还没译
Deep Agents can call any tool you define, any LangChain tool, and tools from any MCP server.
Pass them to create_deep_agent via the tools= parameter alongside the built-in harness tools for file management and subagent spawning.
from deepagents import create_deep_agent
agent = create_deep_agent(
model="google_genai:gemini-3.6-flash",
tools=[search, fetch_url, run_query],
)from deepagents import create_deep_agent
agent = create_deep_agent(
model="openai:gpt-5.5",
tools=[search, fetch_url, run_query],
)from deepagents import create_deep_agent
agent = create_deep_agent(
model="anthropic:claude-sonnet-5",
tools=[search, fetch_url, run_query],
)from deepagents import create_deep_agent
agent = create_deep_agent(
model="openrouter:z-ai/glm-5.2",
tools=[search, fetch_url, run_query],
)from deepagents import create_deep_agent
agent = create_deep_agent(
model="fireworks:accounts/fireworks/models/glm-5p2",
tools=[search, fetch_url, run_query],
)from deepagents import create_deep_agent
agent = create_deep_agent(
model="baseten:zai-org/GLM-5.2",
tools=[search, fetch_url, run_query],
)from deepagents import create_deep_agent
agent = create_deep_agent(
model="ollama:north-mini-code-1.0",
tools=[search, fetch_url, run_query],
)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 os
from typing import Literal
from tavily import TavilyClient
from deepagents import create_deep_agent
tavily_client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])
def internet_search(
query: str,
max_results: int = 5,
topic: Literal["general", "news", "finance"] = "general",
include_raw_content: bool = False,
):
"""Run a web search"""
return tavily_client.search(
query,
max_results=max_results,
include_raw_content=include_raw_content,
topic=topic,
)
agent = create_deep_agent(
model="google_genai:gemini-3.6-flash",
tools=[internet_search],
)import os
from typing import Literal
from tavily import TavilyClient
from deepagents import create_deep_agent
tavily_client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])
def internet_search(
query: str,
max_results: int = 5,
topic: Literal["general", "news", "finance"] = "general",
include_raw_content: bool = False,
):
"""Run a web search"""
return tavily_client.search(
query,
max_results=max_results,
include_raw_content=include_raw_content,
topic=topic,
)
agent = create_deep_agent(
model="openai:gpt-5.5",
tools=[internet_search],
)import os
from typing import Literal
from tavily import TavilyClient
from deepagents import create_deep_agent
tavily_client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])
def internet_search(
query: str,
max_results: int = 5,
topic: Literal["general", "news", "finance"] = "general",
include_raw_content: bool = False,
):
"""Run a web search"""
return tavily_client.search(
query,
max_results=max_results,
include_raw_content=include_raw_content,
topic=topic,
)
agent = create_deep_agent(
model="anthropic:claude-sonnet-5",
tools=[internet_search],
)import os
from typing import Literal
from tavily import TavilyClient
from deepagents import create_deep_agent
tavily_client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])
def internet_search(
query: str,
max_results: int = 5,
topic: Literal["general", "news", "finance"] = "general",
include_raw_content: bool = False,
):
"""Run a web search"""
return tavily_client.search(
query,
max_results=max_results,
include_raw_content=include_raw_content,
topic=topic,
)
agent = create_deep_agent(
model="openrouter:z-ai/glm-5.2",
tools=[internet_search],
)import os
from typing import Literal
from tavily import TavilyClient
from deepagents import create_deep_agent
tavily_client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])
def internet_search(
query: str,
max_results: int = 5,
topic: Literal["general", "news", "finance"] = "general",
include_raw_content: bool = False,
):
"""Run a web search"""
return tavily_client.search(
query,
max_results=max_results,
include_raw_content=include_raw_content,
topic=topic,
)
agent = create_deep_agent(
model="fireworks:accounts/fireworks/models/glm-5p2",
tools=[internet_search],
)import os
from typing import Literal
from tavily import TavilyClient
from deepagents import create_deep_agent
tavily_client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])
def internet_search(
query: str,
max_results: int = 5,
topic: Literal["general", "news", "finance"] = "general",
include_raw_content: bool = False,
):
"""Run a web search"""
return tavily_client.search(
query,
max_results=max_results,
include_raw_content=include_raw_content,
topic=topic,
)
agent = create_deep_agent(
model="baseten:zai-org/GLM-5.2",
tools=[internet_search],
)import os
from typing import Literal
from tavily import TavilyClient
from deepagents import create_deep_agent
tavily_client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])
def internet_search(
query: str,
max_results: int = 5,
topic: Literal["general", "news", "finance"] = "general",
include_raw_content: bool = False,
):
"""Run a web search"""
return tavily_client.search(
query,
max_results=max_results,
include_raw_content=include_raw_content,
topic=topic,
)
agent = create_deep_agent(
model="ollama:north-mini-code-1.0",
tools=[internet_search],
)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 with the mcp extra to connect to MCP servers:
pip install "langchain[mcp]"uv add "langchain[mcp]"import asyncio
from deepagents import create_deep_agent
from langchain.mcp import MCPAdapter
async def main():
config = {"mcpServers": {"my_server": {"url": "http://localhost:8000/mcp"}}}
async with MCPAdapter(config) as adapter:
tools = await adapter.list_tools()
agent = create_deep_agent(
model="google_genai:gemini-3.6-flash",
tools=tools,
)
await agent.ainvoke(
{
"messages": [
{"role": "user", "content": "Use the MCP server to help me."}
]
},
config={"configurable": {"thread_id": "1"}},
)import asyncio
from deepagents import create_deep_agent
from langchain.mcp import MCPAdapter
async def main():
config = {"mcpServers": {"my_server": {"url": "http://localhost:8000/mcp"}}}
async with MCPAdapter(config) as adapter:
tools = await adapter.list_tools()
agent = create_deep_agent(
model="openai:gpt-5.5",
tools=tools,
)
await agent.ainvoke(
{
"messages": [
{"role": "user", "content": "Use the MCP server to help me."}
]
},
config={"configurable": {"thread_id": "1"}},
)import asyncio
from deepagents import create_deep_agent
from langchain.mcp import MCPAdapter
async def main():
config = {"mcpServers": {"my_server": {"url": "http://localhost:8000/mcp"}}}
async with MCPAdapter(config) as adapter:
tools = await adapter.list_tools()
agent = create_deep_agent(
model="anthropic:claude-sonnet-5",
tools=tools,
)
await agent.ainvoke(
{
"messages": [
{"role": "user", "content": "Use the MCP server to help me."}
]
},
config={"configurable": {"thread_id": "1"}},
)import asyncio
from deepagents import create_deep_agent
from langchain.mcp import MCPAdapter
async def main():
config = {"mcpServers": {"my_server": {"url": "http://localhost:8000/mcp"}}}
async with MCPAdapter(config) as adapter:
tools = await adapter.list_tools()
agent = create_deep_agent(
model="openrouter:z-ai/glm-5.2",
tools=tools,
)
await agent.ainvoke(
{
"messages": [
{"role": "user", "content": "Use the MCP server to help me."}
]
},
config={"configurable": {"thread_id": "1"}},
)import asyncio
from deepagents import create_deep_agent
from langchain.mcp import MCPAdapter
async def main():
config = {"mcpServers": {"my_server": {"url": "http://localhost:8000/mcp"}}}
async with MCPAdapter(config) as adapter:
tools = await adapter.list_tools()
agent = create_deep_agent(
model="fireworks:accounts/fireworks/models/glm-5p2",
tools=tools,
)
await agent.ainvoke(
{
"messages": [
{"role": "user", "content": "Use the MCP server to help me."}
]
},
config={"configurable": {"thread_id": "1"}},
)import asyncio
from deepagents import create_deep_agent
from langchain.mcp import MCPAdapter
async def main():
config = {"mcpServers": {"my_server": {"url": "http://localhost:8000/mcp"}}}
async with MCPAdapter(config) as adapter:
tools = await adapter.list_tools()
agent = create_deep_agent(
model="baseten:zai-org/GLM-5.2",
tools=tools,
)
await agent.ainvoke(
{
"messages": [
{"role": "user", "content": "Use the MCP server to help me."}
]
},
config={"configurable": {"thread_id": "1"}},
)import asyncio
from deepagents import create_deep_agent
from langchain.mcp import MCPAdapter
async def main():
config = {"mcpServers": {"my_server": {"url": "http://localhost:8000/mcp"}}}
async with MCPAdapter(config) as adapter:
tools = await adapter.list_tools()
agent = create_deep_agent(
model="ollama:north-mini-code-1.0",
tools=tools,
)
await agent.ainvoke(
{
"messages": [
{"role": "user", "content": "Use the MCP server to help me."}
]
},
config={"configurable": {"thread_id": "1"}},
)
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 a new file, or overwrite an existing one. |
edit_file | Perform exact string replacements in files. |
delete | Delete a file, or a directory and its contents recursively. The delete tool requires deepagents>=0.7. |
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.