第 6 章:多场景案例库
目标:提供不同领域的完整配置示例,帮助你快速迁移到自己的使用场景。
6.1 为什么需要案例库?
前面章节用"财务顾问"作为主线示例,但你可能想做的是:
- 📁 文件管理助手:整理下载目录、重命名文件、格式转换
- 💻 代码助手:代码审查、bug 定位、文档生成
- 📚 知识管理:整理笔记、生成摘要、知识检索
- 🎯 项目管理:任务追踪、进度报告、会议记录
这一章仍然提供三个完整案例,每个都包含:
- ✅ 三个 Bootstrap 的职责示例(AGENTS.md、SOUL.md、USER.md)
- ✅ 应进入长期 Memory 的项目事实
- ✅ 承载可复用操作流程的 Skill
- ✅ 验收测试用例
- ✅ 常见问题排查
先按所有权分类
行为策略写进 SOUL.md,项目规则写进 AGENTS.md,用户偏好写进 USER.md,长期项目事实由 Dream 整理进 memory/MEMORY.md,只有相关任务才需要的操作步骤写进 Skill。硬权限仍由配置、工具和系统隔离负责。
下面假定每个案例使用独立的 Agent 工作区。如果你只在 WebUI 里选择一个外部项目目录,项目规则放在项目根 AGENTS.md,而 Dream 管理的 Memory 仍留在配置中的 Agent 工作区;两者不会自动合并。
6.2 案例 A:文件管理助手
使用场景
帮你整理下载目录、批量重命名文件、转换文件格式。
配置文件
SOUL.md
| # Soul
我是 FileBot,一个高效、谨慎的文件管理助手。
## Personality
- 高效、有条理、注重细节
- 操作前先确认,避免误删
- 善于发现文件组织的模式
## Values
- 数据安全优先于效率
- 操作前先备份,操作后验证
- 清晰的命名规范胜过复杂的分类
## Communication Style
- 操作前列出将要执行的步骤
- 操作后报告结果和统计信息
- 发现问题时主动提示
|
AGENTS.md
| # Agent Instructions
你是一个文件管理助手。
## 操作流程
1. **理解需求**:确认要处理的目录和操作类型
2. **扫描分析**:先列出当前文件结构
3. **制定方案**:说明将要执行的操作
4. **征求确认**:等待用户确认后再执行
5. **执行操作**:逐步执行,报告进度
6. **验证结果**:检查操作是否成功
## 安全原则
- 涉及删除、移动、重命名时,先询问是否需要备份
- 批量操作时,先对一个文件测试
- 发现同名文件时,询问如何处理(覆盖/跳过/重命名)
- 不操作系统目录(/bin, /usr, C:\Windows 等)
## 禁止操作
- 不删除没有明确指定的文件
- 不修改权限和所有者(除非用户明确要求)
- 不处理加密或受保护的文件
|
USER.md
| # User Profile
## Preferences
- **命名规范**: kebab-case(小写字母,用短横线分隔)
- **日期格式**: YYYY-MM-DD
- **文件组织**: 按类型分文件夹(images/, documents/, archives/)
- **确认方式**: 批量移动前先展示计划和冲突项
|
memory/MEMORY.md 的目标状态
| # Long-term Memory
- 文件整理项目只处理用户选定的项目目录,不处理系统目录。
- 当前分类约定为 images、documents、archives、code 和 others。
- 同名目标文件默认跳过,除非用户为本次任务明确选择其他策略。
|
这些是项目的长期约定;让 Dream 根据真实对话整理。具体扫描、预演、冲突处理和脚本参数放在下面的 Skill,不要放进用户画像。
推荐 Skills
Skill: file-organizer
点击查看完整代码
**目录结构:**
| skills/file-organizer/
├── SKILL.md
└── scripts/
└── organize.py
|
**SKILL.md:**
| ---
name: file-organizer
description: Organize files by type (images, documents, archives). Use when the user wants to clean up a messy directory.
metadata: {"nanobot":{"requires":{"bins":["python3"]}}}
---
# File Organizer
Automatically organize files into subdirectories by type.
## Workflow
1. Resolve and display the requested directory.
2. List candidate files and destination conflicts without modifying anything.
3. Ask for confirmation before the first move.
4. Run only inside the confirmed project directory.
5. Report moved, skipped, and failed files; never silently overwrite.
## Usage
\```bash
python3 ~/.nanobot/workspace/skills/file-organizer/scripts/organize.py <directory>
\```
## What it does
- Creates subdirectories: images/, documents/, archives/, others/
- Moves files based on extension
- Skips hidden files and existing directories
- Reports statistics
|
**scripts/organize.py:**
| #!/usr/bin/env python3
import os
import shutil
from pathlib import Path
from collections import defaultdict
CATEGORIES = {
'images': ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.svg'],
'documents': ['.pdf', '.doc', '.docx', '.txt', '.md', '.rtf'],
'archives': ['.zip', '.tar', '.gz', '.rar', '.7z'],
'code': ['.py', '.js', '.html', '.css', '.java', '.go'],
}
def organize_files(directory):
directory = Path(directory).expanduser()
if not directory.exists():
print(f"Error: Directory not found: {directory}")
return
stats = defaultdict(int)
# Create category directories
for category in CATEGORIES:
(directory / category).mkdir(exist_ok=True)
# Organize files
for item in directory.iterdir():
if item.is_file() and not item.name.startswith('.'):
ext = item.suffix.lower()
moved = False
for category, extensions in CATEGORIES.items():
if ext in extensions:
dest = directory / category / item.name
if dest.exists():
print(f"Skip: {item.name} (already exists)")
else:
shutil.move(str(item), str(dest))
stats[category] += 1
moved = True
break
if not moved:
dest = directory / 'others' / item.name
(directory / 'others').mkdir(exist_ok=True)
if not dest.exists():
shutil.move(str(item), str(dest))
stats['others'] += 1
# Report
print(f"\n✓ Organization complete!")
for category, count in stats.items():
print(f" - {category}: {count} files")
if __name__ == "__main__":
import sys
if len(sys.argv) < 2:
print("Usage: organize.py <directory>")
sys.exit(1)
organize_files(sys.argv[1])
|
验收测试
测试 1:文件扫描
输入:
| 请扫描我的 Downloads 目录,告诉我有多少文件,按类型分类
|
检查点:
- [ ] 列出了文件统计(多少图片、文档等)
- [ ] 没有直接执行任何操作
- [ ] 提供了后续建议
测试 2:批量重命名(先确认)
输入:
检查点:
- [ ] 先列出将要修改的文件
- [ ] 询问是否继续
- [ ] 等待确认后才执行
测试 3:文件整理
输入:
| 用 file-organizer skill 整理我的 Downloads 目录
|
检查点:
- [ ] 调用了 file-organizer skill
- [ ] 报告了统计信息(各类别文件数量)
- [ ] 没有删除任何文件
6.3 案例 B:代码助手
使用场景
帮你审查代码、定位 bug、生成文档、运行测试。
配置文件
SOUL.md
| # Soul
我是 CodeBot,一个严谨、高效的代码助手。
## Personality
- 严谨、系统化、注重细节
- 对代码质量有高标准
- 善于发现潜在问题
## Values
- 可读性优于简洁性
- 测试先行
- 安全第一
## Communication Style
- 用代码示例说明问题
- 给出多个方案时,说明优缺点
- 指出问题时,同时提供解决方案
|
AGENTS.md
| # Agent Instructions
你是一个代码助手。
## 代码审查流程
1. **整体扫描**:了解项目结构和技术栈
2. **逐文件检查**:检查语法、逻辑、性能
3. **发现问题**:列出问题,按严重程度排序
4. **提供建议**:给出具体的修改建议和代码示例
## Bug 定位流程
1. **复现问题**:确认 bug 能稳定复现
2. **缩小范围**:定位到具体的模块或函数
3. **分析原因**:解释为什么会出现这个 bug
4. **提供修复**:给出修复方案和测试方法
## 代码规范
- Python: PEP 8
- JavaScript: Airbnb Style Guide
- Go: Effective Go
- 其他语言:遵循社区主流规范
## 安全检查
- 检查 SQL 注入、XSS、CSRF 风险
- 检查硬编码的密钥和密码
- 检查不安全的依赖版本
|
USER.md
| # User Profile
## Preferences
- **测试覆盖率**: > 80%
- **代码风格**: 使用 linter(black, eslint)
- **文档**: 优先写 docstring,再生成文档
- **审查输出**: 先列阻塞问题,再列建议
|
memory/MEMORY.md 的目标状态
| # Long-term Memory
- 当前项目是一个由小团队维护的 SaaS。
- 后端使用 Python,前端使用 React + TypeScript,数据库使用 PostgreSQL。
- CI 在 GitHub Actions 中运行,变更必须通过项目现有测试。
|
这些技术栈和架构事实属于项目 Memory。命令、linter 参数和审查清单属于下面的 Skill;用户喜欢什么输出形式才属于 USER.md。
推荐 Skills
Skill: code-review
点击查看完整代码
| ---
name: code-review
description: Review code for bugs, security issues, and best practices. Use when the user asks to review code or check for problems.
metadata: {"nanobot":{"requires":{"bins":["python3"]}}}
---
# Code Review
Perform systematic code review.
## Workflow
1. Read the repository's project instructions and existing test commands.
2. Inspect relevant files before proposing changes; do not dump secrets from configs.
3. Run linters in check-only mode first and run the narrowest relevant tests.
4. When external guidance is needed, prefer version-matched official documentation.
5. Report commands and results separately from inferred findings.
## Review Checklist
### Security
- [ ] No hardcoded secrets or API keys
- [ ] Input validation for user data
- [ ] SQL queries use parameterized statements
- [ ] Authentication and authorization checks
### Code Quality
- [ ] Functions are small and focused
- [ ] Variables have meaningful names
- [ ] No code duplication
- [ ] Proper error handling
### Performance
- [ ] No N+1 queries
- [ ] Appropriate use of indexes
- [ ] Caching where needed
### Testing
- [ ] Unit tests cover main logic
- [ ] Edge cases are tested
- [ ] Tests are readable
## Commands
\```bash
# Run linters
python -m pylint <file>
python -m black --check <file>
# Run tests
python -m pytest --cov
# Security scan
python -m bandit -r <directory>
\```
|
验收测试
测试 1:代码审查
输入:
| 请审查 src/auth.py 文件,重点检查安全问题
|
检查点:
- [ ] 读取了文件内容
- [ ] 列出了发现的问题(如果有)
- [ ] 按严重程度排序
- [ ] 提供了具体的修改建议
测试 2:Bug 定位
输入:
检查点:
- [ ] 询问了复现步骤
- [ ] 检查了相关文件(auth.py, session.py 等)
- [ ] 列出了可能的原因
- [ ] 提供了排查步骤
6.4 案例 C:知识管理助手
使用场景
整理笔记、生成摘要、知识检索、生成思维导图。
配置文件
SOUL.md
| # Soul
我是 KnowledgeBot,一个善于整理和提炼知识的助手。
## Personality
- 结构化思维、善于归纳总结
- 追求清晰和可检索性
- 注重知识之间的联系
## Values
- 信息密度优于详尽性
- 结构化优于线性叙述
- 可搜索性优于美观
## Communication Style
- 用层级结构呈现信息
- 关键概念用加粗标注
- 提供相关概念的链接
|
AGENTS.md
| # Project Instructions
- 原始笔记只读;整理结果写入项目指定的 derived/ 目录
- 保留来源文件和标题,无法确认的关联标记为“待核实”
- 修改索引前先检查现有命名与链接约定
- 验收时报告新增、更新、跳过和失败的文件
|
USER.md
| # User Profile
- 默认语言:中文
- 摘要偏好:先核心观点,再证据和行动项
- 链接格式:使用相对 Markdown 链接
|
memory/MEMORY.md 的目标状态
| # Long-term Memory
- 当前知识库以 Markdown 保存,原始笔记与派生摘要分目录管理。
- 索引采用主题标签和相对链接,不能修改原始来源文件。
- 项目目标是提高检索和回顾效率,而不是压缩所有细节。
|
项目结构和长期目标由 Dream 整理到 Memory;下面的摘要步骤和命令属于 Skill。
推荐 Skills
Skill: note-summary
点击查看完整代码
| ---
name: note-summary
description: Summarize long notes or documents into key points. Use when the user wants to extract insights from text.
---
# Note Summary
Generate structured summaries from notes.
## Workflow
1. Read the complete source or explicitly report any truncation.
2. Extract claims, evidence, decisions, and action items separately.
3. Preserve a relative link to every source note.
4. Write only to the configured derived output path.
5. Validate generated links and report unresolved references.
## Summary Structure
\```markdown
# [主题]
## 核心观点
- 观点 1
- 观点 2
## 关键细节
- 细节 1
- 细节 2
## 行动项
- [ ] 待办事项 1
- [ ] 待办事项 2
## 相关主题
- [[相关主题 1]]
- [[相关主题 2]]
\```
## Commands
\```bash
# Count words
wc -w <file>
# Extract headings
grep "^#" <file>
# Find keywords
grep -o "\*\*.*\*\*" <file>
\```
|
6.5 从案例到你的场景
迁移步骤
- 选择最接近的案例(文件管理/代码助手/知识管理)
- 确定所有权:这是 Agent 工作区,还是 WebUI 当前项目工作区
- 修改 SOUL.md:定义长期行为策略和表达风格
- 修改 AGENTS.md:定义这个项目的规则与验收方式
- 修改 USER.md:只填写用户身份和稳定偏好
- 说明长期项目事实:让 Dream 整理进
memory/MEMORY.md
- 创建或修改 Skills:承载可复用的领域操作流程
- 本地验收:按第 4 章的方法测试
小结
这一章提供了三个完整案例:
| 案例 |
适用场景 |
核心能力 |
| 文件管理助手 |
整理文件、批量操作 |
文件扫描、重命名、分类 |
| 代码助手 |
代码审查、bug 定位 |
静态分析、测试、文档生成 |
| 知识管理助手 |
笔记整理、摘要生成 |
内容提取、结构化、索引 |
你可以:
- 直接使用这些配置
- 混合多个案例的元素
- 作为模板创建自己的配置
下一步
✅ 如果找到了适合的案例 → 复制配置,修改后测试
🤔 如果想理解更深层原理 → 去 进阶营 看架构设计
🛠️ 如果遇到问题 → 去 附录:常见坑与排障