Building Multi-Agent Applications with Deep Agents使用 Deep Agents 构建多智能体应用

S. Runkle,
V. Trivedy
January 21, 2026
5
min
Go back to blog

By Sydney Runkle and Vivek Trivedy作者:Sydney Runkle 和 Vivek Trivedy

Breaking down complex tasks across specialized agents is one of the most effective approaches to building capable AI systems.将复杂任务分解给专门的智能体,是构建强大 AI 系统最有效的方法之一。

Deep Agents makes this easy with two first-class primitives:Deep Agents 通过两个一流的原语使这一过程变得简单:

  • subagents: delegating to isolated agents子智能体 (subagents):委托给独立的智能体
  • skills: progressively disclosing capabilities技能 (skills):渐进式披露能力

In this post, we'll show you how to build multi-agent systems with Deep Agents.在本文中,我们将向您展示如何使用 Deep Agents 构建多智能体系统。

Using Subagents: Specialized, Isolated Workers使用子智能体:专业、隔离的工作单元

Subagents tackle a fundamental problem in agent engineering: context bloat. This is when an agent's context window becomes close to full as it works on a task.子智能体解决了智能体工程中的一个根本问题:上下文膨胀。当智能体在处理任务时,其上下文窗口接近填满,就会出现这种情况。

Why is this important? There's great work from Chroma on context rot showing that models struggle to complete tasks as their context window gets filled. Our friends at HumanLayer call this high context regime the “dumb zone”. Subagents isolate context from the main agent to help avoid quickly entering the dumb zone.为什么这很重要?Chroma 关于“上下文腐烂 (context rot)”的出色研究表明,当上下文窗口被填满时,模型难以完成任务。我们的朋友 HumanLayer 将这种高上下文状态称为“愚钝区 (dumb zone)”。子智能体将上下文与主智能体隔离开来,有助于避免过快进入“愚钝区”。

When your agent makes dozens of web searches or file reads, the context window fills with intermediate results. Subagents isolate work by running with their own context window. So if the subagent is doing a lot of exploratory work before coming with its final answer, the main agent still only gets the final result, not the 20 tool calls that produced it.当您的智能体进行数十次网络搜索或文件读取时,上下文窗口会被中间结果填满。子智能体通过在各自的上下文窗口中运行来隔离工作。因此,如果子智能体在得出最终答案之前进行了大量的探索性工作,主智能体仍然只会收到最终结果,而不是产生该结果的 20 次工具调用。

Here's a look at the basic subagents architecture:以下是基本子智能体架构的概览:

When to Use Subagents何时使用子智能体

  • Context Preservation: A task requiring multiple steps can clutter the main agent's context (ex: codebase exploration).上下文保留:需要多个步骤的任务可能会弄乱主智能体的上下文(例如:代码库探索)。
  • Specialization: Use domain specific instructions or tools. Subagents developed by distinct teams can specialize in different verticals.专业化:使用特定领域的指令或工具。由不同团队开发的子智能体可以专注于不同的垂直领域。
  • Multi-Model: Subagents can use different models than the main agent. For example, choosing a smaller model for lower latency.多模型:子智能体可以使用与主智能体不同的模型。例如,选择较小的模型以降低延迟。
  • Parallelization: Subagents can run simultaneously and return their outputs to the main agent. This reduces latency.并行化:子智能体可以同时运行并将输出返回给主智能体。这减少了延迟。

Creating Subagents创建子智能体

Define subagents as dictionaries and pass them to create_deep_agent():将子智能体定义为字典并将其传递给 create_deep_agent():

from deepagents import create_deep_agent
 
research_subagent = {
    "name": "research-agent",
    "description": "Used to research more in depth questions",
    "system_prompt": "You are a great researcher",
    "tools": [internet_search],
    "model": "openai:gpt-4o",  # Optional: override main agent model
}
 
agent = create_deep_agent(
    model="claude-sonnet-4-5-20250929",
    subagents=[research_subagent]
)

See the subagents documentation for configuration details.有关配置详细信息,请参阅子智能体文档。

The General-Purpose Subagent通用子智能体

Deep Agents include a built-in general-purpose subagent that mirrors your main agent's capabilities. It has the same system prompt, tools, and model. This is perfect for context isolation without specialized behavior.Deep Agents 包含一个内置的通用子智能体,它镜像了您主智能体的能力。它具有相同的系统提示词、工具和模型。这非常适合在无需特殊行为的情况下进行上下文隔离。

Example: Instead of your main agent making 10 web searches and filling its context, it can delegate to the general-purpose subagent with task(name="general-purpose", task="Research quantum computing trends"). The subagent performs all searches internally and returns only a summary.示例:与其让主智能体进行 10 次网络搜索并填满其上下文,不如将其委托给通用子智能体,使用 task(name="general-purpose", task="Research quantum computing trends")。子智能体在内部执行所有搜索,并仅返回摘要。

Best Practices for Subagents子智能体的最佳实践

Write clear descriptions. Your main agent uses descriptions to decide which subagent to call:编写清晰的描述。您的主智能体使用描述来决定调用哪个子智能体:

✅ Good: "Analyzes financial data and generates investment insights with confidence scores"
❌ Bad: "Does finance stuff"
✅ 好:“分析财务数据并生成具有置信度的投资见解” ❌ 差:“做财务方面的事情”

Keep system prompts detailed. Include tool usage guidance and output format requirements:保持系统提示词详细。包括工具使用指南和输出格式要求:

research_subagent = {
    "name": "research-agent",
    "description": "Conducts in-depth research using web search and synthesizes findings",
    "system_prompt": """You are a thorough researcher. Your job is to:

    1. Break down the research question into searchable queries
    2. Use internet_search to find relevant information
    3. Synthesize findings into a comprehensive but concise summary
    4. Cite sources when making claims

    Output format:
    - Summary (2-3 paragraphs)
    - Key findings (bullet points)
    - Sources (with URLs)

    Keep your response under 500 words to maintain clean context.""",
    "tools": [internet_search],
}

Minimize tool sets. Only give subagents the tools they need:最小化工具集。只给子智能体提供它们需要的工具:

# ✅ Good: Focused tool set
email_agent = {
    "name": "email-sender",
    # Only email-related
    "tools": [send_email, validate_email],
}
 
# ❌ Bad: Too many tools
email_agent = {
    "name": "email-sender",
    # Unfocused
    "tools": [send_email, web_search, database_query, file_upload],
}

Using Skills: Progressive Disclosure of Capabilities使用技能:渐进式披露能力

Skills provide a different pattern: progressive disclosure. Instead of giving your agent dozens of tools upfront, you define specialized capabilities in SKILL.md files. Your agent sees skill names and descriptions, then reads the full instructions only when needed.技能提供了一种不同的模式:渐进式披露。与其预先给智能体提供数十种工具,不如在 SKILL.md 文件中定义专门的能力。您的智能体可以看到技能名称和描述,然后仅在需要时才读取完整的指令。

Skill descriptions are pre-loaded into the context window. The skill body is only loaded when the agent decides the skill is needed based on the description and previous context.技能描述被预加载到上下文窗口中。技能主体仅在智能体根据描述和先前的上下文决定需要该技能时才会被加载。

Caption: skill descriptions are pre-loaded into the context window. The skill body is only loaded when the agent decides the skill is needed based on the description and previous context.说明:技能描述被预加载到上下文窗口中。技能主体仅在智能体根据描述和先前的上下文决定需要该技能时才会被加载。

Setting Up Skills设置技能

Skills use the agentskills.io spec. Here's the structure:技能使用 agentskills.io 规范。结构如下:

.deepagents/skills/
├── deploy/SKILL.md
└── review-pr/SKILL.md

Each SKILL.md file has YAML frontmatter with metadata and a main body:每个 SKILL.md 文件都有带有元数据的 YAML 前置内容和主体:

---
name: deploy
description: Deploy to production
version: 1.0.0  # Optional
tags: [deployment, production]  # Optional
---
 
# Deploy to Production
 
When the user asks to deploy, follow these steps:
 
1. Run tests: `npm test`
2. Build the application: `npm run build`
3. Deploy to production: `npm run deploy:prod`
4. Verify deployment: Check the health endpoint
 
Always confirm with the user before deploying to production.

Adding Skills to Your Agent将技能添加到您的智能体

Use the skills argument to create_deep_agent to load skills from the filesystem:使用 create_deep_agent 的 skills 参数从文件系统加载技能:

from deepagents import create_deep_agent
from deepagents.backends import FilesystemBackend
 
agent = create_deep_agent(
    model="claude-sonnet-4-5-20250929",
    backend=FilesystemBackend(root_dir="/"),
    skills=[".deepagents/skills"],
)

The agent now sees your skills. When it needs detailed instructions, it reads the full SKILL.md file.智能体现在可以看到您的技能。当它需要详细指令时,它会读取完整的 SKILL.md 文件。

You can also use other backends (such as a StateBackend or StoreBackend), then invoke the agent with a files specification:您还可以使用其他后端(例如 StateBackend 或 StoreBackend),然后使用文件规范调用智能体:

from deepagents.middleware.filesystem import FileData
 
# default backend is a StateBackend
agent = create_deep_agent(
    model="anthropic:claude-sonnet-4-20250514",
    skills=["/skills/"],
)
 
skill_content = """
---
name: deploy
...
"""
 
# Invoke the agent with the skill and virtual files
result = agent.invoke({
    "messages": [HumanMessage(content="Research the latest Python releases")],
    "files": {
        "/skills/web-research/SKILL.md": FileData(
            content=skill_content.split("\n"),
            created_at="2024-01-01T00:00:00Z",
            modified_at="2024-01-01T00:00:00Z",
        ),
    },
})

Choosing the Right Pattern选择正确的模式

Here's a quick set of questions to guide you:以下是一组快速问题来指导您:

When you need to... Use... Both?
Delegate complex, multi-step work Subagents for context isolation
Reuse procedures or instructions Skills for progressive disclosure
Provide specialized tools for specific tasks Subagents with focused tool sets
Share capabilities across multiple agents Skills (they’re just files)
Work with large tool sets Skills to avoid token bloat

Note, this doesn't have to be an either-or decision.Many systems use both. Skills define procedures; subagents execute complex multi-step work. Your subagents can use skills to effectively manage their context windows!请注意,这不必是二选一的决定。许多系统两者都使用。技能定义程序;子智能体执行复杂的多步骤工作。您的子智能体可以使用技能来有效地管理它们的上下文窗口!

Next Steps后续步骤

To learn more about multi-agent patterns in Deep Agents, check out our:要了解有关 Deep Agents 中多智能体模式的更多信息,请查看我们的:

The key insight: multi-agent patterns don't have to be complicated. With the right abstractions (middleware for plumbing, tool calling for invocation), they become simple building blocks you can compose into capable, sophisticated systems.关键见解:多智能体模式不必很复杂。有了正确的抽象(用于管道的中间件,用于调用的工具调用),它们就变成了简单的构建块,您可以将其组合成强大、复杂的系统。

Start with subagents for context management, add skills for progressive disclosure, and build from there.从用于上下文管理的子智能体开始,添加用于渐进式披露的技能,并在此基础上进行构建。

S
e
e
w
h
a
t
y
o
u
r
a
g
e
n
t
i
s
r
e
a
l
l
y
d
o
i
n
g

LangSmith, our agent engineering platform, helps developers debug every agent decision, eval changes, and deploy in one click.