Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .opencode/agent/code-reviewer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
description: Reviews code changes for quality and best practices
mode: subagent
model: ollama/qwen2.5:1.5b
temperature: 0.2
context:
mode: filtered
includeToolResults: ["read", "edit", "write"]
includeFileChanges: true
maxMessages: 10
maxTokens: 8000
tools:
write: false
edit: false
bash: false
---

Review the provided code for:

1. **Code Quality**
- Readability and maintainability
- Proper naming conventions
- Code organization and structure

2. **Best Practices**
- Design patterns and architecture
- Error handling
- Performance considerations

3. **Potential Issues**
- Bug risks
- Security concerns
- Edge cases

Provide specific, actionable feedback with line references when possible.
25 changes: 25 additions & 0 deletions .opencode/agent/doc-reader.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
description: Reads documentation and summarizes key insights
mode: subagent
model: ollama/llama3.2:1b
temperature: 0.1
context:
mode: filtered
includeMessageTypes: ["user"]
includeToolResults: ["read"]
maxTokens: 2000
tools:
write: false
edit: false
bash: false
---

Extract key points, APIs, and caveats from documentation.
Provide a short summary and a Q&A with likely follow-ups.

Focus on:

- Main concepts and their purpose
- API endpoints and their parameters
- Common pitfalls and best practices
- Integration examples
34 changes: 34 additions & 0 deletions .opencode/agent/log-analyzer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
description: Analyzes log files for errors and patterns
mode: subagent
model: ollama/llama3.2:1b
temperature: 0.0
context:
mode: summary
includeFileChanges: false
maxTokens: 1000
tools:
write: false
edit: false
bash: false
webfetch: false
---

Analyze the provided log file and identify:

1. **Errors and Warnings**
- Critical errors with timestamps
- Warning patterns
- Frequency of issues

2. **Performance Metrics**
- Response times
- Resource usage patterns
- Bottlenecks

3. **Anomalies**
- Unusual patterns
- Spike in errors
- Unexpected behavior

Provide a concise summary with actionable insights.
23 changes: 23 additions & 0 deletions .opencode/agent/quick-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
description: Fast search for specific code patterns or functions
mode: subagent
model: ollama/qwen2.5:1.5b
temperature: 0.0
context:
mode: none
tools:
write: false
edit: false
bash: false
webfetch: false
---

Search the codebase for the requested pattern, function, or code snippet.

Return:

- File paths and line numbers
- Brief context around each match
- Total number of matches found

Keep responses concise and focused on the search results.
16 changes: 16 additions & 0 deletions .opencode/agent/test-context-filtered.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
description: Test context control with filtered mode
mode: subagent
model: anthropic/claude-sonnet-4
context:
mode: filtered
includeToolResults: ["read"]
maxTokens: 2000
tools:
write: false
edit: false
bash: false
---

Summarize what you see very concisely.
List only the key points.
13 changes: 13 additions & 0 deletions .opencode/agent/test-context-none.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
description: Test with no context (baseline)
mode: subagent
model: anthropic/claude-sonnet-4
context:
mode: none
tools:
write: false
edit: false
bash: false
---

Answer the question concisely.
15 changes: 15 additions & 0 deletions .opencode/agent/test-context-summary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
description: Test context control with summary mode
mode: subagent
model: anthropic/claude-sonnet-4
context:
mode: summary
includeFileChanges: true
maxTokens: 1000
tools:
write: false
edit: false
bash: false
---

Based on the session summary, answer the question.
19 changes: 19 additions & 0 deletions .opencode/agent/test-debug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
description: Debug agent to test context control
mode: subagent
model: anthropic/claude-sonnet-4
context:
mode: filtered
includeToolResults: ["read", "list", "glob"]
includeMessageTypes: ["user"]
maxMessages: 5
maxTokens: 3000
tools:
write: false
edit: false
bash: false
---

You are a debug agent testing context control.
Just respond with "I received context" if you got any context, or "No context" if not.
Then list what you can see.
38 changes: 38 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,44 @@

- To test opencode in the `packages/opencode` directory you can run `bun dev`

## Context Control for Subagents

Subagents can be configured with context filters to control what parent session context they receive. This enables better performance for lightweight local models.

### Configuration

Add a `context` field to your agent configuration:

```yaml
context:
mode: filtered
maxTokens: 2000
includeToolResults: ["read", "edit"]
includeMessageTypes: ["user"]
```

### Modes

- `none` (default) - No parent context
- `summary` - Compact summary with message counts and tool usage
- `filtered` - Selective inclusion by message type and tool results
- `full` - All context with token/message limits

### Example

```yaml
---
mode: subagent
model: ollama/llama3.2:1b
context:
mode: filtered
includeToolResults: ["read"]
maxTokens: 2000
---
```

See `.opencode/agent/` for example configurations.

## Tool Calling

- ALWAYS USE PARALLEL TOOLS WHEN APPLICABLE. Here is an example illustrating how to execute 3 parallel file reads in this chat environment:
Expand Down
17 changes: 16 additions & 1 deletion packages/opencode/src/agent/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export namespace Agent {
prompt: z.string().optional(),
tools: z.record(z.string(), z.boolean()),
options: z.record(z.string(), z.any()),
context: Config.ContextFilter.optional(),
})
.meta({
ref: "Agent",
Expand Down Expand Up @@ -148,7 +149,20 @@ export namespace Agent {
tools: {},
builtIn: false,
}
const { name, model, prompt, tools, description, temperature, top_p, mode, permission, color, ...extra } = value
const {
name,
model,
prompt,
tools,
description,
temperature,
top_p,
mode,
permission,
color,
context,
...extra
} = value
item.options = {
...item.options,
...extra,
Expand All @@ -169,6 +183,7 @@ export namespace Agent {
if (top_p != undefined) item.topP = top_p
if (mode) item.mode = mode
if (color) item.color = color
if (context) item.context = context
// just here for consistency & to prevent it from being added as an option
if (name) item.name = name

Expand Down
38 changes: 38 additions & 0 deletions packages/opencode/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,43 @@ export namespace Config {
})
export type Command = z.infer<typeof Command>

export const ContextFilter = z
.object({
mode: z
.enum(["none", "summary", "filtered", "full"])
.optional()
.default("none")
.describe(
"Context mode: 'none' (no parent context), 'summary' (compact summary), 'filtered' (selective context), 'full' (all parent context)",
),
maxTokens: z
.number()
.int()
.positive()
.optional()
.describe("Maximum tokens to include from parent session context"),
maxMessages: z
.number()
.int()
.positive()
.optional()
.describe("Maximum number of messages to include from parent session"),
includeToolResults: z
.array(z.string())
.optional()
.describe("Which tool results to include (e.g., ['read', 'edit', 'bash'])"),
includeMessageTypes: z
.array(z.enum(["user", "assistant"]))
.optional()
.describe("Which message types to include from parent session"),
includeFileChanges: z.boolean().optional().describe("Include file changes made in parent session"),
})
.optional()
.meta({
ref: "ContextFilterConfig",
})
export type ContextFilter = z.infer<typeof ContextFilter>

export const Agent = z
.object({
model: z.string().optional(),
Expand All @@ -364,6 +401,7 @@ export namespace Config {
.regex(/^#[0-9a-fA-F]{6}$/, "Invalid hex color format")
.optional()
.describe("Hex color code for the agent (e.g., #FF5733)"),
context: ContextFilter.describe("Control what context from the parent session is passed to this subagent"),
permission: z
.object({
edit: Permission.optional(),
Expand Down
Loading