Skip to content
Back/Claude Code

Claude Managed Agents Cookbook

View in Graph
Updated 2026-05-14
2 min read
287 words

Claude Managed Agents Cookbook

Anthropic 官方 Cookbook 实践:构建基于 Claude Managed Agents 的数据分析师和 Slack Bot。

核心概念

Claude Managed Agents 基于四个核心概念:

  • Agent:模型、系统提示词、工具、MCP servers 和 skills
  • Environment:配置的容器模板(包、网络访问)
  • Session:在环境中运行的 agent 实例,执行特定任务
  • Events:应用与 agent 之间交换的消息

Agent + Environment = Session。Anthropic 处理沙盒、工具执行和上下文管理。


Cookbook 1:Data Analyst Agent

将 CSV 转换为带交互式图表的叙事 HTML 报告。

关键实现步骤

  1. 创建 Environment:声明 pandasplotly 为预装包
  2. 创建 Agent:使用 agent_toolset_20260401(八工具:bash/read/write/edit/glob/grep/web_fetch/web_search)
  3. 上传数据集 → Files API
  4. 创建 Session 并发送分析任务
  5. 流式监控运行过程
  6. 获取报告/mnt/session/outputs/ 下的文件通过 Files API 获取

系统提示词要点

  • 专业精确风格,使用具体数字
  • 图表之间短段落(2-3 句)
  • 以最具行动力的发现开头
  • 输出到 /mnt/session/outputs/report.html

Cookbook 2:Slack Data Analyst Bot

用 Bolt for Python 包装数据分析师 agent,@bot + CSV 附件即可获得线程内分析报告。

架构

user: @databot what's driving Q1 revenue? [sales.csv]
    |
    bot uploads CSV and starts agent session
    |
    bot streams progress back to thread
    |
    bot posts finished report to thread

关键设计

  • Thread-to-Session 映射thread_sessions: dict[str, str] 维持多轮对话上下文
  • 后台线程:Slack 3 秒 ack 窗口要求慢操作必须在后台线程执行
  • Socket Mode:WebSocket 交付,无需公网 URL
  • Follow-ups:线程内回复继续同一会话

生产考虑

  • thread_sessions 持久化到数据库,确保 bot 重启后对话不丢失
  • 线程过期时归档会话释放容器
  • 在数据分析师 notebook 中修改 agent 系统提示词即可改变分析风格

最佳实践

  • Agent 和 Environment 创建一次,跨运行复用
  • 每个对话创建新 Session
  • 完成后归档 Session 释放容器
  • 将 agent/environment ID 保存到 .env 供其他应用复用

2026-05-14 更新:三项新功能

来源:AI 简报 2026-05-14 Afternoon

Claude Managed Agents 新增三项能力:

Dreaming(自动记忆提取)

自动从对话历史中提取记忆,无需用户手动标记。这是 Memory Backend 范式的官方实现——agent 自主判断什么值得记住,而非依赖用户显式输入。

Outcomes(用户定义成功标准)

用户可为任务定义成功标准,系统内置评分器自动评判 Agent 工作质量。将验证从"人工检查"推向"结构化自动评估",与 自我验证循环 形成呼应。

Multi-agent orchestration(子 Agent 委派)

主 Agent 自动拆解任务并委派给专业子 Agent。这是 多 Agent 协调模式 的官方实现:不再依赖单一全能 Agent,而是利用专业化分工。


实际应用案例

Skillet:浏览器端的 Claude Code 体验

Skillet 利用 Claude Managed Agents 将 Claude Code 的能力带入浏览器,让非技术人员无需终端即可使用 AI agent。

  • 基于 Claude Agent SDK 构建,skills 安装方式与 Claude Code 一致
  • gstack 的 /office-hours skill 可以在浏览器中直接运行
  • 消除了终端门槛,扩大了 AI agent 的受众范围
  • 代表了 agent 工具从开发者工具向大众工具的演进趋势

Sources

Synthesized from 4 sources

Evolution

1 event
  1. absorbed

    Derived from source material

    This page is currently synthesized from 4 sources.

    From Build a data analyst agent with Claude Managed Agents, Build a Slack data analyst bot with Claude Managed Agents, Anthropic Cookbook: Data Analyst Agent, Anthropic Cookbook: Slack Data BotTo Claude Managed Agents Cookbook
    Sources: raw/to-learn/Build a data analyst agent with Claude Managed Agents.md · raw/to-learn/Build a Slack data analyst bot with Claude Managed Agents.md · https://platform.claude.com/cookbook/managed-agents-data-analyst-agent · https://platform.claude.com/cookbook/managed-agents-slack-data-bot

Linked from