|
1 | 1 | --- |
2 | 2 | title: "Agents" |
3 | | -description: "Configure and use primary agents and subagents in OpenCode." |
| 3 | +description: "" |
4 | 4 | --- |
5 | 5 |
|
6 | 6 | Agents combine a system prompt, model preference, tool permissions, and display |
7 | 7 | metadata into a reusable assistant profile. OpenCode includes agents for common |
8 | 8 | workflows, and you can override them or add your own in configuration or |
9 | 9 | Markdown files. |
10 | 10 |
|
11 | | -## Modes |
12 | | - |
13 | | -An agent's `mode` controls where it can run: |
14 | | - |
15 | | -| Mode | Behavior | |
16 | | -| --- | --- | |
17 | | -| `primary` | Can be selected as the main agent for a session. It cannot be launched as a subagent. | |
18 | | -| `subagent` | Can run in a child session through the `subagent` tool, but cannot be selected as the main agent. | |
19 | | -| `all` | Can be used either way. This is the default for a custom agent when `mode` is omitted. | |
20 | | - |
21 | | -In the TUI, press <kbd>Tab</kbd> and <kbd>Shift</kbd>+<kbd>Tab</kbd> to cycle |
22 | | -through visible primary and `all` agents, or use `/agents` to choose one. |
23 | | - |
24 | | -Subagents run in child sessions with fresh context. A primary agent can invoke |
25 | | -one with the `subagent` tool, either in the foreground or in the background. |
26 | | -You can also `@` mention a visible subagent to ask the current agent to delegate |
27 | | -work to it: |
28 | | - |
29 | | -```text |
30 | | -@explore find where authentication errors are handled |
31 | | -``` |
32 | | - |
33 | | -The parent agent's `subagent` permission controls which agents it may launch. |
34 | | -The child currently uses its own configured permissions, not a restricted copy |
35 | | -of the parent's permissions. |
36 | | - |
37 | 11 | ## Built-in agents |
38 | 12 |
|
39 | 13 | | Agent | Mode | Purpose | |
@@ -66,42 +40,33 @@ be hidden. If it is unavailable, OpenCode falls back to `build`, then to the |
66 | 40 | first visible agent that can run as a primary agent. This selection does not |
67 | 41 | rewrite the agent already stored on an existing session. |
68 | 42 |
|
69 | | -## Configure agents |
| 43 | +## Modes |
70 | 44 |
|
71 | | -### JSON or JSONC |
| 45 | +An agent's `mode` controls where it can run: |
72 | 46 |
|
73 | | -Use the plural `agents` field in any [OpenCode configuration file](/config): |
| 47 | +| Mode | Behavior | |
| 48 | +| --- | --- | |
| 49 | +| `primary` | Can be selected as the main agent for a session. It cannot be launched as a subagent. | |
| 50 | +| `subagent` | Can run in a child session through the `subagent` tool, but cannot be selected as the main agent. | |
| 51 | +| `all` | Can be used either way. This is the default for a custom agent when `mode` is omitted. | |
74 | 52 |
|
75 | | -```jsonc title="opencode.jsonc" |
76 | | -{ |
77 | | - "$schema": "https://opencode.ai/config.json", |
78 | | - "default_agent": "reviewer", |
79 | | - "agents": { |
80 | | - "reviewer": { |
81 | | - "description": "Reviews changes for correctness, security, and missing tests", |
82 | | - "mode": "all", |
83 | | - "model": "anthropic/claude-sonnet-4-5#high", |
84 | | - "system": "Review the current changes. Report findings before any summary.", |
85 | | - "color": "warning", |
86 | | - "steps": 8, |
87 | | - "permissions": [ |
88 | | - { "action": "edit", "resource": "*", "effect": "deny" }, |
89 | | - { "action": "shell", "resource": "*", "effect": "deny" } |
90 | | - ] |
91 | | - }, |
92 | | - "build": { |
93 | | - "permissions": [ |
94 | | - { "action": "shell", "resource": "git push *", "effect": "ask" } |
95 | | - ] |
96 | | - } |
97 | | - } |
98 | | -} |
| 53 | +In the TUI, press <kbd>Tab</kbd> and <kbd>Shift</kbd>+<kbd>Tab</kbd> to cycle |
| 54 | +through visible primary and `all` agents, or use `/agents` to choose one. |
| 55 | + |
| 56 | +Subagents run in child sessions with fresh context. A primary agent can invoke |
| 57 | +one with the `subagent` tool, either in the foreground or in the background. |
| 58 | +You can also `@` mention a visible subagent to ask the current agent to delegate |
| 59 | +work to it: |
| 60 | + |
| 61 | +```text |
| 62 | +@explore find where authentication errors are handled |
99 | 63 | ``` |
100 | 64 |
|
101 | | -Agent definitions merge in configuration order. Later scalar fields replace |
102 | | -earlier values, request maps merge by key, and permission rules are appended. |
103 | | -Global `permissions` are applied to every agent before its agent-specific rules, |
104 | | -so a later agent rule can refine a global rule. |
| 65 | +The parent agent's `subagent` permission controls which agents it may launch. |
| 66 | +The child currently uses its own configured permissions, not a restricted copy |
| 67 | +of the parent's permissions. |
| 68 | + |
| 69 | +## Configure agents |
105 | 70 |
|
106 | 71 | ### Markdown files |
107 | 72 |
|
@@ -139,9 +104,40 @@ Review for correctness, security, regressions, and missing tests. |
139 | 104 | List findings in severity order with file and line references. |
140 | 105 | ``` |
141 | 106 |
|
142 | | -For compatibility with older layouts, V2 also discovers Markdown under |
143 | | -`agent/`, and treats files under `mode/` or `modes/` as primary agents. Prefer |
144 | | -`agents/` for new files. |
| 107 | +### JSON or JSONC |
| 108 | + |
| 109 | +Use the `agents` field in any [OpenCode configuration file](/config): |
| 110 | + |
| 111 | +```jsonc title="opencode.jsonc" |
| 112 | +{ |
| 113 | + "$schema": "https://opencode.ai/config.json", |
| 114 | + "default_agent": "reviewer", |
| 115 | + "agents": { |
| 116 | + "reviewer": { |
| 117 | + "description": "Reviews changes for correctness, security, and missing tests", |
| 118 | + "mode": "all", |
| 119 | + "model": "anthropic/claude-sonnet-4-5#high", |
| 120 | + "system": "Review the current changes. Report findings before any summary.", |
| 121 | + "color": "warning", |
| 122 | + "steps": 8, |
| 123 | + "permissions": [ |
| 124 | + { "action": "edit", "resource": "*", "effect": "deny" }, |
| 125 | + { "action": "shell", "resource": "*", "effect": "deny" } |
| 126 | + ] |
| 127 | + }, |
| 128 | + "build": { |
| 129 | + "permissions": [ |
| 130 | + { "action": "shell", "resource": "git push *", "effect": "ask" } |
| 131 | + ] |
| 132 | + } |
| 133 | + } |
| 134 | +} |
| 135 | +``` |
| 136 | + |
| 137 | +Agent definitions merge in configuration order. Later scalar fields replace |
| 138 | +earlier values, request maps merge by key, and permission rules are appended. |
| 139 | +Global `permissions` are applied to every agent before its agent-specific rules, |
| 140 | +so a later agent rule can refine a global rule. |
145 | 141 |
|
146 | 142 | ## Options |
147 | 143 |
|
|
0 commit comments