407 lines
26 KiB
Markdown
407 lines
26 KiB
Markdown
# 前言
|
||
1. AI算法讲解
|
||
1. [【Transformer】最强动画讲解!目前B站最全最详细的Transformer教程,2025最新版!从理论到实战,通俗易懂解释原理,草履虫都学的会!](https://www.bilibili.com/video/BV1fj6vBfEnu/?p=3&share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e)
|
||
2. Claude:编程向的LLM大模型
|
||
1. 本地部署 LLM,无订阅使用 Claude Code https://km.netease.com/v4/detail/blog/258409
|
||
1. 【【硬核教程】教你搭建Mac AI集群!4台M3 Ultra,运行万亿参数大模型!】 https://www.bilibili.com/video/BV18wZjBuEUB/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
2. 【模型推理时所需的GPU显存】 https://www.bilibili.com/video/BV1up25Y7Emb/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
2. [ ] ClaudeCode插件
|
||
1. 【🚀告别Vibe Coding!用Superpowers让Claude Code写出工程级代码,一次通过零报错!遵循TDD最佳实践!支持Codex】 https://www.bilibili.com/video/BV11urFBrEc4/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
2. Ralph for Claude Code:【🚀Claude Code自动化开发必备神器!Ralph for Claude Code实战演示,导入PRD文档秒变任务清单,AI通宵帮你写代码!保姆级教程】 https://www.bilibili.com/video/BV1V9kEB7Erw/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
3. [ ] Claude Code Agent Teams 实验与技术剖析 https://km.netease.com/v4/detail/blog/259175
|
||
4. [ ] [Anthropic 黑客马拉松获胜者的完整 Claude Code 配置集合](https://github.com/affaan-m/everything-claude-code/blob/main/README.zh-CN.md)
|
||
5. [ ] [claude.md怎么写才能让Claude Code更高效?](https://www.zhihu.com/question/1979609139266213083/answer/2009919949922133046?share_code=vC8d59XJYGNj&utm_psn=2010698466100262066)
|
||
6. [ ] [他把Claude Code给玩通关了 - 欧巴聊AI的文章 - 知乎](https://zhuanlan.zhihu.com/p/2001805409359520847)
|
||
3. 教学视频
|
||
1. ClaudeCode
|
||
1. [x] 【Claude Code 从 0 到 1 全攻略:MCP / SubAgent / Agent Skill / Hook / 图片 / 上下文处理/ 后台任务】 https://www.bilibili.com/video/BV14rzQB9EJj/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
2. [x] 【最火AI编程Claude Code详细攻略,一期视频精通】 https://www.bilibili.com/video/BV1XGbazvEuh/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
3. 【AI Max+ 395突破96G显存限制部署GLM-4.7生成电脑游戏】 https://www.bilibili.com/video/BV1pfixBvEzC/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
2. CodeX
|
||
1. 【AI编程新王Codex详细攻略,一期视频精通,附免费使用方法】 https://www.bilibili.com/video/BV1wm4UzfEbr/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
3. OpenCode
|
||
1. 【OpenCode详细攻略,开源版Claude Code,免费模型与神级插件】 https://www.bilibili.com/video/BV1BVrXBUEbR/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
4. MCP
|
||
1. 【用过上百款编程MCP,只有这15个真正好用,Claude Code与Codex配置MCP详细教程】 https://www.bilibili.com/video/BV1ZJsBznEt3/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
2. 【从零编写MCP并发布上线,超简单!手把手教程】 https://www.bilibili.com/video/BV1RNTtzMENj/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
5. Skill
|
||
1. 【Agent Skills (Claude Skills) 详细攻略,一期视频精通】 https://www.bilibili.com/video/BV1HuiyBQE9G/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
2. 我用Claude白嫖了整个Github,现在每天只工作2小时 https://zhuanlan.zhihu.com/p/1998522824734815001
|
||
3. 【解读EvoMap(Evolver),让Openclaw自我进化的神秘机制】 https://www.bilibili.com/video/BV1hcf1BxETm/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
6. Agent
|
||
1. 【Agent 的概念、原理与构建模式 —— 从零打造一个简化版的 Claude Code】 https://www.bilibili.com/video/BV1TSg7zuEqR/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
2. 《AI Agent设计实战:智能体设计的方法与技巧》
|
||
3. 如何从0开始写一个AI Agent: nanobot源码分析 https://km.netease.com/v4/detail/blog/259144
|
||
1. 学习OpenClaw、OpenCode来编写AITA Agent。
|
||
2. Agent论文 大学生。
|
||
3. 【那些 Agent 神文没告诉你的事:照着做,系统只会更烂 【AI agent 搭建实操指南】】 https://www.bilibili.com/video/BV1nPq2BoEf3/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
4. 【AI agent 开发千万别越努力,越心酸!【AI agent 搭建实操指南 第二弹】】 https://www.bilibili.com/video/BV1VzvYBBE92/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
|
||
4. WY工具
|
||
1. Claude Dashboard:AI并行编程的指挥中心 https://km.netease.com/v4/detail/blog/258957
|
||
2. WY MCP市场:https://modelspace.netease.com/mcphub
|
||
5. 开发案例:
|
||
1. 【GLM-5 一战封神,如何用他构建全自动开发系统?】 https://www.bilibili.com/video/BV1zZcYz1EMy/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
6. 其他大模型:【免费Claude Code,免费模型有满血版几成功力? Claude Code高热度AI编程工具】 https://www.bilibili.com/video/BV1jGtEzNEAv/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
1. 【普通人学AI,如何理智地选择Coding Plan】 https://www.bilibili.com/video/BV14yfuBnEkc/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
2. ClaudeCode API:可以通过OpenRouter来中转API。
|
||
3. GLM5
|
||
4. QWen
|
||
5. Gemini
|
||
7. Trae
|
||
1. 【MCP到虚幻5,感觉吃了一坨大的,但是有点甜!AI创作游戏前瞻,trae+UE】 https://www.bilibili.com/video/BV1JmG9zPEqw/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
2. ***【TRAE正式上线Seed 2.0模型!和Seedance2同代的编程模型,Seed2.0到底什么水平*** https://www.bilibili.com/video/BV1y8ZLBcEMQ/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
8. MacStudio叠罗汉
|
||
1. 在 Mac Studio 集群上用 MLX 做分布式推理 / 训练,核心是**统一环境、免密 SSH、低延迟网络、mlx.launch 调度**,推荐优先用 Thunderbolt 5 + RDMA 以获得最佳性能。
|
||
9. 其他
|
||
1. 它把Coding Agent 是怎么工作的讲清楚了 https://www.zhihu.com/pin/1996206268008927358?native=1&scene=share&share_code=rhJTYBz9Y9iW&utm_psn=2006646711288870147
|
||
2. 【【深度解析】字节开源 OpenViking:给 AI Agent 装上文件系统-哔哩哔哩】 https://b23.tv/LXBFLLj
|
||
3. 【手把手教你做Skill,把Github变成本地知识库】 https://www.bilibili.com/video/BV1p46eBPEWP/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
4. 【聊一下AI时代怎么选取信息源】 https://www.bilibili.com/video/BV1xr6GB5EnH/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
5. ClaudeCode Three3D.js Skill https://github.com/CloudAI-X/threejs-skills
|
||
6. 【【OpenCode】小彭老师skills+提示词配置分享】 https://www.bilibili.com/video/BV16WfwBDE4y/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
1. https://github.com/archibate/dotfiles-opencode
|
||
|
||
|
||
|
||
## Skill与MCP对比
|
||
| | 侧重点 | 类比 | Token消耗 | 核心主体 | 编写难度 |
|
||
| ------------ | -------- | -------------- | --------- | ------------ | -------- |
|
||
| Agent Skills | 提示词 | 带目录的说明书 | 低 | Markdown文件 | 低 |
|
||
| MCP | 工具调用 | 标准化工具箱 | 高 | 软件包 | 高 |
|
||
# Token
|
||
github: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
|
||
OpenClaw
|
||
y_yg3nEbh3s3xS3Z2-Vy
|
||
# WY API
|
||
- ANTHROPIC_AUTH_TOKEN:deweza3h28b2umy2.i0utchmh7l8ofrkliv6k1kbp2o42ahmg
|
||
- ANTHROPIC_BASE_URL:https://openai.nie.netease.com
|
||
- DISABLE_AUTOUPDATER:1
|
||
|
||
PS. 接入OpenClaw,API格式是基于OpenAI的。
|
||
|
||
# ClaudeCode
|
||
- 教学视频
|
||
- [【Claude Code 从 0 到 1 全攻略:MCP / SubAgent / Agent Skill / Hook / 图片 / 上下文处理/ 后台任务】 https://www.bilibili.com/video/BV14rzQB9EJj/?share_source=copy_web&vd_source=fe8142e8e12816535feaeabd6f6cdc8e
|
||
- 可视化客户端:https://github.com/getAsterisk/claudia
|
||
- Insight -> Forks -> xuzhenpeng263 / claudia-globa
|
||
|
||
## Claude.md
|
||
ClaudeCode每次启动都会读取这个文件。
|
||
|
||
### 🤔 为什么你需要一个 `CLAUDE.md` 文件?
|
||
Claude 每次对话都是独立的,没有项目记忆。`CLAUDE.md` 解决了这个问题,它会在每次会话开始时自动加载,告诉 Claude 关于你项目的一切,让你无需重复说明项目背景、代码风格或常用命令。
|
||
**编写优秀 `CLAUDE.md` 的核心原则:**
|
||
- **简洁为王,保持精悍**:Claude的上下文窗口是宝贵的资源。文件应尽量精炼,最好控制在300行以内,确保每一条信息都不可或缺。
|
||
- **具体明确,拒绝模糊**:指令要清晰、可操作。不要说“代码写得好一点”,而要规定“使用ES模块,推崇命名导出,变量命名采用驼峰式”这样的具体规则。
|
||
- **持续进化,动态更新**:这不是一份写完就固定的文档。在开发过程中,如果发现 Claude 的某些做法不符合预期,可以随时让它“更新 `CLAUDE.md`:以后都使用日志库替代 `console.log`”。通过这种持续迭代,让文件成为项目活的规范。
|
||
- **善用引用,分层管理**:对于庞大的项目,可以将通用规则放在根目录的 `CLAUDE.md` 中,而将特定模块的细节(如API设计模式)拆分到单独的文件里,再用 `@docs/api-patterns.md` 的方式引入。此外,`.claude/rules/` 目录和子目录下的 `CLAUDE.md` 文件也是实现模块化、按需加载的好方法。
|
||
|
||
### 🚀 优秀 `CLAUDE.md` 方案与实战案例
|
||
基于以上原则,这里为你提供一套可以直接套用的编写方案和几个不同场景的案例。
|
||
|
||
#### 基础通用模板
|
||
这个模板涵盖了大多数项目需要的基本信息,你可以根据自己的项目进行填充。
|
||
```markdown
|
||
# 项目: [项目名称]
|
||
|
||
一句话描述项目:这是一个[项目类型]应用,使用了[核心技术栈]和[关键集成服务]。
|
||
|
||
## 代码风格与规范
|
||
|
||
- **语言与框架**:[例如:TypeScript 严格模式,Next.js 14 App Router]
|
||
- **命名规则**:[例如:组件使用 PascalCase,工具函数使用 camelCase,样式类使用 kebab-case]
|
||
- **导入导出**:[例如:统一使用命名导出 (named export),避免默认导出 (default export)]
|
||
- **样式方案**:[例如:使用 TailwindCSS 工具类,禁止编写自定义 CSS 文件]
|
||
- **错误处理**:[例如:必须使用 try-catch 包裹异步操作,错误信息需记录到 Sentry]
|
||
|
||
## 重要命令
|
||
|
||
- `npm run dev`:启动开发服务器(端口 3000)
|
||
- `npm run build`:构建生产版本
|
||
- `npm run test`:运行单元测试 (Jest)
|
||
- `npm run lint`:运行代码检查 (ESLint)
|
||
- `npm run db:migrate`:执行数据库迁移
|
||
|
||
## 项目架构与重要约定
|
||
|
||
- `/app`:Next.js 路由和页面
|
||
- `/components/ui`:可复用的UI组件库
|
||
- `/lib`:工具函数和共享逻辑
|
||
- `/prisma`:数据库Schema和迁移文件
|
||
- **重要**:`/app/api/webhooks/stripe` 文件中的签名验证逻辑**严禁修改**
|
||
- **禁止**:将 `.env` 文件提交到代码仓库
|
||
```
|
||
|
||
#### 分层文件结构方案(适合大型项目)
|
||
当项目变得庞大时,单一文件会变得臃肿。可以采用分层结构,让 Claude 在不同目录下工作时,只加载最相关的规则。
|
||
```text
|
||
your-project/
|
||
├── CLAUDE.md # 全局规则:Git工作流、通用命令
|
||
├── .claude/
|
||
│ └── rules/
|
||
│ ├── testing.md # 测试规范,被根目录CLAUDE.md引用
|
||
│ └── security.md # 安全规范
|
||
├── backend/
|
||
│ └── CLAUDE.md # 后端专属规则:Python/FastAPI 风格、数据库操作
|
||
└── frontend/
|
||
└── CLAUDE.md # 前端专属规则:React/TypeScript 组件规范、状态管理
|
||
```
|
||
|
||
#### 案例一:Next.js 电商项目
|
||
这个案例来自 Builder.io 的博客,清晰地展示了如何为一个具体的 Next.js 电商项目编写指令。
|
||
```markdown
|
||
# Project: ShopFront
|
||
|
||
Next.js 14 e-commerce application with App Router, Stripe payments, and Prisma ORM.
|
||
|
||
## Code Style
|
||
|
||
- TypeScript strict mode, no `any` types
|
||
- Use named exports, not default exports
|
||
- CSS: Tailwind utility classes, no custom CSS files
|
||
|
||
## Commands
|
||
|
||
- `npm run dev`: Start development server (port 3000)
|
||
- `npm run test`: Run Jest tests
|
||
- `npm run test:e2e`: Run Playwright end-to-end tests
|
||
- `npm run lint`: ESLint check
|
||
- `npm run db:migrate`: Run Prisma migrations
|
||
|
||
## Architecture
|
||
|
||
- `/app`: Next.js App Router pages and layouts
|
||
- `/components/ui`: Reusable UI components
|
||
- `/lib`: Utilities and shared logic
|
||
- `/prisma`: Database schema and migrations
|
||
- `/app/api`: API routes
|
||
|
||
## Important Notes
|
||
|
||
- NEVER commit .env files
|
||
- The Stripe webhook handler in /app/api/webhooks/stripe must validate signatures
|
||
- Product images are stored in Cloudinary, not locally
|
||
- See @docs/authentication.md for auth flow details
|
||
```
|
||
|
||
#### 案例二:集成外部工具的支持调查员(Mergify 实战)
|
||
这个案例来自 Mergify 公司,展示了 `CLAUDE.md` 如何超越代码规范,成为一个复杂工作流的“大脑”。他们将技术支持手册编码进文件,让 Claude 能并行调查来自 Sentry、Datadog 和数据库的线索,将平均处理时间从15分钟锐减到5分钟以内。
|
||
```markdown
|
||
# Support Investigation Agent
|
||
|
||
You are an expert support engineer for Mergify. Your goal is to investigate customer tickets by gathering evidence from multiple systems in parallel.
|
||
|
||
## Investigation Workflow (Execute Steps in Parallel)
|
||
|
||
1. **Identify Context**: Extract `organization`, `repository`, and `PR number` from the ticket URL (fetched via Plain MCP).
|
||
2. **Launch Parallel Investigations (Wave 1)**:
|
||
- **Database Query (Read-Only)**: Use `/pr-event-log` slash command to get event timeline for the PR.
|
||
- **Error Tracking**: Search Sentry (via MCP) for errors related to the customer org and timeframe.
|
||
- **Logs**: Query Datadog (via MCP) for relevant log spikes.
|
||
- **Existing Tickets**: Search Linear (via MCP) for related, unresolved issues.
|
||
3. **Synthesize Findings**: Merge results from all sources into a unified timeline.
|
||
4. **Generate Output**: Draft a response with findings, hypothesis, and suggested next steps. If a new bug is confirmed, create a Linear ticket draft with a fix plan.
|
||
|
||
## Important Constraints
|
||
|
||
- All database queries MUST include a `LIMIT` clause and time filter.
|
||
- Never assume causality; present findings as correlations for the engineer to review.
|
||
- If the investigation involves engine code, inspect it under the `src/` directory.
|
||
- Check GitHub status for ongoing incidents if widespread failures are suspected.
|
||
```
|
||
|
||
### 💡 高级技巧与避坑指南
|
||
- **`/init` 命令是你的好帮手**:在新项目中,首先运行 `/init` 命令。Claude 会自动扫描你的项目结构、依赖和文档,生成一个不错的 `CLAUDE.md` 基础版本,你可以在这个基础上修改,比自己从零开始写要快得多。
|
||
- **用 @ 精确引用信息**:在 `CLAUDE.md` 中,你可以使用 `@` 符号引用其他文件,如 `@README.md` 或 `@docs/api-spec.md`。Claude 在需要时会自动读取这些文件的内容,这有助于保持主文件的简洁,同时又能提供深度信息。
|
||
- **区分团队共享与个人偏好**:将团队共有的规范放在项目内的 `CLAUDE.md` 中并提交至 Git。而个人的、无需共享的偏好(如最喜欢的 Pizza 口味、个人笔记),可以放在 `CLAUDE.local.md` 或通过 `@~/.claude/info.md` 引用,并确保这些文件被 Git 忽略。
|
||
- **通过代码审查持续改进**:当同事在代码审查中指出一个未文档化的约定或错误时,这就是更新 `CLAUDE.md` 的最佳时机。甚至可以直接在 PR 评论中 @Claude,让它根据评论自动更新文件,形成“发现问题 -> 更新规则 -> 预防未来问题”的良性循环。
|
||
- **避免“过度承诺”**:不要在文件中堆砌无用的套话,每一条指令都应该有它存在的价值。像“请编写高质量的代码”这种模糊指令可以删掉,它们只会稀释真正重要的信息。
|
||
## 操作命令
|
||
1. /init:扫描项目所有代码,并且记录上下文到**claude.md**。后续用户可以自己在里面补充相关信息。
|
||
2. **/compact**:压缩上下文。提高AI专注度并且可以节约token。 可以输入压缩策略,比如:重点保留用户需求。
|
||
3. **/clear**:清楚上下文。一般在新任务开启时使用。
|
||
1. 控制AI思考时间的关键词 think < think hard < think harder < ultrathink
|
||
4. **/resume**:回到上一个对话。
|
||
5. **/skills**:在项目目录下新建Skills文件夹,在里面添加Skill。
|
||
1. 可以输出/SkillName,主动让ClaudeCode调用指定Skill。
|
||
6. **/ide**:可以打通ClaudeCode与对应IDE。
|
||
7. /rewind 或者 按2下ESC:回滚这一步操作。
|
||
8. /tasks:查看后台任务。
|
||
9. ! 临时执行命令行。
|
||
10. # 向claude说明相关知识。
|
||
11. 在命令行中开启危险模式**输入:** `/permission` 或 `/config` 在弹出的设置菜单中,寻找 **"Auto-approve safe commands"** 或 **"Full Auto-approve"** 选项并开启。
|
||
12. 启动危险模式:claude --dangerously-skip-permissions;执行完某个Prompt后退出:claude -p "运行测试并修复报错" --dangerously-skip-permissions
|
||
13. 切换模型:
|
||
1. claude --model claude-opus-4-6
|
||
2. claude --model glm-4.7-flash:q8_0
|
||
14. 永久修改模型设置:claude config set -g model claude-opus-4-6
|
||
|
||
## Hook
|
||
当用户做到某项操作后自动执行某项命令。
|
||
- PreToolUse:
|
||
- PostToolUse:
|
||
- Notification
|
||
- UsePromptSubmit
|
||
- Stop
|
||
- SubagentStop
|
||
- PreCompact
|
||
- SessionStart
|
||
|
||
Common
|
||
- Task
|
||
- Bash
|
||
- Glob
|
||
- Read
|
||
- Edit
|
||
- MultiEdit
|
||
- Write
|
||
|
||
## SubAgent
|
||
用于哪些与主Agent上下文关系不大的任务。
|
||
- 提示词
|
||
- 这是一个用于代码审核的 SubAgent。在用户要求“代码审核”的时候调用它。
|
||
|
||
|
||
## 历史对话
|
||
- RonitSachdev/CCUndo:回退对话并且回退代码。
|
||
# Plugin
|
||
用于将一系列的Skill、SubAgent、Hook等能力都打包到一起,你只需要一键安装即可。
|
||
使用/plugin来进行安装,通过find来寻找插件。
|
||
推荐插件:
|
||
- Context7
|
||
|
||
# 其他相关知识
|
||
## Agent Teams 工作机制与原理
|
||
在深入案例之前,先理解 Agent Teams 的底层工作机制。这有助于理解后续协作中发生的每一个事件。
|
||
### **2.1 架构概览**
|
||
```
|
||
┌─────────────────────────────────────────────────────────┐
|
||
│ 用户(Human) │
|
||
│ │ │
|
||
│ ▼ │
|
||
│ ┌─────────────────┐ │
|
||
│ │ Team Lead │ ◀── 主 Claude 会话 │
|
||
│ │ (Orchestrator) │ │
|
||
│ └────────┬────────┘ │
|
||
│ │ │
|
||
│ ┌────────────┼────────────┐ │
|
||
│ │ SendMessage / TaskUpdate │ │
|
||
│ │ (异步消息队列) │ │
|
||
│ ▼ ▼ ▼ │
|
||
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
|
||
│ │ Agent A │ │ Agent B │ │ Agent C │ ◀── 子进程 │
|
||
│ │(Architect)│ │(Backend) │ │(Frontend)│ │
|
||
│ └──────────┘ └──────────┘ └──────────┘ │
|
||
│ │ │ │ │
|
||
│ └────────────┼────────────┘ │
|
||
│ ▼ │
|
||
│ 共享文件系统 │
|
||
│ (api-contract.yaml, │
|
||
│ shared-types.ts, ...) │
|
||
└─────────────────────────────────────────────────────────┘
|
||
```
|
||
### 2.2 核心组件
|
||
#### **Team(团队)**
|
||
通过 TeamCreate 创建,在 ~/.claude/teams/{team-name}/config.json 生成团队配置文件。团队是一个逻辑分组,包含:
|
||
- 团队名称和描述
|
||
- 成员列表(name、agentId、agentType)
|
||
- 与 TaskList 的 1:1 对应关系
|
||
#### **Agent(智能体)**
|
||
每个 Agent 是一个独立的 Claude 子进程,通过 Task 工具启动(subagent_type: general-purpose)。每个 Agent 拥有:
|
||
- **独立的上下文窗口**:Agent 之间不共享对话历史
|
||
- **独立的工具集**:可以读写文件、执行 bash 命令、搜索代码等
|
||
- **异步消息队列**:接收来自其他 Agent 或 Team Lead 的消息
|
||
- **团队感知**:可以读取团队配置文件,知道队友是谁
|
||
|
||
#### **TaskList(任务列表)**
|
||
通过 TaskCreate、TaskUpdate、TaskList 等工具管理。任务系统提供:
|
||
- **状态机**:pending → in_progress → completed
|
||
- **依赖关系**:blockedBy / blocks 实现任务间的前后依赖
|
||
- **分配机制**:owner 字段标识任务归属
|
||
|
||
#### **SendMessage(消息系统)**
|
||
Agent 间通信的唯一方式。消息类型包括:
|
||
- message:点对点消息(Agent A → Agent B)
|
||
- broadcast:广播消息(发送给所有队友)
|
||
- shutdown_request / shutdown_response:优雅关闭协议
|
||
|
||
### **2.3 通信模型:异步邮箱 + 空闲通知**
|
||
Agent Teams 的通信是**异步的**,这是理解整个协作过程的关键:
|
||
```
|
||
Agent A Agent B
|
||
│ │
|
||
├─── SendMessage ──────────▶│ (消息进入 B 的邮箱)
|
||
│ │
|
||
├─── 继续工作... │ (B 可能正忙,消息排队)
|
||
│ │
|
||
│ ├── 本轮工作结束
|
||
│ ├── 检查邮箱,读取消息
|
||
│ ├── 处理消息,发送回复
|
||
│ ◀── idle_notification ───┤ (B 的轮次结束,系统自动通知)
|
||
│ │
|
||
```
|
||
|
||
**关键机制:**
|
||
1. **消息不会打断正在工作的 Agent**:如果 Agent B 正在写代码,Agent A 发送的消息会在 B 的邮箱中排队,直到 B 当前轮次结束后才会被处理。
|
||
2. **idle_notification 是系统自动发送的**:当一个 Agent 的轮次结束(无论是完成了工作还是在等待输入),系统会自动向 Team Lead 发送空闲通知。这不是 Agent 主动发的。
|
||
3. **Agent 间不直接通信**:所有消息都通过邮箱系统路由。Agent A 发给 Agent B 的消息,Team Lead 可以在 idle_notification 的 summary 中看到摘要。
|
||
4. **共享文件系统是隐式通信通道**:虽然 Agent 间不共享上下文,但它们可以通过读写同一个文件(如 api-contract.yaml)来传递信息。
|
||
|
||
### **2.4 Agent 的生命周期**
|
||
```
|
||
创建(Task tool)
|
||
│
|
||
▼
|
||
初始化 ──▶ 读取 prompt ──▶ 开始工作
|
||
│
|
||
┌───────────┤
|
||
▼ ▼
|
||
完成工作 等待消息
|
||
│ │
|
||
▼ ▼
|
||
发送结果 idle (空闲)
|
||
│ │
|
||
▼ ▼
|
||
idle_notification ──▶ Team Lead
|
||
│
|
||
┌───────┤
|
||
▼ ▼
|
||
收到新消息 收到 shutdown_request
|
||
│ │
|
||
▼ ▼
|
||
继续工作 shutdown_response(approve)
|
||
│
|
||
▼
|
||
进程退出
|
||
```
|
||
|
||
### **2.5 任务依赖如何控制协作节奏**
|
||
这个案例中最关键的协调机制是**任务依赖**:
|
||
```
|
||
Task #1 (Architect: 设计 API) status: pending → in_progress → completed
|
||
│
|
||
├── blocks ──▶ Task #2 (Backend: 评审) ← blockedBy: [#1]
|
||
├── blocks ──▶ Task #3 (Frontend: 评审) ← blockedBy: [#1]
|
||
└── blocks ──▶ Task #4 (QA: 评审+测试) ← blockedBy: [#1]
|
||
```
|
||
当 Task #1 的状态变为 completed 时,Tasks #2/#3/#4 的 blockedBy 列表自动清空,Agent 可以通过 TaskList 发现任务可执行。
|
||
但实际操作中,**依赖关系是"软约束"** —— Agent 并不会自动被阻塞。Team Lead 需要主动告知 Agent "你的任务被阻塞了,请等待",或者 Agent 自己通过 TaskList 查看依赖状态后决定等待。
|
||
|
||
### **2.6 多团队工作流**
|
||
在这个案例里面,同一个 Team Lead **顺序创建、使用、销毁了 4 支团队**,每支团队负责一个阶段:
|
||
```
|
||
flash-sale (4 Agent) 合约设计 + 并行编码
|
||
│ 完成 → 销毁
|
||
▼
|
||
flash-sale-review (4 Agent) 代码评审
|
||
│ 完成 → 销毁
|
||
▼
|
||
p0-fix (9 Agent) P0 级问题并行修复
|
||
│ 完成 → 销毁
|
||
▼
|
||
remaining-fix (4 Agent) 剩余问题并行修复
|
||
│ 完成 → 销毁
|
||
```
|
||
|
||
每支团队拥有独立的 TaskList 和成员列表,团队之间通过**共享文件系统**传递成果(上一支团队的代码产出是下一支团队的评审/修复输入)。Team Lead 的主会话贯穿全程,是唯一跨团队的持久上下文。 |