词元广场TOKPUB.COM - 欢迎您,支持一个 Key 调用近 600+ 海内外模型,限时特价模型低至 1 折,欢迎上岸!
理解 Agent 的本质,创建你的第一个自定义 Agent。

| 类型 | 说明 | 特点 |
|---|---|---|
| Workflow | LLM 和工具通过预定义代码路径编排 | 步骤固定、可预测 |
| Agent | LLM 动态指导自己的流程和工具使用 | 自主决策、灵活应对 |
| 场景 | 不用 Agent | 用 Agent |
|---|---|---|
| 代码审查 | 每次说"你是代码审查专家..." | 直接 @reviewer |
| 文档写作 | 每次说"用技术文档风格..." | 直接 @docs-writer |
| 安全审计 | 每次说"检查安全漏洞..." | 直接 @security-auditor |
| 类型 | 说明 | 调用方式 |
|---|---|---|
| Primary | 主 Agent,你直接交互的对象 | Tab 键切换 |
| Subagent | 子 Agent,被主 Agent 调用执行专项任务 | @agent名 或自动调用 |
| All | 混合模式,既可以作为主 Agent,也可以被调用 | Tab 切换或 @ 调用 |
用户 ←→ Primary Agent (build/plan)
↓
Task Tool (创建独立 Session)
↓
Subagent (explore/general/你的自定义 Agent)
↓
返回结果给 Primarymode: "all" 的 Agent:| 名称 | 模式 | 默认权限 | 说明 |
|---|---|---|---|
build | primary | 全部允许 | 默认开发 Agent,所有工具可用 |
plan | primary | edit: deny(仅 .opencode/plans/*.md 允许) | 只读规划,不修改代码 |
general | subagent | todoread/todowrite: deny | 通用研究,多步任务 |
explore | subagent | 仅允许 grep/glob/list/bash/read/webfetch/websearch/codesearch | 快速代码探索 |
关于 Explore Agent 的探索深度:调用 Explore 时可以指定探索深度级别。AI 会根据任务描述自动判断,你也可以在提示词中明确指定: quick:基本搜索,快速定位目标文件 medium:中等探索,平衡速度和覆盖面 very thorough:全面分析,跨多个位置和命名约定进行搜索 来源: agent.ts:150
关于 Plan Agent:它不是"需要确认才能编辑",而是默认禁止编辑,只有 .opencode/plans/*.md目录下的文件允许写入。这是为了让你在规划阶段专注思考,不被代码修改分心。来源: agent.ts:69-83
| 名称 | 用途 | 说明 |
|---|---|---|
title | 生成会话标题 | 使用 small_model |
summary | 生成会话摘要 | 用于压缩 |
compaction | 压缩上下文 | 当上下文过长时自动触发 |
来源: agent.ts:122-166
| 位置 | 作用范围 | 优先级 |
|---|---|---|
.opencode/agent/*.md | 当前项目 | 高 |
~/.config/opencode/agent/*.md | 全局所有项目 | 中 |
opencode.json 的 agent 字段 | 取决于文件位置 | 与 Markdown 合并 |
文件名即 Agent 名称: docs-writer.md创建名为docs-writer的 Agent。
.opencode/agent/docs-writer.md:| 字段 | 类型 | 说明 |
|---|---|---|
description | string | 建议填。Agent 简介,影响主 Agent 的自动选择决策 |
mode | enum | subagent | primary | all。默认 all |
model | string | 格式 provider/model。不填则继承主 Agent 当前模型 |
prompt | string | 系统提示词(JSON 配置专用,Markdown 中使用正文) |
temperature | number | 0-1,控制回答的随机性 |
top_p | number | 0-1,核采样参数 |
steps | number | 最大迭代步数,防止死循环 |
hidden | boolean | true 则从 @ 自动补全菜单中隐藏 |
color | string | 十六进制颜色 #RRGGBB,用于界面区分 |
permission | object | 权限配置对象 |
disable | boolean | 是否禁用此 Agent |
options | object | 透传参数容器,用于存放不常用的 Provider 参数 |
| 其他字段 | any | 未知字段会自动作为参数透传给 Provider(如 reasoningEffort) |
maxSteps已废弃,请使用steps。
| 模型 | 默认 Temperature | 说明 |
|---|---|---|
| Claude | undefined | 使用 API 默认 |
| GPT | undefined | 使用 API 默认 |
| Gemini | 1.0 | 固定值 |
| Qwen | 0.55 | 固定值 |
| GLM-4.6/4.7 | 1.0 | 固定值 |
| MiniMax-M2 | 1.0 | 固定值 |
| Kimi-K2 | 0.6 或 1.0 | thinking/k2./k2p 版本为 1.0,其他为 0.6 |
agent.temperature(用户设置) > 模型默认值 > undefinedcapabilities.temperature = true 的模型才会生效┌─────────────────────────────────────────────────────────────┐
│ 1. Agent prompt 或 Provider 默认提示词(二选一) │
│ ├─ 有 prompt → 使用你定义的 │
│ └─ 无 prompt → 使用模型默认(如 anthropic.txt) │
├─────────────────────────────────────────────────────────────┤
│ 2. 环境信息 + 指令文件(始终添加) │
│ 工作目录、git 状态、平台、日期 │
│ AGENTS.md、CLAUDE.md 等全局规则文件 │
└─────────────────────────────────────────────────────────────┘| Agent | 有自定义 prompt? | 实际使用的提示词 |
|---|---|---|
build | ❌ 无 | Provider 默认 |
plan | ❌ 无 | Provider 默认 |
general | ❌ 无 | Provider 默认 |
explore | ✅ 有 | 专用 prompt(文件 搜索专家) |
title | ✅ 有 | 专用 prompt(生成会话标题) |
summary | ✅ 有 | 专用 prompt(生成会话摘要) |
compaction | ✅ 有 | 专用 prompt(压缩上下文) |
| 模型 | 提示词文件 | 风格特点 |
|---|---|---|
| Claude | anthropic.txt | 强调 TodoWrite、使用专用工具、简洁输出 |
| GPT-5 | codex_header.txt | OpenAI Codex 专用 |
| GPT / O1 / O3 | beast.txt | 强调持续迭代、联网研究、自主解决 |
| Gemini | gemini.txt | 适配 Gemini 特性 |
| Trinity | trinity.txt | Trinity 模型专用 |
| 其他(Qwen 等) | qwen.txt | 类似 Anthropic 但不含 TodoWrite |
说明:未匹配到上述模型的会使用 qwen.txt(PROMPT_ANTHROPIC_WITHOUT_TODO)。
You are OpenCode, the best coding agent on the planet.
You are an interactive CLI tool that helps users with software engineering tasks.
Use the instructions below and the tools available to you to assist the user.
# Tone and style
- Only use emojis if the user explicitly requests it
- Your responses should be short and concise
- Output text to communicate with the user
# Task Management
You have access to the TodoWrite tools to help you manage and plan tasks.
Use these tools VERY frequently...You are opencode, an agent - please keep going until the user's query
is completely resolved, before ending your turn and yielding back to the user.
You MUST iterate and keep going until the problem is solved.
THE PROBLEM CAN NOT BE SOLVED WITHOUT EXTENSIVE INTERNET RESEARCH.
You must use the webfetch tool to recursively gather all information...anthropic.txt 或 beast.txt,然后在其后面追加环境信息和指令文件。你是代码审查专家,专注于安全和性能... ← 你的 prompt(替代默认)
You are powered by the model named... ← 环境信息
Working directory: /path/to/project ← 环境信息
... ← AGENTS.md 内容(如有)You are OpenCode, the best coding agent... ← Provider 默认
You are powered by the model named... ← 环境信息
Working directory: /path/to/project ← 环境信息
... ← AGENTS.md 内容(如有)