Skip to content

Commit d44433a

Browse files
committed
feat: update agent visibility and enhance delegation guidelines for improved context management
1 parent 2595796 commit d44433a

13 files changed

Lines changed: 68 additions & 46 deletions

File tree

src/agents/caveman.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,17 @@ Resume caveman after clear part done.
4545
4646
Code blocks / commits / file content: write normal (no caveman in code).
4747
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.
4861
`

src/agents/explore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const exploreAgent: AgentDefinition = {
77
displayName: 'explore',
88
description: 'Open-ended exploration agent — optimised for parallel codebase discovery and research.',
99
mode: 'subagent',
10-
hidden: true,
10+
hidden: false,
1111
temperature: 0.2,
1212
toolSupported: true,
1313
tools: {

src/agents/forge.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ You have access to three graph tools: graph-query, graph-symbols, and graph-anal
106106
107107
## Agent delegation
108108
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.
110110
111111
### 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.
113113
114114
### When to delegate (default to YES)
115115
@@ -131,18 +131,13 @@ Skip delegation when:
131131
- The user explicitly asked you to do it directly.
132132
- The result depends on context only you have (in-progress edits, pending tool output).
133133
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.
139-
140-
### Conversational sub-agents
141-
Agent tools (\`agent_explore\`, \`agent_librarian\`, \`agent_sage\`, \`agent_oracle\`, \`agent_prometheus\`, \`agent_metis\`) support multi-turn conversations:
142-
- **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.
146141
147142
| Task Type | Delegate To | Notes |
148143
|-----------|-------------|-------|
@@ -154,11 +149,11 @@ Agent tools (\`agent_explore\`, \`agent_librarian\`, \`agent_sage\`, \`agent_ora
154149
| Analyse agent routing | metis | Recommends which agent to use |
155150
156151
### 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.
158153
- **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.
160155
- **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.
162157
163158
# Code references
164159
When referencing code, use the pattern \`file_path:line_number\` for easy navigation.

src/agents/librarian.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const librarianAgent: AgentDefinition = {
88
description:
99
'Research-only agent — finds information in the codebase using read-only tools. Returns structured findings.',
1010
mode: 'subagent',
11-
hidden: true,
11+
hidden: false,
1212
temperature: 0.0,
1313
toolSupported: true,
1414
tools: {

src/agents/metis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const metisAgent: AgentDefinition = {
77
displayName: 'metis',
88
description: 'Meta-agent — analyses the current session context and recommends which agent to use next.',
99
mode: 'subagent',
10-
hidden: true,
10+
hidden: false,
1111
temperature: 0.1,
1212
toolSupported: true,
1313
tools: {

src/agents/muse.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ You have access to four graph tools: graph-status, graph-query, graph-symbols, a
6464
6565
## Agent delegation
6666
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.
6868
6969
### 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.
7171
7272
### When to delegate (default to YES)
7373
@@ -87,17 +87,13 @@ Skip delegation when:
8787
- The task is a small, well-scoped tweak to an area you already understand.
8888
- The result depends on synthesis only you can do (writing the plan itself, weighing tradeoffs, making the final recommendation).
8989
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.
95-
96-
### Conversational sub-agents
97-
Agent tools (\`agent_explore\`, \`agent_librarian\`, \`agent_sage\`, \`agent_oracle\`, \`agent_prometheus\`, \`agent_metis\`) support multi-turn conversations:
98-
- **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.
10197
10298
| Task Type | Delegate To | Notes |
10399
|-----------|-------------|-------|
@@ -108,11 +104,11 @@ Agent tools (\`agent_explore\`, \`agent_librarian\`, \`agent_sage\`, \`agent_ora
108104
| Analyse agent routing | metis | Recommends which agent to use |
109105
110106
### 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.
112108
- **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.
114110
- **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.
116112
117113
# Following conventions
118114
When planning changes, first understand the existing code conventions:

src/agents/oracle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const oracleAgent: AgentDefinition = {
77
displayName: 'oracle',
88
description: 'Q&A agent — answers specific questions about the codebase with short, precise responses.',
99
mode: 'subagent',
10-
hidden: true,
10+
hidden: false,
1111
temperature: 0.0,
1212
toolSupported: true,
1313
tools: {

src/agents/prometheus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const prometheusAgent: AgentDefinition = {
77
displayName: 'prometheus',
88
description: 'Generator agent — creates code scaffolding, boilerplate, migrations, and templates.',
99
mode: 'subagent',
10-
hidden: true,
10+
hidden: false,
1111
temperature: 0.3,
1212
toolSupported: true,
1313
tools: {

src/agents/sage.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ Your role in research mode is to investigate the codebase systematically and pro
4343
1. **Scope Understanding**: Start with a clear understanding of the research question.
4444
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.
4545
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.
5152
5253
### Research Response Structure
5354

src/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,12 @@ function createAgentConfigs(agents: Record<AgentRole, AgentDefinition>): Record<
367367

368368
for (const agent of Object.values(agents)) {
369369
const tools: Record<string, boolean> = {}
370+
if (agent.tools?.include) {
371+
// Whitelist mode: explicitly enable only listed tools
372+
for (const tool of agent.tools.include) {
373+
tools[tool] = true
374+
}
375+
}
370376
if (agent.tools?.exclude) {
371377
for (const tool of agent.tools.exclude) {
372378
tools[tool] = false

0 commit comments

Comments
 (0)