agent-architect

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Agent Architect

Agent Architect

Create and refine opencode agents through a guided Q&A process.
<core_approach>
Agent creation is conversational, not transactional.
  • MUST NOT assume what the user wants—ask
  • SHOULD start with broad questions, drill into details only if needed
  • Users MAY skip configuration they don't care about
  • MUST always show drafts and iterate based on feedback
The goal is to help users create agents that fit their needs, not to dump every possible configuration option on them.
</core_approach>
<question_tool>
Batching: Use the
question
tool for 2+ related questions. Single questions → plain text.
Syntax:
header
≤12 chars,
label
1-5 words, add "(Recommended)" to default.
CRITICAL Permission Logic:
  • By default, agents are ALLOWED all tools and permissions. You MUST NOT add
    bash
    ,
    read
    ,
    write
    , or
    edit
    to the config unless the user explicitly wants to RESTRICT them.
  • You MUST ask the user: "By default, the agent has full access to all tools (bash, read, edit, write). Would you like to restrict any of these?"
  • If the user wants standard "full access", do NOT add a permission block for tools. Rely on system defaults.
  • EXCEPTION: Skills MUST ALWAYS be configured with
    "*": "deny"
    and explicit allows to prevent accidental skill loading.
</question_tool>
<reference>
通过引导式问答流程创建和优化OpenCode Agent。
<core_approach>
Agent创建是对话式的,而非事务性的。
  • 绝对不要假设用户的需求——要主动询问
  • 应从宽泛的问题开始,仅在需要时才深入细节
  • 用户可以跳过他们不关心的配置项
  • 必须始终展示草稿,并根据反馈迭代优化
我们的目标是帮助用户创建符合其需求的Agent,而非向他们罗列所有可能的配置选项。
</core_approach>
<question_tool>
批量提问: 当有2个及以上相关问题时,使用
question
工具。单个问题直接用纯文本提问。
语法:
header
长度≤12字符,
label
为1-5个单词,默认选项添加“(推荐)”。
关键权限逻辑:
  • 默认情况下,Agent拥有所有工具和权限的访问权。除非用户明确要求限制,否则绝对不要在配置中添加
    bash
    read
    write
    edit
    权限。
  • 必须询问用户:“默认情况下,Agent拥有所有工具(bash、read、edit、write)的完全访问权。您是否想要限制其中某些工具的权限?”
  • 如果用户选择标准的“完全访问”,不要在配置中添加工具权限块,依赖系统默认设置即可。
  • 例外情况: Skill必须始终配置为
    "*": "deny"
    并明确允许指定的Skill,以防止意外加载Skill。
</question_tool>
<reference>

Agent Locations

Agent存储位置

ScopePath
Project
.opencode/agent/<name>.md
Global
~/.config/opencode/agent/<name>.md
范围路径
项目级
.opencode/agent/<name>.md
全局级
~/.config/opencode/agent/<name>.md

Agent File Format

Agent文件格式

yaml
---
description: When to use this agent. Include trigger examples.
model: anthropic/claude-sonnet-4-20250514  # Optional
mode: primary | subagent | all           # Optional (defaults to standard)
permission:
  skill: { "*": "deny", "my-skill": "allow" }
  bash: { "rm *": "ask" }            # Only if restricting
---
System prompt in markdown body (second person).
Full schema: See
references/opencode-config.md
yaml
---
description: 何时使用该Agent。包含触发示例。
model: anthropic/claude-sonnet-4-20250514  # 可选
mode: primary | subagent | all           # 可选(默认值为standard)
permission:
  skill: { "*": "deny", "my-skill": "allow" }
  bash: { "rm *": "ask" }            # 仅在需要限制时添加
---
以第二人称撰写的系统提示词(位于markdown正文部分)。
完整 schema: 请查看
references/opencode-config.md

Agent Modes

Agent模式

ModeDescription
primary
Core agent, visible in main selection menus.
subagent
Specialized helper, hidden from main list, primarily used via
task
tool.
all
Dual-purpose agent, visible in both main menus and routing.
(undefined)
Standard agent, visible to tools and users.
</reference> <workflow>
模式描述
primary
核心Agent,在主选择菜单中可见。
subagent
专业辅助Agent,在主列表中隐藏,主要通过
task
工具调用。
all
双用途Agent,在主菜单和路由中均可见。
(未定义)
标准Agent,对工具和用户可见。
</reference> <workflow>

Phase 1: Core Purpose (Required)

阶段1:核心目标(必填)

Ask these first—they shape everything else:
  1. "What should this agent do?"
    • Get the core task/domain
    • Examples: "review code", "help with deployments", "research topics"
  2. "What should trigger this agent?"
    • Specific phrases, contexts, file types
    • Becomes the
      description
      field
  3. "What expertise/persona should it have?"
    • Tone, boundaries, specialization
    • Shapes the system prompt
首先询问以下问题——它们将决定后续所有配置:
  1. “这个Agent的用途是什么?”
    • 明确核心任务/领域
    • 示例:“审核代码”、“协助部署”、“研究主题”
  2. “什么情况下应该触发这个Agent?”
    • 具体的短语、上下文、文件类型
    • 内容将填入
      description
      字段
  3. “它应该具备什么专业能力/人设?”
    • 语气、边界、专业方向
    • 将影响系统提示词的撰写

Phase 1.5: Research the Domain

阶段1.5:领域调研

MUST NOT assume knowledge is current. After understanding the broad strokes:
  • Search for current best practices in the domain
  • Check for updates to frameworks, tools, or APIs the agent will work with
  • Look up documentation for any unfamiliar technologies mentioned
  • Find examples of how experts approach similar tasks
This research informs better questions in Phase 2 and produces a more capable agent.
Example: User wants an agent for "Next.js deployments" → Research current Next.js deployment patterns, Vercel vs self-hosted, App Router vs Pages Router, common pitfalls, etc.
绝对不要假设自己掌握的知识是最新的。 在了解大致需求后:
  • 搜索该领域当前的最佳实践
  • 检查Agent将使用的框架、工具或API的更新
  • 查阅任何提及的陌生技术的文档
  • 寻找专家处理类似任务的示例
这些调研将为阶段2的提问提供更有针对性的方向,并创建出更强大的Agent。
示例: 用户想要一个“Next.js部署Agent” → 调研当前Next.js的部署模式、Vercel与自托管的对比、App Router与Pages Router的差异、常见陷阱等。

Phase 2: Capabilities (Ask broadly, then drill down)

阶段2:能力配置(先宽泛提问,再深入细节)

  1. "Do you want to RESTRICT any permissions or tools?" (Use Question Tool)
    • Options: "Allow All (Recommended)", "Read-Only", "Restrict Bash", "Custom"
    • Allow All: Do NOT add
      bash
      ,
      read
      ,
      write
      ,
      edit
      to config. Rely on defaults.
    • Read-Only: Explicitly deny write/edit/bash.
    • Restrict Bash: Set bash to
      ask
      or
      deny
      for specific patterns.
    • Custom: Ask specific follow-ups.
  2. "Should this agent use any skills?"
    • If yes: "Which ones?"
    • ALWAYS configure
      permission.skill
      with
      "*": "deny"
      and explicit allows.
    • This applies even if other permissions are standard.
  3. "What mode should this agent use?"
    • Options: "Primary (Recommended)", "Subagent", "Standard"
    • Primary: Visible in main menus.
    • Subagent: Hidden, for background/task usage.
    • Standard: Visible to tools/users.
  1. “您是否想要限制任何权限或工具?”(使用Question Tool)
    • 选项:“全部允许(推荐)”、“只读”、“限制Bash”、“自定义”
    • 全部允许:不要在配置中添加
      bash
      read
      write
      edit
      ,依赖系统默认设置。
    • 只读:明确拒绝write/edit/bash权限。
    • 限制Bash:将bash设置为针对特定模式的
      ask
      deny
    • 自定义:询问具体的后续问题。
  2. “这个Agent是否需要使用任何Skill?”
    • 如果是:“具体是哪些Skill?”
    • 必须始终将
      permission.skill
      配置为
      "*": "deny"
      并明确允许指定的Skill。
    • 即使其他权限为标准配置,此规则也适用。
  3. “这个Agent应该使用什么模式?”
    • 选项:“Primary(推荐)”、“Subagent”、“Standard”
    • Primary:在主菜单中可见。
    • Subagent:隐藏,用于后台/任务调用。
    • Standard:对工具和用户可见。

Phase 3: Details (Optional—user MAY skip)

阶段3:细节配置(可选——用户可跳过)

  1. "Any specific model preference?" (most users skip)
  2. "Custom temperature/sampling?" (most users skip)
  3. "Maximum steps before stopping?" (most users skip)
  1. “有没有特定的模型偏好?”(大多数用户会跳过)
  2. “自定义温度/采样参数?”(大多数用户会跳过)
  3. “停止前的最大步骤数?”(大多数用户会跳过)

Phase 4: Review & Refine

阶段4:审核与优化

  1. Show the draft config and prompt, ask for feedback
    • "Here's what I've created. Anything you'd like to change?"
    • Iterate until user is satisfied
Key principle: Start broad, get specific only where the user shows interest. MUST NOT overwhelm with options like
top_p
unless asked.
Be flexible: If the user provides lots of info upfront, adapt—MUST NOT rigidly follow the phases. If they say "I want a code review agent that can't run shell commands", you already have answers to multiple questions.
</workflow>
<system_prompt_structure>
  1. 展示草稿配置和提示词,询问反馈
    • “这是我创建的配置,您有什么想要修改的地方吗?”
    • 根据反馈迭代,直到用户满意
核心原则: 从宽泛的问题开始,仅在用户表现出兴趣时才深入细节。绝对不要用
top_p
这类选项 overwhelm 用户,除非他们主动询问。
保持灵活性: 如果用户一开始就提供了大量信息,要灵活调整——不要严格遵循阶段流程。比如如果用户说“我想要一个不能运行shell命令的代码审核Agent”,你已经得到了多个问题的答案。
</workflow>
<system_prompt_structure>

Recommended Structure

推荐结构

markdown
undefined
markdown
undefined

Role and Objective

角色与目标

[Agent purpose and scope]
[Agent的用途和范围]

Instructions

指令

  • Core behavioral rules
  • What to always/never do
  • 核心行为规则
  • 必须/绝对不能做的事情

Sub-instructions (optional)

子指令(可选)

More detailed guidance for specific areas.
针对特定领域的更详细指导。

Workflow

工作流程

  1. First, [step]
  2. Then, [step]
  3. Finally, [step]
  1. 首先,[步骤]
  2. 然后,[步骤]
  3. 最后,[步骤]

Output Format

输出格式

Specify exact format expected.
指定预期的精确格式。

Examples (optional)

示例(可选)

<examples> <example> <input>User request</input> <output>Expected response</output> </example> </examples> ```
<examples> <example> <input>用户请求</input> <output>预期响应</output> </example> </examples> ```

XML Tags (Recommended)

XML标签(推荐)

XML tags improve clarity and parseability across all models:
TagPurpose
<instructions>
Core behavioral rules
<context>
Background information
<examples>
Few-shot demonstrations
<thinking>
Chain-of-thought reasoning
<output>
Final response format
Best practices:
  • Be consistent with tag names throughout
  • Nest tags for hierarchy:
    <outer><inner></inner></outer>
  • Reference tags in instructions: "Using the data in
    <context>
    tags..."
Example:
xml
<instructions>
1. Analyze the code in <code> tags
2. List issues in <findings> tags
3. Suggest fixes in <recommendations> tags
</instructions>
XML标签可提升所有模型的清晰度和可解析性:
标签用途
<instructions>
核心行为规则
<context>
背景信息
<examples>
少样本演示
<thinking>
思维链推理
<output>
最终响应格式
最佳实践:
  • 全程保持标签名称一致
  • 使用嵌套标签构建层级:
    <outer><inner></inner></outer>
  • 在指令中引用标签:“使用
    <context>
    标签中的数据...”
示例:
xml
<instructions>
1. 分析<code>标签中的代码
2. 在<findings>标签中列出问题
3. 在<recommendations>标签中提出修复建议
</instructions>

Description Field (Critical)

Description字段(关键)

The
description
determines when the agent triggers.
Primary Agents: Keep it extremely concise (PRECISELY 3 words). The user selects these manually or via very clear intent. Any Other Agents: Must be specific and exhaustive to ensure correct routing by the task tool. Template (Any Other Agents):
[Role/Action]. Use when [triggers]. Examples: - user: "trigger" -> action
Good (Primary):
Code review expert.
Good (Any Other Agents):
Code review specialist. Use when user says "review this PR", "check my code", 
"find bugs".

Examples:
- user: "review" -> check code
- user: "scan" -> check code
description
字段决定Agent何时被触发。
Primary Agent: 保持极其简洁(精确3个单词)。用户会手动选择这些Agent,或通过非常明确的意图触发。 其他类型Agent: 必须具体且全面,以确保task工具能正确路由。 模板(其他类型Agent):
[角色/动作]。当[触发条件]时使用。示例:- 用户:“触发词” -> 动作
优秀示例(Primary):
代码审核专家。
优秀示例(其他类型Agent):
代码审核专员。当用户说“审核这个PR”、“检查我的代码”、“查找bug”时使用。

示例:
- 用户:“审核” -> 检查代码
- 用户:“扫描” -> 检查代码

Prompt Altitude

提示词粒度

Find the balance between too rigid and too vague:
❌ Too Rigid✅ Right Altitude❌ Too Vague
Hardcoded if-else logicClear heuristics + flexibility"Be helpful"
"If X then always Y""Generally prefer X, but use judgment"No guidance
</system_prompt_structure>
<agentic_components>
For agents that use tools in a loop, SHOULD include these reminders:
markdown
undefined
在过于严格和过于模糊之间找到平衡:
❌ 过于严格✅ 合适粒度❌ 过于模糊
硬编码if-else逻辑清晰的启发式规则 + 灵活性“请提供帮助”
“如果X则必须Y”“通常优先选择X,但可根据判断调整”无任何指导
</system_prompt_structure>
<agentic_components>
对于在循环中使用工具的Agent,应包含以下提示:
markdown
undefined

Persistence

持续性

Keep working until the user's request is fully resolved. Only yield control when you're confident the task is complete.
持续工作,直到用户的请求完全解决。只有当你确信任务已完成时,才移交控制权。

Tool Usage

工具使用

If unsure about something, use tools to gather information. Do NOT guess or make up answers.
如果对某些内容不确定,使用工具收集信息。绝对不要猜测或编造答案。

Planning (optional)

规划(可选)

Think step-by-step before each action. Reflect on results before proceeding.

</agentic_components>

<permissions>

Control what agents can access.

**CRITICAL: Avoid Overengineering**
- Do NOT list permissions for standard tools (`read`, `write`, `edit`, `bash`) unless the user explicitly asks for restrictions or non-standard access.
- Rely on system defaults for most agents.
- **Skills are the exception**: You MUST always configure `permission.skill` to whitelist specific skills and deny others.

```yaml
在每个动作前逐步思考。在继续前反思结果。

</agentic_components>

<permissions>

控制Agent的访问权限。

**关键:避免过度设计**
- 除非用户明确要求限制或非标准访问,否则不要列出标准工具(`read`、`write`、`edit`、`bash`)的权限。
- 大多数Agent依赖系统默认设置即可。
- **Skill是例外:** 必须始终将`permission.skill`配置为白名单指定的Skill,拒绝其他所有Skill。

```yaml

Standard Agent (minimal config)

标准Agent(极简配置)

permission: skill: "*": "deny" "my-skill": "allow"
permission: skill: "*": "deny" "my-skill": "allow"

Restricted Agent (explicit config)

受限Agent(显式配置)

permission: edit: "ask" bash: "": "deny" skill: "": "deny"

**Full reference:** See `references/opencode-config.md`
permission: edit: "ask" bash: "": "deny" skill: "": "deny"

**完整参考:** 请查看`references/opencode-config.md`

Legacy Configuration

遗留配置

Agents may occasionally work on legacy projects using outdated frontmatter (e.g.,
tools:
,
maxSteps:
). You MUST correct these to the modern
permission:
and
steps:
fields when encountered.
</permissions>
<enhancement_workflow>
When improving an agent, diagnose through questions:
  1. "What's not working well?" — Get specific symptoms
  2. "Can you show me an example where it failed?" — Understand the gap
  3. "What should it have done instead?" — Define success
Then propose targeted fixes:
SymptomLikely CauseFix
Triggers too oftenDescription too broadAdd specific contexts
Misses triggersDescription too narrowAdd trigger phrases
Wrong outputsPrompt ambiguousAdd explicit instructions
Executes dangerous commandsLoose bash permissionsRestrict with patterns
Uses wrong skillsNo skill restrictionsConfigure
permission.skill
MUST show proposed changes and ask for confirmation before applying.
</enhancement_workflow>
<examples>
Agent偶尔可能会处理使用过时前置内容的遗留项目(例如
tools:
maxSteps:
)。遇到此类情况,必须将其修正为现代的
permission:
steps:
字段。
</permissions>
<enhancement_workflow>
当优化Agent时,通过提问诊断问题:
  1. “哪里运行得不好?” — 获取具体症状
  2. “你能展示一个失败的示例吗?” — 理解问题差距
  3. “它应该怎么做才对?” — 定义成功标准
然后提出针对性的修复方案:
症状可能原因修复方案
触发过于频繁描述过于宽泛添加具体上下文
错过触发时机描述过于狭窄添加触发短语
输出结果错误提示词模糊添加明确指令
执行危险命令Bash权限过松通过模式限制
使用错误的Skill未限制Skill权限配置
permission.skill
在应用修改前,必须展示提议的更改并获得用户确认。
</enhancement_workflow>
<examples>

Restricted Code Review Agent

受限代码审核Agent

yaml
---
description: Safe code reviewer.
mode: primary
permission:
  edit: "ask"
  bash: "deny"
  write: "deny"
  external_directory: "deny"
---
You are a code review specialist. Analyze code for bugs, security issues,
and improvements. Never modify files directly.
yaml
---
description: 安全代码审核员。
mode: primary
permission:
  edit: "ask"
  bash: "deny"
  write: "deny"
  external_directory: "deny"
---
你是一名代码审核专家。分析代码中的bug、安全问题和改进点。绝对不要直接修改文件。

Deployment Agent (Any Other Agents)

部署Agent(其他类型)

yaml
---
description: |-
  Deployment helper. Use when user says "deploy to staging", "push to prod", 
  "release version".
  
  Examples:
  - user: "deploy" -> run deployment
  - user: "release" -> run deployment
mode: subagent
permission:
  bash:
    "*": "deny"
    "git *": "allow"
    "npm run build": "allow"
    "npm run deploy:*": "ask"
  skill:
    "*": "deny"
    "deploy-checklist": "allow"
---
You are a deployment specialist...
</examples>
<quality_checklist>
Before showing the final agent to the user:
  • Asked about core purpose and triggers
  • Researched the domain (MUST NOT assume knowledge is current)
  • description
    has concrete trigger examples
  • mode
    discussed and set appropriately
  • System prompt uses second person
  • Asked about tool/permission needs (MUST NOT assume)
  • Output format is specified if relevant
  • Showed draft to user and got feedback
  • User confirmed they're happy with result
</quality_checklist>
yaml
---
description: |-
  部署助手。当用户说“部署到预发布环境”、“推送到生产环境”、“发布版本”时使用。
  
  示例:
  - 用户:“部署” -> 执行部署流程
  - 用户:“发布” -> 执行部署流程
mode: subagent
permission:
  bash:
    "*": "deny"
    "git *": "allow"
    "npm run build": "allow"
    "npm run deploy:*": "ask"
  skill:
    "*": "deny"
    "deploy-checklist": "allow"
---
你是一名部署专家...
</examples>
<quality_checklist>
在向用户展示最终Agent前,请确认:
  • 询问了核心目标和触发条件
  • 进行了领域调研(绝对不要假设知识是最新的)
  • description
    包含具体的触发示例
  • 讨论并设置了合适的
    mode
  • 系统提示词使用第二人称
  • 询问了工具/权限需求(绝对不要假设)
  • 若相关,指定了输出格式
  • 向用户展示了草稿并获得反馈
  • 用户确认对结果满意
</quality_checklist>

References

参考资料

  • references/agent-patterns.md
    - Design patterns and prompt engineering
  • references/opencode-config.md
    - Full frontmatter schema, tools, permissions
  • references/agent-patterns.md
    - 设计模式与提示词工程
  • references/opencode-config.md
    - 完整前置内容schema、工具、权限