docs: agents
This commit is contained in:
@@ -5,111 +5,6 @@ description: Configure and use specialized agents in opencode.
|
|||||||
|
|
||||||
Agents are specialized AI assistants that can be configured for specific tasks and workflows. They allow you to create focused tools with custom prompts, models, and tool access.
|
Agents are specialized AI assistants that can be configured for specific tasks and workflows. They allow you to create focused tools with custom prompts, models, and tool access.
|
||||||
|
|
||||||
## Built-in Agents
|
|
||||||
|
|
||||||
opencode comes with a built-in `general` agent:
|
|
||||||
|
|
||||||
- **general** - General-purpose agent for researching complex questions, searching for code, and executing multi-step tasks. Use this when searching for keywords or files and you're not confident you'll find the right match in the first few tries.
|
|
||||||
|
|
||||||
## Configuration
|
|
||||||
|
|
||||||
Agents can be configured in your `opencode.json` config file or as markdown files.
|
|
||||||
|
|
||||||
### JSON Configuration
|
|
||||||
|
|
||||||
```json title="opencode.json"
|
|
||||||
{
|
|
||||||
"$schema": "https://opencode.ai/config.json",
|
|
||||||
"agent": {
|
|
||||||
"code-reviewer": {
|
|
||||||
"description": "Reviews code for best practices and potential issues",
|
|
||||||
"model": "anthropic/claude-sonnet-4-20250514",
|
|
||||||
"prompt": "You are a code reviewer. Focus on security, performance, and maintainability.",
|
|
||||||
"tools": {
|
|
||||||
"write": false,
|
|
||||||
"edit": false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"test-writer": {
|
|
||||||
"description": "Specialized agent for writing comprehensive tests",
|
|
||||||
"prompt": "You are a test writing specialist. Write thorough, maintainable tests.",
|
|
||||||
"tools": {
|
|
||||||
"bash": true,
|
|
||||||
"read": true,
|
|
||||||
"write": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Markdown Configuration
|
|
||||||
|
|
||||||
You can also define agents using markdown files. Place them in:
|
|
||||||
|
|
||||||
- Global: `~/.config/opencode/agent/`
|
|
||||||
- Project: `.opencode/agent/`
|
|
||||||
|
|
||||||
```markdown title="~/.config/opencode/agent/code-reviewer.md"
|
|
||||||
---
|
|
||||||
description: Reviews code for best practices and potential issues
|
|
||||||
model: anthropic/claude-sonnet-4-20250514
|
|
||||||
tools:
|
|
||||||
write: false
|
|
||||||
edit: false
|
|
||||||
---
|
|
||||||
|
|
||||||
You are a code reviewer with expertise in security, performance, and maintainability.
|
|
||||||
|
|
||||||
Focus on:
|
|
||||||
|
|
||||||
- Security vulnerabilities
|
|
||||||
- Performance bottlenecks
|
|
||||||
- Code maintainability
|
|
||||||
- Best practices adherence
|
|
||||||
```
|
|
||||||
|
|
||||||
## Agent Properties
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- **description** - Brief description of what the agent does and when to use it
|
|
||||||
|
|
||||||
### Optional
|
|
||||||
|
|
||||||
- **model** - Specific model to use (defaults to your configured model)
|
|
||||||
- **prompt** - Custom system prompt for the agent
|
|
||||||
- **tools** - Object specifying which tools the agent can access (true/false for each tool)
|
|
||||||
- **disable** - Set to true to disable the agent
|
|
||||||
|
|
||||||
## Tool Access
|
|
||||||
|
|
||||||
By default, agents inherit the same tool access as the main assistant. You can restrict or enable specific tools:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"agent": {
|
|
||||||
"readonly-agent": {
|
|
||||||
"description": "Read-only agent for analysis",
|
|
||||||
"tools": {
|
|
||||||
"write": false,
|
|
||||||
"edit": false,
|
|
||||||
"bash": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Common tools you might want to control:
|
|
||||||
|
|
||||||
- `write` - Create new files
|
|
||||||
- `edit` - Modify existing files
|
|
||||||
- `bash` - Execute shell commands
|
|
||||||
- `read` - Read files
|
|
||||||
- `glob` - Search for files
|
|
||||||
- `grep` - Search file contents
|
|
||||||
|
|
||||||
## Using Agents
|
## Using Agents
|
||||||
|
|
||||||
Agents are automatically available through the Task tool when configured. The main assistant will use them for specialized tasks based on their descriptions.
|
Agents are automatically available through the Task tool when configured. The main assistant will use them for specialized tasks based on their descriptions.
|
||||||
|
|||||||
Reference in New Issue
Block a user