CMA:协调专家团队

多个专业 Agent 协同完成任务

🌐 查看英文原文 | 源码 Notebook


多 Agent:协调专家团队

我们将使用 Claude Managed Agents 和多 Agent 协调器模式来自动化为一家名为 Northstar 的虚构公司编写销售提案,该公司向中型市场运营团队销售工作流自动化平台。

目前,他们的销售代表为每个潜在客户构建定制提案:研究潜在客户所在行业中公司通常优先考虑什么,从数百个案例库中提取两个相关案例,根据内部规则表建模定价,并将其组装成两页文档。每一步都依赖于不同的来源和不同的判断。

我们将让一个协调器 Agent 运行三个专家来完成这项工作。研究员使用网络搜索来查找潜在客户所在行业的典型情况。图书馆员阅读案例库并选择两个最佳匹配。定价建模师只看到规则文件和席位数。协调器安排它们的顺序并编写提案。

1. 设置客户端

首先,让我们安装 SDK 并设置 Anthropic 客户端。multiagent 配置和事件类型是 Managed Agents beta 的一部分。

%%capture
%pip install -q anthropic python-dotenv
import os

import anthropic
from dotenv import load_dotenv

load_dotenv()

BETAS = ["managed-agents-2026-04-01"]
MODEL = os.environ.get("COOKBOOK_MODEL", "claude-opus-4-6")
client = anthropic.Anthropic()

2. 定义三个专家子 Agent

接下来,我们将创建三个队友。每个都有自己的系统提示、自己的输出形状,以及仅其工作所需的工具。研究员拥有网络搜索,案例选择器只能读取本地库,定价建模师只看到 pricing_rules.md 和席位数。按角色限定工具范围可以防止定价器从网上拉取竞争对手的价格,并将完整的案例库排除在协调器的上下文之外。

def make_agent(name, description, system, tools):
    a = client.beta.agents.create(
        name=name,
        description=description,
        model=MODEL,
        system=system,
        tools=tools,
        betas=BETAS,
    )
    print(f"{name}: {a.id}")
    return a.id


prospect_researcher = make_agent(
    "prospect_researcher",
    "Researches what companies in a given industry segment and size tier typically prioritize.",
    """Given a prospect's industry and size, use web search to find:
- What companies in that segment typically list as strategic priorities
- Recent trends or pressures in that industry
- Common operational pain points at that scale
Return via send_to_parent: {"priorities": [...], "recent_moves": [...], "pain_points": [...], "sources": [...]}""",
    [
        {
            "type": "agent_toolset_20260401",
            "configs": [{"name": "web_search"}, {"name": "web_fetch"}],
        }
    ],
)

case_study_picker = make_agent(
    "case_study_picker",
    "Selects the two most relevant case studies from the library for a given prospect profile.",
    """The case study library is in /mnt/user-data/case_studies/. Each file is one customer story.
You will be given a prospect's industry, size, and top priorities. Read the library, score each study on relevance, and pick the two best matches.
Return via send_to_parent: {"picks": [{"file": ..., "customer": ..., "why_relevant": ...}, ...]}""",
    [{"type": "agent_toolset_20260401"}],
)

pricing_modeler = make_agent(
    "pricing_modeler",
    "Builds two or three pricing options for a prospect based on seat count and expected usage.",
    """Pricing rules are in /mnt/user-data/pricing_rules.md. Given a prospect's estimated seat count and usage tier, build:
- a conservative option (annual commit, lower per-seat)
- a flexible option (monthly, higher per-seat)
- if seat count > 500, an enterprise option with a platform fee
Show the first-year total for each. Return via send_to_parent: {"options": [{"name": ..., "structure": ..., "year_one_total": ...}, ...]}""",
    [{"type": "agent_toolset_20260401"}],
)
prospect_researcher: agent_011Cahy5YQwAN99heAeSpPob
case_study_picker: agent_011Cahy5ZKWFqEAgPNZZxPvM
pricing_modeler: agent_011Cahy5a5eTdwuzZabFgu6K

3. 给团队一些工作素材

图书馆员需要一个可供选择的库。我们将给它七个跨医疗、制造、物流、零售、金融科技和公共部门的简短案例,这样你可以看到它实际选择适合我们潜在客户的两个。

CASE_STUDIES = [
    {
        "slug": "stclair_health",
        "title": "St. Clair Health",
        "industry": "regional hospital network",
        "employees": 6200,
        "summary": """Challenge: credentialing and prior-auth workflows spread across 11 systems.
Result with Northstar: consolidated to 3 automated workflows; prior-auth turnaround down 58%; $1.9M annual labor savings.""",
    },
    {
        "slug": "blueridge_health_plan",
        "title": "BlueRidge Health Plan",
        "industry": "regional payer",
        "employees": 2800,
        "summary": """Challenge: claims-adjudication exceptions queued in email; 19% required manual rework.
Result with Northstar: exception routing automated end-to-end; rework rate down to 6%; 11-day faster average claim resolution.""",
    },
    {
        "slug": "calder_mfg",
        "title": "Calder Manufacturing",
        "industry": "industrial",
        "employees": 3100,
        "summary": """Challenge: purchase-order approvals averaging 9 days.
Result with Northstar: PO cycle time cut to 2.1 days; 14% reduction in maverick spend.""",
    },
    {
        "slug": "northwind",
        "title": "Northwind Logistics",
        "industry": "3PL",
        "employees": 4400,
        "summary": """Challenge: carrier-onboarding paperwork took 3 weeks per carrier.
Result with Northstar: onboarding down to 4 days; 22% more carriers activated in Q1.""",
    },
    {
        "slug": "harborview_retail",
        "title": "Harborview Retail Group",
        "industry": "specialty retail",
        "employees": 5600,
        "summary": """Challenge: store-level inventory exceptions handled by regional managers over Slack and spreadsheets.
Result with Northstar: exception triage automated across 140 stores; stockout incidents down 31%.""",
    },
    {
        "slug": "aperture_fintech",
        "title": "Aperture Payments",
        "industry": "fintech",
        "employees": 1900,
        "summary": """Challenge: KYC and merchant-onboarding reviews averaging 6 business days.
Result with Northstar: review SLA cut to 36 hours; onboarding throughput up 2.4x with the same team.""",
    },
    {
        "slug": "summit_county",
        "title": "Summit County Government",
        "industry": "public sector",
        "employees": 3700,
        "summary": """Challenge: building-permit applications routed through five departments by paper packet.
Result with Northstar: single digital intake with parallel department review; median permit time 41 to 17 days.""",
    },
]

产品和定价资料

我们还将提供协调器在编写”我们如何提供帮助”部分时阅读的产品一页纸,以及建模师用来构建选项的定价规则文件。

PRODUCT = """# Northstar Platform — One-Pager
Northstar is a workflow automation platform for mid-market operations teams.
Core capabilities: visual process builder, 200+ SaaS connectors, role-based approvals, SOC 2 Type II.
Typical results: 40-60% reduction in manual ticket handling, 3-week time-to-first-workflow."""

PRICING = """# Pricing Rules (internal)
- Per-seat list: $65/mo (monthly) or $52/mo (annual commit).
- Usage tiers: light = 1.0x, standard = 1.15x, heavy = 1.30x multiplier on per-seat.
- Enterprise (>500 seats): add $48,000/yr platform fee, per-seat drops to $44/mo annual.
- All options include onboarding; enterprise includes a named CSM."""

连接协调器并启动 session

现在让我们创建一个 environment,上传九个文件,并创建带有三个专家的 multiagent 名册的协调器。每个条目都是一个完整的 agent,有自己的模型、提示和工具集,因此你可以按角色混合模型层级。

env = client.beta.environments.create(
    name="proposal-meridian",
    config={"type": "anthropic_cloud", "networking": {"type": "unrestricted"}},
)

resources = []


def mount(path, content):
    f = client.beta.files.upload(
        file=(os.path.basename(path), content.encode(), "text/plain")
    )
    resources.append({"type": "file", "file_id": f.id, "mount_path": path})


for cs in CASE_STUDIES:
    body = f"# {cs['title']} ({cs['industry']}, {cs['employees']:,} employees)\n{cs['summary']}"
    mount(f"/mnt/user-data/case_studies/{cs['slug']}.md", body)
mount("/mnt/user-data/product_one_pager.md", PRODUCT)
mount("/mnt/user-data/pricing_rules.md", PRICING)

coordinator = client.beta.agents.create(
    name="Proposal Writer",
    model=MODEL,
    system="""You assemble tailored sales proposals.
Given a prospect name and basic profile:
1. Send the prospect's industry and size to prospect_researcher.
2. Send the prospect's industry, size, and (once the researcher reports back) their priorities to case_study_picker.
3. Send the seat count and usage tier to pricing_modeler.
4. Read /mnt/user-data/product_one_pager.md, then write /mnt/session/outputs/proposal.md with sections:
   Executive summary (tied to their priorities), How we help (from the one-pager),
   Proof (the two case studies), Investment (the pricing options), Next steps.
Keep it to two pages.""",
    tools=[{"type": "agent_toolset_20260401"}],
    multiagent={
        "type": "coordinator",
        "agents": [prospect_researcher, case_study_picker, pricing_modeler],
    },
    betas=BETAS,
)

session = client.beta.sessions.create(
    agent={"type": "agent", "id": coordinator.id, "version": coordinator.version},
    environment_id=env.id,
    resources=resources,
    title="Proposal: Meridian Health",
    betas=BETAS,
)
print(f"Session {session.id} ready with {len(resources)} files mounted")
Session sesn_011Cahy5wq6Jyk32n2NwgR88 ready with 9 files mounted

4. 启动提案

让我们发送潜在客户资料并观察协调器工作。它将并行启动研究员和定价建模师,然后在研究员的发现返回后运行案例选择器,因为选择器需要这些优先级来评分相关性。

PROSPECT = {
    "name": "Meridian Health",
    "industry": "regional healthcare system",
    "employees": 8500,
    "estimated_seats": 600,
    "usage_tier": "heavy",
}

client.beta.sessions.events.send(
    session.id,
    betas=BETAS,
    events=[
        {
            "type": "user.message",
            "content": [
                {
                    "type": "text",
                    "text": f"Build a proposal for {PROSPECT['name']}, a {PROSPECT['industry']} with "
                    f"~{PROSPECT['employees']} employees. Estimate {PROSPECT['estimated_seats']} seats "
                    f"at {PROSPECT['usage_tier']} usage. Write to /mnt/session/outputs/proposal.md.",
                }
            ],
        }
    ],
)

with client.beta.sessions.events.stream(session.id, betas=BETAS) as stream:
    for ev in stream:
        if ev.type == "session.thread_created":
            print(f"[spawn] {ev.agent_name}")
        elif ev.type == "agent.thread_message_received":
            print(f"[report] {ev.from_agent_name} returned")
        elif ev.type == "session.status_idle":
            print("[done]")
            break
[spawn] prospect_researcher
[spawn] pricing_modeler
[report] prospect_researcher returned
[spawn] case_study_picker
[report] pricing_modeler returned
[report] case_study_picker returned
[done]

每个队友返回的内容

在我们查看组装好的提案之前,让我们打印三个原始的 send_to_parent 负载。每个子 Agent 在自己的上下文中运行,只有自己的工具,因此三份报告看起来彼此非常不同。

def text_of(content):
    return "".join(b.text for b in content if b.type == "text")


for ev in client.beta.sessions.events.list(session.id, limit=1000, betas=BETAS):
    if ev.type == "agent.thread_message_received":
        body = text_of(ev.content)
        print(f"━━━ send_to_parent from {ev.from_agent_name} ({len(body)} chars) ━━━")
        print(body[:1200] + (f"\n…[{len(body) - 1200} more chars]" if len(body) > 1200 else ""))
        print()
━━━ send_to_parent from prospect_researcher (9580 chars) ━━━
Here is the structured research for tailoring a sales proposal to Meridian Health (regional healthcare system, ~8,500 employees):

---

## 1. TOP 3–5 STRATEGIC PRIORITIES FOR REGIONAL HEALTHCARE SYSTEMS IN 2025–2026

**Priority 1: Financial Resilience & Cost Containment**
- Regional health systems are under intense financial pressure from reimbursement shortfalls, labor cost inflation, and policy changes (e.g., Medicaid cuts, 340B reforms under the One Big Beautiful Bill Act). Per Plante Moran: "Medicaid changes could create tens of millions in revenue shortfalls for some systems." Cash flow acceleration, revenue cycle optimization, and cost control without compromising care quality are top-of-mind.
- EY notes: "Reimbursement, labor shortage and cost inflation headwinds are compounded by the need to invest in leading clinical programs." Regional health systems specifically are "signaling the strategic importance of increasing scale in the face of accelerating costs."

**Priority 2: Workforce Retention, Burnout Reduction & Staffing Optimization**
- The AHA's 2026 Workforce Scan highlights: "Burnout, vacancies and administrative burden remain top concerns for health care leaders acro
…[8380 more chars]

━━━ send_to_parent from pricing_modeler (2440 chars) ━━━
{"options": [
  {
    "name": "Flexible — Monthly",
    "structure": "Month-to-month billing, no annual commitment. 600 seats at $84.50/seat/month (list $65.00 × 1.30 heavy-usage multiplier). Includes: onboarding program, visual process builder, 200+ SaaS connectors, role-based approvals, SOC 2 Type II compliance, standard email/chat support (business-hours SLA). No volume discount applied; full flexibility to scale seats up or down monthly.",
    "year_one_total": "$608,400"
  },
  {
    "name": "Standard — Annual Commit",
    "structure": "12-month annual commitment, billed annually or quarterly. 600 seats at $67.60/seat/month ($52.00 annual-commit base × 1.30 heavy-usage multiplier). Includes everything in Flexible plus: 20% per-seat savings vs. monthly ($121,680 first-year savings), priority support queue, onboarding program. Annual commitment locks in rate for the term.",
    "year_one_total": "$486,720"
  },
  {
    "name": "Enterprise — Annual Commit + Platform",
    "structure": "12-month annual commitment with Enterprise platform tier. 600 seats at $57.20/seat/month ($44.00 enterprise base × 1.30 heavy-usage multiplier) plus $48,000/year platform fee. Includes everything i
…[1240 more chars]

━━━ send_to_parent from case_study_picker (3470 chars) ━━━
{"picks": [
  {
    "file": "/mnt/session/uploads/mnt/user-data/case_studies/stclair_health.md",
    "customer": "St. Clair Health — regional hospital network, 6,200 employees",
    "key_results": "Consolidated credentialing and prior-auth workflows from 11 disconnected systems into 3 automated workflows; prior-auth turnaround reduced 58%; $1.9M annual labor savings.",
    "why_relevant": "St. Clair is the strongest match across nearly every Meridian priority: (1) Same industry and org type — a regional hospital network of comparable size (6,200 vs. 8,500 employees), making it a highly credible peer reference. (2) System consolidation — collapsed 11 systems into 3 automated workflows, directly mirroring Meridian's need to consolidate ~1,500 disconnected applications and improve interoperability. (3) Cost containment — $1.9M annual labor savings speaks directly to Meridian's financial resilience priority and makes a concrete ROI case. (4) Admin burden reduction — automating credentialing and prior-auth are classic high-burden healthcare admin tasks, addressing the workforce burnout and retention priority. (5) Prior-auth turnaround improvement (58%) ties to revenue cycle acceleration
…[2270 more chars]

5. 读取提案

最后,让我们拉取组装好的提案。协调器使用 write 工具将其写入 proposal.md,因此我们将在日志中找到该事件并查看它生成的部分。如果你想阅读完整文档,请打印 proposal 本身。

proposal = ""
for ev in client.beta.sessions.events.list(session.id, limit=1000, betas=BETAS):
    if (
        ev.type == "agent.tool_use"
        and ev.name == "write"
        and ev.input["file_path"].endswith("proposal.md")
    ):
        proposal = ev.input["content"]
        break

# Show the section structure rather than the full proposal.
for line in proposal.splitlines():
    if line.startswith("#"):
        print(line)
# Northstar Platform — Proposal for Meridian Health
## Executive Summary
## How We Help
## Proof — Results from Healthcare Organizations Like Yours
### St. Clair Health — Regional Hospital Network, 6,200 Employees
### BlueRidge Health Plan — Regional Health Plan, 2,800 Employees
## Investment — Three Options for 600 Seats, Heavy Usage
## Next Steps

为什么用三个子 Agent 而不是一个

一个拥有所有三个工具的单 Agent 也可以编写此提案,那为什么要拆分呢?将每个角色限定到自己的工具意味着定价建模师无法从网上拉取竞争对手的标价,因为它只有规则文件。案例选择器在这里读取七个文件,但在生产环境中它将读取数百个,而该容量留在子 Agent 的上下文中而不是协调器的上下文中。协调器可以决定顺序和交接,而无需自己做任何专家工作。

有关多 Agent 协调的更多信息,请参阅 Managed Agents 文档。


Tip

中文读者提示:本章节的代码和输出为英文原文。如需理解具体实现细节,可参考上方中文导读和代码注释。如有疑问,欢迎在 GitHub Issues 讨论。