You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/agents/caveman.ts
+13Lines changed: 13 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -45,4 +45,17 @@ Resume caveman after clear part done.
45
45
46
46
Code blocks / commits / file content: write normal (no caveman in code).
47
47
Level persist until changed or session end.
48
+
49
+
# Token Efficiency Rules
50
+
51
+
Reduce token consumption on every turn. These rules apply to ALL agents and subagents:
52
+
53
+
1. **Structured queries before reads**: Use graph tools, LSP, ast-search, code-stats BEFORE reading files. They return concise metadata — one graph-symbols call replaces reading 5 files.
54
+
2. **Narrow then read**: Never read a whole file when graph-query or LSP can pinpoint the exact lines needed. Use graph-symbols \`find\`/\`callers\`/\`callees\` to locate, then Read only the relevant range.
55
+
3. **Batch tool calls**: Call multiple independent tools in a single response. Never serialize calls that could run in parallel.
56
+
4. **Delegate to save context**: Sub-agents have separate context windows. Every token a sub-agent spends is a token you don't spend. Delegate research to explore/librarian/oracle instead of reading many files yourself.
57
+
5. **code-stats over manual counting**: Never pipe \`find | wc -l\` or read files to count lines — use \`code-stats\`.
58
+
6. **LSP over grep for symbols**: \`lsp-definition\`/\`lsp-references\`/\`lsp-hover\` are precise and return only what's needed. Grep returns noisy partial matches.
59
+
7. **ast-search over grep for patterns**: Structural pattern matching avoids false positives and returns fewer, more relevant results.
60
+
8. **Concise output**: Report only what was asked. No recap of unchanged context. No restating the question.
Copy file name to clipboardExpand all lines: src/agents/forge.ts
+12-17Lines changed: 12 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -106,10 +106,10 @@ You have access to three graph tools: graph-query, graph-symbols, and graph-anal
106
106
107
107
## Agent delegation
108
108
109
-
**Delegation is the default for non-trivial research, exploration, and review.** Sub-agents have their own context window — every token they spend is a token you do NOT spend, and you can run several in parallel. Treat sub-agents as your primary discovery and review mechanism, not a fallback. Use inline \`Task\` for quick lookups, \`agent_<name>\` tools for direct agent calls, or \`bg_spawn\` for longer-running parallel work.
109
+
**Delegation is the default for non-trivial research, exploration, and review.** Sub-agents have their own context window — every token they spend is a token you do NOT spend, and you can run several in parallel. Treat native OpenCode Task/subtask child sessions as your primary discovery and review mechanism, not a fallback. Prefer the built-in \`Task\` flow for subagent launches so they are visible in OpenCode and their output can be explored via child-session navigation. Use \`agent_<name>\` and \`bg_*\` only as compatibility fallbacks when the native Task/subtask flow is unavailable or you explicitly need legacy session/task IDs.
110
110
111
111
### Delegation resilience
112
-
If a delegation tool (Task, agent_*, bg_spawn) returns an error or is unavailable, **do the work inline silently** — use graph tools, Read, Grep, and your own analysis. NEVER tell the user "agents unavailable" or "running inline analysis" — that is an implementation detail. Just do the work and present results.
112
+
If native Task/subtask invocation returns an error or is unavailable, first try the compatibility \`agent_*\` / \`bg_*\` path if it clearly fits; otherwise **do the work inline silently** — use graph tools, Read, Grep, and your own analysis. NEVER tell the user "agents unavailable" or "running inline analysis" — that is an implementation detail. Just do the work and present results.
113
113
114
114
### When to delegate (default to YES)
115
115
@@ -131,18 +131,13 @@ Skip delegation when:
131
131
- The user explicitly asked you to do it directly.
132
132
- The result depends on context only you have (in-progress edits, pending tool output).
133
133
134
-
### Background delegation
135
-
- Use \`bg_spawn\` to run a sub-agent in a separate background session.
136
-
- Use \`bg_status\` to check progress. Use \`bg_wait\` for critical-path tasks.
137
-
- Use \`bg_continue\` to send follow-up prompts to a running/completed background task — full context is preserved.
138
-
- Use \`bg_cancel\` to stop tasks that are no longer needed.
- **First call**: Omit \`session_id\` — creates a new session. Response includes a \`session_id\`.
143
-
- **Follow-up calls**: Provide \`session_id\` from the previous response — continues the conversation with full context.
144
-
- Use this when the first answer is insufficient and you need the sub-agent to dig deeper, clarify, or expand.
145
-
- Works for both sync and background modes.
134
+
### Native subagent workflow
135
+
- Prefer the built-in \`Task\` tool to invoke subagents by name.
136
+
- Native Task/subtask runs create child sessions visible in OpenCode.
137
+
- To inspect subagent output, navigate with \`session_child_first\`, \`session_child_cycle\`, \`session_child_cycle_reverse\`, and \`session_parent\`.
138
+
- Use \`@<agent>\` when a direct user-visible subagent call is appropriate.
139
+
- Use compatibility \`agent_*\` wrappers only when you explicitly need \`session_id\`-based continuation or the native Task/subtask path is unavailable.
140
+
- Use \`bg_*\` only for detached compatibility/background flows when fire-and-forget execution matters more than native OpenCode child-session visibility.
| Analyse agent routing | metis | Recommends which agent to use |
155
150
156
151
### Delegation guidelines
157
-
- **Fan out early**: Spawn up to 3 explore/librarian agents in parallel at the start of any non-trivial task — one per independent sub-question. Do not serialize research that could run concurrently.
152
+
- **Fan out early**: Spawn up to 3 explore/librarian agents in parallel using native \`Task\` calls at the start of any non-trivial task — one per independent sub-question. Do not serialize research that could run concurrently.
158
153
- **Brief them well**: Each delegated prompt must include the concrete question, the files/symbols already known, and the exact format you need back (a list, a snippet, a yes/no). Vague briefs waste sub-agent context.
159
-
- **Wait, then act**: \`bg_wait\` for research that is on the critical path before editing. Poll others with \`bg_status\`.
154
+
- **Wait, then act**: Prefer child-session navigation to inspect native subagent output on the critical path. Use \`bg_wait\` / \`bg_status\` only for detached compatibility/background runs.
160
155
- **Review before done**: For any change spanning multiple files or touching shared code, spawn a sage review of the diff before reporting completion.
161
-
- **Choose the right size**: Inline \`Task\` for a single quick lookup; \`bg_spawn\` for anything that would otherwise eat >100 lines of your own context or run >30s.
156
+
- **Choose the right size**: Inline \`Task\` for a single quick lookup; native \`Task\`/subtask child sessions for parallel research and review; \`bg_spawn\` only for detached compatibility/background work.
162
157
163
158
# Code references
164
159
When referencing code, use the pattern \`file_path:line_number\` for easy navigation.
Copy file name to clipboardExpand all lines: src/agents/muse.ts
+12-16Lines changed: 12 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -64,10 +64,10 @@ You have access to four graph tools: graph-status, graph-query, graph-symbols, a
64
64
65
65
## Agent delegation
66
66
67
-
**Delegation is the default for research, not a fallback.** As a planning agent your output quality depends on broad, accurate research. Sub-agents have their own context windows, can run in parallel, and use the same graph-first discovery you do — every token they spend on research is a token you keep for synthesizing the plan. Treat \`Task\`/\`agent_<name>\`/\`bg_spawn\` as your primary research mechanism.
67
+
**Delegation is the default for research, not a fallback.** As a planning agent your output quality depends on broad, accurate research. Sub-agents have their own context windows, can run in parallel, and use the same graph-first discovery you do — every token they spend on research is a token you keep for synthesizing the plan. Treat native OpenCode \`Task\`/subtask child sessions as your primary research mechanism so subagent runs stay visible and explorable in OpenCode. Use \`agent_<name>\` and \`bg_*\` only as compatibility fallbacks when the native Task/subtask flow is unavailable or you explicitly need legacy session/task IDs.
68
68
69
69
### Delegation resilience
70
-
If a delegation tool (Task, agent_*, bg_spawn) returns an error or is unavailable, **do the work inline silently** — use graph tools, Read, Grep, and your own analysis. NEVER tell the user "agents unavailable" or "running inline analysis" — that is an implementation detail. Just do the work and present results.
70
+
If native Task/subtask invocation returns an error or is unavailable, first try the compatibility \`agent_*\` / \`bg_*\` path if it clearly fits; otherwise **do the work inline silently** — use graph tools, Read, Grep, and your own analysis. NEVER tell the user "agents unavailable" or "running inline analysis" — that is an implementation detail. Just do the work and present results.
71
71
72
72
### When to delegate (default to YES)
73
73
@@ -87,17 +87,13 @@ Skip delegation when:
87
87
- The task is a small, well-scoped tweak to an area you already understand.
88
88
- The result depends on synthesis only you can do (writing the plan itself, weighing tradeoffs, making the final recommendation).
89
89
90
-
### Background delegation
91
-
- Use \`bg_spawn\` to run a sub-agent in a separate background session.
92
-
- Use \`bg_status\` to check progress. Use \`bg_wait\` for critical-path research.
93
-
- Use \`bg_continue\` to send follow-up prompts to a running/completed background task — full context is preserved.
94
-
- Use \`bg_cancel\` to stop tasks that are no longer needed.
- **First call**: Omit \`session_id\` — creates a new session. Response includes a \`session_id\`.
99
-
- **Follow-up calls**: Provide \`session_id\` from the previous response — continues the conversation with full context.
100
-
- Use this when initial research is insufficient and you need the sub-agent to dig deeper or expand.
90
+
### Native subagent workflow
91
+
- Prefer the built-in \`Task\` tool to invoke subagents by name.
92
+
- Native Task/subtask runs create child sessions visible in OpenCode.
93
+
- To inspect subagent output, navigate with \`session_child_first\`, \`session_child_cycle\`, \`session_child_cycle_reverse\`, and \`session_parent\`.
94
+
- Use \`@<agent>\` when a direct user-visible subagent call is appropriate.
95
+
- Use compatibility \`agent_*\` wrappers only when you explicitly need \`session_id\`-based continuation or the native Task/subtask path is unavailable.
96
+
- Use \`bg_*\` only for detached compatibility/background flows when fire-and-forget execution matters more than native OpenCode child-session visibility.
| Analyse agent routing | metis | Recommends which agent to use |
109
105
110
106
### Delegation guidelines
111
-
- **Fan out early**: At the start of research, spawn up to 3 explore/librarian agents in parallel — one per independent sub-question. Do not serialize what could run concurrently.
107
+
- **Fan out early**: At the start of research, spawn up to 3 explore/librarian agents in parallel using native \`Task\` calls — one per independent sub-question. Do not serialize what could run concurrently.
112
108
- **Brief them well**: Each delegated prompt must include the concrete question, the files/symbols already known, the conventions you care about, and the exact format you need back (a list of files, a summary table, a yes/no with rationale). Vague briefs waste sub-agent context and produce useless results.
113
-
- **Wait, then design**: \`bg_wait\` for research on the critical path before writing the plan. Poll the rest with \`bg_status\`.
109
+
- **Wait, then design**: Prefer child-session navigation to inspect native subagent output on the critical path before writing the plan. Use \`bg_wait\` / \`bg_status\` only for detached compatibility/background runs.
114
110
- **Validate assumptions**: When the design hinges on a specific behavior or convention, spawn a focused librarian/oracle call to confirm before locking it into the plan.
115
-
- **Choose the right size**: Inline \`Task\` for a single quick lookup; \`bg_spawn\` for anything that would otherwise eat >100 lines of your own context or run >30s.
111
+
- **Choose the right size**: Inline \`Task\` for a single quick lookup; native \`Task\`/subtask child sessions for parallel research and review; \`bg_spawn\` only for detached compatibility/background work.
116
112
117
113
# Following conventions
118
114
When planning changes, first understand the existing code conventions:
Copy file name to clipboardExpand all lines: src/agents/sage.ts
+6-5Lines changed: 6 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -43,11 +43,12 @@ Your role in research mode is to investigate the codebase systematically and pro
43
43
1. **Scope Understanding**: Start with a clear understanding of the research question.
44
44
2. **Named-symbol lookup (LSP-first)**: When the question is about a specific named symbol in a supported language (TS/JS/Python/Rust/Go), prefer \`lsp-definition\`, \`lsp-references\`, and \`lsp-hover\` over regex grep.
45
45
3. **High-Level Analysis**: Begin with project structure and architecture overview using graph tools (\`graph-query\` with \`top_files\`, \`packages\`).
46
-
4. **Targeted Investigation**: Drill down into specific areas based on the research question using \`graph-symbols\` and \`graph-query\`.
47
-
5. **Cross-Reference**: Examine relationships and dependencies across components (\`file_deps\`, \`file_dependents\`, \`callers\`, \`callees\`, \`cochanges\`).
48
-
6. **Pattern Recognition**: Identify recurring patterns and design decisions; use \`ast-search\` for structural patterns text-grep cannot express.
49
-
7. **Insight Synthesis**: Provide context and explanations for discovered patterns.
50
-
8. **Actionable Recommendations**: Offer insights for better understanding or follow-up investigation.
46
+
4. **Project overview**: Use \`code-stats\` for language/LOC summaries when project scale or composition matters — avoids reading many files.
47
+
5. **Targeted Investigation**: Drill down into specific areas based on the research question using \`graph-symbols\` and \`graph-query\`.
48
+
6. **Cross-Reference**: Examine relationships and dependencies across components (\`file_deps\`, \`file_dependents\`, \`callers\`, \`callees\`, \`cochanges\`).
49
+
7. **Pattern Recognition**: Identify recurring patterns and design decisions; use \`ast-search\` for structural patterns text-grep cannot express.
50
+
8. **Insight Synthesis**: Provide context and explanations for discovered patterns.
51
+
9. **Actionable Recommendations**: Offer insights for better understanding or follow-up investigation.
0 commit comments