词元之母TOK.MOM - 平台充值汇率 1:1 即 1 人民币充值到账 1 美元,支持一个 Key 调用近 600+ 海内外模型,限时特价模型低至 1 折,欢迎上岸!
来源:Anthropic《Building Effective Agents》、Lilian Weng《LLM Powered Autonomous Agents》

"最成功的实现使用简单、可组合的模式,而非复杂框架。"
"显式展示 Agent 的规划步骤。"
"像设计人机界面(HCI)一样投入精力设计 Agent-计算机界面(ACI)。"
| 类型 | 特点 | 适用场景 | OpenCode 实现 |
|---|---|---|---|
| Workflow | 预定义代码路径,步骤固定 | 任务可预测、结构清晰 | Skill、Command |
| Agent | LLM 动态决策,自主探索 | 开放性问题、无法预测步骤 | Agent + Task tool |
任务来了
↓
步骤是否固定?
├─ 是 → 用 Workflow(Skill/Command)
└─ 否 → 需要多少自主性?
├─ 低 → 受限 Agent(steps + 权限控制)
└─ 高 → 完全自主 Agent{
"agent": {
"router": {
"description": "代码问题分类路由器",
"mode": "primary",
"permission": {
"task": {
"*": "deny",
"bug-fixer": "allow",
"performance-optimizer": "allow",
"security-auditor": "allow",
"refactor-expert": "allow"
}
}
}
}
}| 技术 | 说明 | 适用场景 |
|---|---|---|
| Chain of Thought | "一步步思考" | 通用推理 |
| Tree of Thoughts | 探索多个推理路径 | 复杂决策 |
| ReAct | 思考-行动-观察循环 | 需要与环境交互 |
| 类型 | 对应 | 特点 |
|---|---|---|
| 短期记忆 | 上下文窗口 | 有限,约几万 token |
| 长期记忆 | 外部向量库 | 无限,需要检索 |
@doc-parser、@translator-zh 等都是示例名称,OpenCode 没有内置这些 Agent。你需要按照 5.2a Agent 快速入门 学到的方法自己创建它们。description 字段本身就是一个够用的 prompt,配合低 temperature 就能工作。不需要额外写 .md 文件。用户输入 API 文档
↓
@doc-parser(解析文档结构)
↓
@translator-zh(翻译成中文)
@translator-ja(翻译成日文) ← 并行
@translator-ko(翻译成韩文)
↓
@doc-formatter(格式化输出)
↓
多语言文档// opencode.json
{
"$schema": "https://opencode.ai/config.json",
"agent": {
"doc-generator": {
"description": "多语言文档生成编排器",
"mode": "primary",
"prompt": "{file:./prompts/doc-generator.md}",
"permission": {
"task": {
"*": "deny",
"doc-parser": "allow",
"translator-*": "allow",
"doc-formatter": "allow"
}
}
},
"doc-parser": {
"description": "解析 API 文档结构,提取可翻译内容",
"mode": "subagent",
"temperature": 0.1
},
"translator-zh": {
"description": "英译中专家,保持技术术语准确",
"mode": "subagent",
"temperature": 0.3
},
"translator-ja": {
"description": "英译日专家",
"mode": "subagent",
"temperature": 0.3
},
"translator-ko": {
"description": "英译韩专家",
"mode": "subagent",
"temperature": 0.3
},
"doc-formatter": {
"description": "文档格式化,确保多语言版本格式一致",
"mode": "subagent",
"temperature": 0.1
}
}
}@security-auditor、@test-auditor 等都是示例名称,OpenCode 没有内置这些 Agent。你需要按照 5.2a Agent 快速入门 学到的方法自己创建它们。PR 代码变更
↓
@audit-coordinator(协调器)
↓
┌──────────────────────────────────┐
│ 并行执行(Sectioning) │
│ @security-auditor │
│ @performance-auditor │
│ @quality-auditor │
│ @test-auditor │
└──────────────────────────────────┘
↓
汇总所有发现
↓
@report-generator(生成报告)
↓
审计报告{
"$schema": "https://opencode.ai/config.json",
"agent": {
"audit-coordinator": {
"description": "代码审计协调器,编排多维度审计",
"mode": "subagent",
"model": "anthropic/claude-opus-4-5-thinking",
"prompt": "{file:./prompts/audit-coordinator.md}",
"steps": 50
},
"security-auditor": {
"description": "安全漏洞审计:注入、认证、数据泄露",
"mode": "subagent",
"temperature": 0.1,
"prompt": "{file:./prompts/security-auditor.md}",
"permission": {
"edit": "deny"
}
},
"performance-auditor": {
"description": "性能审计:复杂度、内存、并发",
"mode": "subagent",
"temperature": 0.1,
"permission": {
"edit": "deny"
}
},
"quality-auditor": {
"description": "代码质量审计:可读性、SOLID、重复代码",
"mode": "subagent",
"temperature": 0.2,
"permission": {
"edit": "deny"
}
},
"test-auditor": {
"description": "测试审计:覆盖率、边界情况、Mock 质量",
"mode": "subagent",
"temperature": 0.1,
"permission": {
"edit": "deny",
"bash": {
"*": "deny",
"npm test*": "allow",
"npm run test*": "allow"
}
}
},
"report-generator": {
"description": "生成结构化审计报告",
"mode": "subagent",
"temperature": 0.2
}
}
}performance-auditor、quality-auditor、test-auditor、report-generator 这四个没有引用外部 prompt 文件,它们会使用模型的默认提示词。对审计任务来说这不太够,你需要为每个专家创建 .md 文件。.opencode/
├── agent/
│ └── security-auditor.md ← 也可以放这里
└── prompts/
├── audit-coordinator.md ← 协调器(上面已有)
├── security-auditor.md ← 安全审计专家
├── performance-auditor.md ← 性能审计专家
├── quality-auditor.md ← 质量审计专家
├── test-auditor.md ← 测试审计专家
└── report-generator.md ← 报告生成器.opencode/agent/security-auditor.md:opencode.json 的配置中加上 "prompt": "{file:./prompts/xxx.md}"。提示:上面这些 prompt 是起点,不是终点。根据你的项目特点(语言、框架、业务),调整审计范围才能获得最 好的效果。
| 陷阱 | 表现 | 解决 |
|---|---|---|
| 过度设计 | 用多 Agent 解决简单问题 | 先用单 Agent 尝试 |
| 模糊描述 | description 太泛导致错误调用 | 具体说明适用场景 |
| 无限循环 | Agent 互相调用不停止 | 设置 steps 限制 |
| 权限过松 | subagent 可以做任何事 | 明确 task/edit/bash 权限 |
| 缺乏透明 | 不知道 Agent 在做什么 | 要求输出中间步骤 |
设计好 Agent 后,如何精确控制它能做什么、不能做什么?下一课深入权限系统。