Purpose: Master reference for defining files, agents, and tools in prompts that work seamlessly with OpenCode's automatic tool resolution.
| Type | Syntax | Auto-Loaded? | AI Action Required | When to Use |
|---|---|---|---|---|
| File (Initial) | @file.md |
โ Yes | โ No | User's initial prompt |
| File (Nested) | @file.md |
โ No | โ Yes (read_file) | Inside loaded files |
| Directory | @src/components/ |
โ Yes | โ No | Folder context |
| Sub-Agent (Context) | @agent-name |
โ Yes* | โ No | Reference agent info |
| Sub-Agent (Invoke) | task(subagent_type="name") |
โ No | โ Yes (task tool) | Delegate tasks |
| Shell Command | !`command` |
โ Yes | โ No | Inline command output |
| Config File | instructions: [] in opencode.json |
โ Yes | โ No | Always-needed context |
| Agent (Markdown) | .opencode/agent/**/*.md |
โ Auto-registered | โ No | Define agents |
task tool.opencode/agent/ directoryThe @ symbol only has special meaning in USER PROMPTS, not in AGENT SYSTEM PROMPTS.
Use the !`command` syntax to execute commands and inline their output into prompts:
# Example: Include git information
Current branch: !`git branch --show-current`
Recent commits: !`git log --oneline -5`
# Example: Include system information
Node version: !`node --version`
Available memory: !`free -h | grep Mem`
# Example: Include file contents
Database schema: !`cat schema.sql`
# Example: Include directory structure
Project structure:
!`tree -L 2 -I 'node_modules|dist'`
How it works:
## Current Work Context
Branch: !`git branch --show-current`
Modified files: !`git status --short`
Last commit: !`git log -1 --pretty=format:'%h - %s'`
Uncommitted changes:
!`git diff --stat`
## Project Layout
!`find src -type f -name '*.ts' | head -20`
## Component Structure
!`tree src/components -L 2`
## Environment
Node: !`node --version`
npm: !`npm --version`
OS: !`uname -a`
## Configuration
Current eslint rules:
!`cat .eslintrc.json`
Package scripts:
!`cat package.json | jq .scripts`
| Scenario | Use Shell ! Syntax |
Use run_terminal_cmd Tool |
|---|---|---|
| Static context in prompt | โ | โ |
| Git information | โ | โ |
| File contents | โ | โ |
| Interactive AI execution | โ | โ |
| Based on AI decisions | โ | โ |
| Build/test commands | โ | โ |
| Requires error handling | โ | โ |
When you type this in your prompt:
Follow guidelines in @GUIDELINES.md
Use patterns from @src/patterns/
OpenCode automatically:
GUIDELINES.mdsrc/patterns/ directoryWhen GUIDELINES.md contains:
Also see @CODE_STYLE.md and @TESTING.md
OpenCode does:
To make AI read them, use explicit instructions:
# GUIDELINES.md
โ ๏ธ **CRITICAL**: Before proceeding, read these files using read_file:
1. @CODE_STYLE.md - Coding standards (READ FIRST)
2. @TESTING.md - Testing patterns (READ FIRST)
3. @ARCHITECTURE.md - System design (READ FIRST)
[rest of your guidelines...]
Key phrases that work:
READ FIRSTuse read_file toolCRITICAL: Read these filesLoad immediately before proceedingIMPORTANT DISTINCTION: Agent Files vs Agent Names
Agent File (Documentation):
.opencode/agents/subagents/core/taskmanager.md@.opencode/agents/subagents/core/taskmanager.md to load file contentAgent Name (System Registration):
taskmanager (registered in OpenCode)task(subagent_type="taskmanager", ...) to invoke@agent-name (USUALLY NOT RECOMMENDED)When you use @agent-name in your initial prompt:
Use @reviewer agent for code review
What happens:
Result: AI knows the agent exists but doesn't execute it.
When to use: Rarely needed. Only if you want to reference agent capabilities in context.
To actually run an agent and execute tasks:
// AI must explicitly call the task tool
task(
subagent_type="CodeReviewer",
description="Review code",
prompt="Review the auth implementation for security issues"
)
Result: Agent executes and returns results.
When to use: Always - this is how you actually invoke agents.
If you have agent documentation files:
# Initial prompt
Follow guidelines in @.opencode/agents/subagents/core/taskmanager.md
What happens:
When to use: When you want to load documentation about how to use agents.
โ DON'T write this (confusing - uses @ for agents):
Use @reviewer to review code
Review with @taskmanager agent
Problems:
โ DO write this (clear and explicit):
Option 1: If you have agent documentation files
# Load agent documentation (file)
@.opencode/agents/subagents/core/taskmanager.md
# Then instruct AI how to invoke (not using @)
**Agent: `taskmanager`**
- Purpose: Task planning and breakdown
- Invoke with: task(subagent_type="taskmanager", description="Plan X", prompt="Break down feature Y")
Option 2: Direct invocation instructions (no @ at all)
**Agent: `reviewer`** - Code review agent
- Purpose: Review code for quality and security
- When: After implementing features
- Invoke with: task(subagent_type="CodeReviewer", description="Review X", prompt="Review Y for Z issues")
**DO NOT use @reviewer** - This loads metadata, not invocation
**ALWAYS use task tool** - This actually runs the agent
# Available Sub-Agents
โ ๏ธ **IMPORTANT**: These agents are NOT loaded as context. You MUST invoke them using the `task` tool:
## Code Agents
**Agent: `tester`** (DO NOT use @tester as context reference)
- **Purpose**: Test generation and execution
- **When to invoke**: After implementing features, before commits
- **Tool call**:
javascript task(
subagent_type="TestEngineer",
description="Test auth",
prompt="Write comprehensive tests for auth module with >80% coverage"
)
**Agent: `reviewer`** (DO NOT use @reviewer as context reference)
- **Purpose**: Code review and quality checks
- **When to invoke**: After completing code changes
- **Tool call**:
javascript task(
subagent_type="CodeReviewer",
description="Review changes",
prompt="Review the authentication implementation for security vulnerabilities, code quality, and best practices"
)
## Core Agents
**Agent: `planner`** (DO NOT use @planner as context reference)
- **Purpose**: Project planning and task breakdown
- **When to invoke**: Starting large features or projects
- **Tool call**:
javascript task(
subagent_type="planner",
description="Plan feature",
prompt="Break down the payment system feature into implementable tasks with dependencies"
)
To make the AI automatically invoke sub-agents at appropriate times:
## Agent Automation Rules
**CRITICAL**: Agents are invoked via `task` tool, NOT by referencing them with @.
**After completing code changes, ALWAYS:**
1. Invoke the `tester` agent using `task` tool to write and run tests
2. Invoke the `reviewer` agent using `task` tool to review code quality
3. Report results back to the user
**Example workflow:**
1. User requests feature
2. You implement the code
3. Automatically call:
javascript task(subagent_type="TestEngineer", description="Test feature", prompt="Write tests for X")
4. Automatically call:
javascript task(subagent_type="CodeReviewer", description="Review feature", prompt="Review X for quality")
5. Summarize results for user
**Important**:
- Sub-agents return results ONLY to you. You must summarize for the user.
- DO NOT use `@agent-name` syntax to invoke agents
- ALWAYS use the `task` tool for agent invocation
## Available Tools
**File Operations**
- `read_file` - Read file contents (supports line ranges)
- `write_file` - Create or overwrite files
- `search_replace` - Edit files with precision
- `list_dir` - List directory contents
- `glob_file_search` - Find files by pattern
**Code Operations**
- `grep` - Search code with ripgrep
- `codebase_search` - Semantic code search
**Execution**
- `run_terminal_cmd` - Execute shell commands
- `task` - Invoke sub-agents
**Planning**
- `todo_write` - Create and manage task lists
# Task Instructions
When you need to find configuration files, use `glob_file_search` to locate them.
When analyzing code patterns, use `codebase_search` for semantic understanding.
When editing code, use `search_replace` for precision rather than rewriting entire files.
Here's a production-ready index file that works perfectly with OpenCode:
# Project Context Index
## ๐ Quick Start
**CRITICAL INSTRUCTION**: Before proceeding with ANY task:
1. Read the files marked `[READ FIRST]` using the `read_file` tool
2. Review the available sub-agents below
3. Follow the coding standards and patterns defined in these files
---
## ๐ Core Documentation [READ FIRST]
Load these files immediately using `read_file`:
- @docs/CODING_STANDARDS.md - TypeScript/React coding patterns
- @docs/TESTING_STRATEGY.md - Test requirements and patterns
- @docs/ARCHITECTURE.md - System design and component structure
- @.opencode/WORKFLOWS.md - Development workflows and CI/CD
---
## ๐ค Available Sub-Agents
Use the `task` tool to invoke these specialized agents:
### Development Agents
**@subagents/code/implementer** - Complex feature implementation
javascript task( subagent_type="implementer", description="Implement user auth", prompt="Create complete authentication system with JWT tokens, including login, logout, and session management. Follow patterns in @docs/ARCHITECTURE.md" )
**@TestEngineer** - Test generation and execution
javascript task( subagent_type="TestEngineer", description="Test auth system", prompt="Write comprehensive unit and integration tests for the authentication module. Ensure >80% coverage. Run tests and report results." )
**@CodeReviewer** - Code quality and security review
javascript task( subagent_type="CodeReviewer", description="Review auth code", prompt="Review the authentication implementation for security vulnerabilities, code quality, and adherence to @docs/CODING_STANDARDS.md. Provide specific improvement suggestions." )
### Documentation Agents
**@subagents/docs/technical-writer** - API and code documentation
javascript task( subagent_type="technical-writer", description="Document auth API", prompt="Generate comprehensive API documentation for the authentication endpoints, including request/response examples and error codes." )
### Planning Agents
**@subagents/core/architect** - System design and planning
javascript task( subagent_type="architect", description="Design payment system", prompt="Design a payment processing system architecture that integrates with Stripe. Break down into implementable tasks. Consider scalability and error handling." )
---
## ๐ Automated Workflows
### After Implementing Code
**ALWAYS execute this workflow:**
1. **Test** - Invoke `@TestEngineer` to validate implementation
2. **Review** - Invoke `@CodeReviewer` for quality check
3. **Document** - Update relevant documentation
4. **Report** - Summarize results to user with:
- What was implemented
- Test results and coverage
- Any issues found in review
- Next recommended steps
### Before Starting Large Features
**ALWAYS execute this workflow:**
1. **Plan** - Invoke `@subagents/core/architect` for design
2. **Load Context** - Read relevant documentation from @docs/
3. **Break Down** - Create detailed TODO list with `todo_write`
4. **Confirm** - Ask user to confirm approach
---
## ๐ Additional Context Files
### Code Patterns & Examples
For specific implementation patterns, read these on-demand:
- @examples/api-patterns.ts - REST API implementation patterns
- @examples/component-patterns.tsx - React component patterns
- @examples/test-patterns.test.ts - Testing patterns and fixtures
- @examples/error-handling.ts - Error handling strategies
### Configuration Files
Reference these when setting up tools or CI/CD:
- @.github/workflows/ - GitHub Actions workflows
- @tsconfig.json - TypeScript configuration
- @package.json - Project dependencies and scripts
---
## ๐ฏ Tool Usage Guidelines
### File Search Strategy
1. **Known filename**: Use `read_file` directly
2. **Pattern match**: Use `glob_file_search` (e.g., "*.test.ts")
3. **Semantic search**: Use `codebase_search` (e.g., "authentication logic")
4. **Text search**: Use `grep` for exact text matches
### Editing Strategy
1. **Small changes**: Use `search_replace` for precision
2. **New files**: Use `write_file`
3. **Large refactors**: Consider sub-agent with `task` tool
### Execution Strategy
1. **Simple commands**: Use `run_terminal_cmd`
2. **Complex workflows**: Create shell scripts first
3. **Multistep tasks**: Use sub-agents with `task` tool
---
## โ ๏ธ Common Pitfalls to Avoid
### โ DON'T DO THIS:
markdown
Use @tester when needed Review with @reviewer after coding
Read @tester for testing guidelines See @reviewer documentation
Use the tester agent when needed
See @guidelines.md (which references @other.md)
Available agents: tester, reviewer, planner
Use @agent-name to run the agent
### โ
DO THIS:
markdown
Agent: tester - Invoke ONLY via task tool:
task(subagent_type="TestEngineer", description="Test feature", prompt="Write comprehensive tests for X")
File: @docs/testing-guide.md - Load with read_file
Agent: tester - Invoke with task tool
CRITICAL: Read @guidelines.md, then read all files it references using read_file
Use the codebase_search tool to find authentication logic
After implementing code, ALWAYS invoke the tester agent: task(subagent_type="TestEngineer", description="Test X", prompt="Write and run tests for X")
---
## ๐ Quick Start Template
Copy this template to create your own index:
markdown
CRITICAL: Load these files first using read_file:
task tool to invoke)Agent: [AGENT_NAME] (DO NOT use @[AGENT_NAME] as context)
Tool call:
task(
subagent_type="[AGENT_NAME]",
description="[SHORT_DESC]",
prompt="[DETAILED_TASK_INSTRUCTIONS]"
)
task tooltask toolExample:
// Step 1: Test
task(subagent_type="[TESTER_AGENT]", description="Test feature", prompt="Write tests for X")
// Step 2: Review
task(subagent_type="[REVIEWER_AGENT]", description="Review feature", prompt="Review X for quality")
// Step 3: Summarize results for user
---
## ๐ Verification Checklist
Before sharing your index file, verify:
- [ ] All **file** references use `@` prefix
- [ ] Agent references use `task` tool, NOT `@` syntax
- [ ] Agent names are plain text (e.g., `tester`), not `@tester`
- [ ] Nested file references have explicit "READ FIRST" instructions
- [ ] Sub-agents have complete `task()` tool call examples
- [ ] Sub-agents show when/why to invoke them
- [ ] Clear distinction between files (@file.md) and agents (task tool)
- [ ] Automated workflows use `task` tool for agents
- [ ] Tool usage instructions are specific
- [ ] No ambiguous or vague instructions
- [ ] No mixing of @ syntax for agents
---
## ๐ Quick Reference Notes
- **Files**: Use `@path/to/file.md` in prompts (auto-loaded initially, nested require read_file)
- **Agent Files**: Use `@.opencode/agents/subagents/core/agent.md` to load documentation
- **Agent Invocation**: Use `task` tool, NOT `@agent-name` syntax
- **Agent Names**: Plain text only (e.g., `taskmanager`), never `@taskmanager`
- **Shell**: Use `` !`command` `` for automatic execution in prompts
- **Key Rule**: `@` is for FILES only, `task` tool is for AGENTS
- **Rare Exception**: `@agent-name` loads agent metadata (usually not needed)
---
## ๐จ Advanced Patterns
### Combining Multiple Context Types
markdown
@docs/auth-spec.md @src/auth/types.ts
!find src/auth -type f -name '*.ts'
Branch: !git branch --show-current
Changes: !git diff --name-only
Node: !node --version
Dependencies: !npm list --depth=0 | grep auth
@subagents/code/implementer - Use for implementation @TestEngineer - Use for testing
Implement the authentication flow following @docs/auth-spec.md
### Dynamic File Loading
markdown
Test files in project:
!find . -name "*.test.ts" -o -name "*.spec.ts"
INSTRUCTION: Read all test files above using read_file to understand testing patterns.
### Conditional Context
markdown
!npm run db:status 2>&1
!ls -t migrations/ | head -1 | xargs cat
If migrations are pending: Read @docs/migration-guide.md If migrations are up-to-date: Proceed with schema changes
### Nested Shell Commands with File References
markdown
!find src -name "*.tsx" | grep -v test
@docs/component-patterns.md
CRITICAL:
read_fileEnsure new components follow established patterns
---
## ๐ Shell Command Cheat Sheet
### Git Commands
bash
!git branch --show-current
!git log --oneline -n 10
!git status --short
!git diff --stat
!git shortlog -sn --all
!git rev-parse HEAD
### File System Commands
bash
!find src -name "*.ts" -type f
!find src -name "*.ts" | xargs wc -l | tail -1
!ls -lt src | head -10
!tree -L 3 -I 'node_modules|dist|.git'
!du -sh src/*
### Project Info Commands
bash
!cat package.json | jq -r .version
!npm list --depth=0
!cat package.json | jq .scripts
!node --version
!npm --version
### Search Commands
bash
!grep -r "TODO" src --include="*.ts"
!grep -r "FIXME" src --include="*.ts"
!grep -rn "function authenticate" src
!find . -name "*.test.ts" | wc -l
### System Commands
bash
!uname -a
!free -h
!df -h .
!ps aux | grep node
---
## ๐ฏ Complete Real-World Example
markdown
Branch: !git branch --show-current
Modified Files:
!git status --short
Existing Auth Files:
!find src/auth -name "*.ts" -type f
Test Coverage:
!npm run test:coverage -- src/auth 2>&1 | tail -5
Current Auth Libraries:
!npm list | grep -E "(passport|jwt|bcrypt)"
Node Version: !node --version
@subagents/code/implementer - Feature implementation
task(subagent_type="implementer", description="OAuth flow", prompt="Implement OAuth2 flow with Google, following patterns in @docs/AUTH_ARCHITECTURE.md")@TestEngineer - Test creation
task(subagent_type="TestEngineer", description="Test OAuth", prompt="Write integration tests for OAuth2 flow with >90% coverage")@subagents/security/auditor - Security review
task(subagent_type="auditor", description="Audit auth", prompt="Review auth implementation for security vulnerabilities, SQL injection, XSS, and CSRF")cat src/auth/auth.service.tscat tests/auth/auth.test.tsInvoke tester agent via task tool for test creation
task(subagent_type="TestEngineer", description="Test auth", prompt="Write tests for auth module")
Run tests: Use run_terminal_cmd for npm test
Verify coverage meets requirements
Invoke security auditor agent via task tool
task(subagent_type="auditor", description="Security audit", prompt="Review auth for vulnerabilities")
Address any issues found
Re-run tests after fixes
Database Schema:
!cat migrations/latest_auth_schema.sql
Environment Variables:
!cat .env.example | grep AUTH
REMEMBER:
@filename (nested require read_file)task tool, NOT @agent-name!`cmd` executes automatically in promptAgent names are plain text (e.g., tester), never @tester
---
## ๐ Notes
- **Auto-loaded**: Initial `@` references in YOUR prompt (files only)
- **Requires tool call**: Nested `@` references in loaded files
- **Agent as context**: `@agent-name` in initial prompt attaches agent info (not invocation)
- **Agent invocation**: Always requires `task` tool call - NEVER use `@` syntax
- **Shell commands**: `` !`command` `` syntax executes automatically in prompt processing
- **Tool commands**: `run_terminal_cmd` for AI-driven execution during conversation
- **Key distinction**: Files use `@`, Agents use `task` tool
---
## ๐ฏ Quick Decision Tree
**Need to load a file?**
- Initial prompt โ Use `@path/to/file.md`
- Nested reference โ Add "READ FIRST" instruction for AI to use `read_file`
- Agent docs โ Use `@.opencode/agents/subagents/core/agent.md` (file path)
**Need to invoke an agent?**
- โ **NEVER** use `@agent-name` syntax for invocation
- โ
AI must call `task(subagent_type="name", ...)`
- โ
Use plain agent names (e.g., `taskmanager`, not `@taskmanager`)
- โ
Add clear invocation instructions in your context
- โ ๏ธ Using `@agent-name` only loads metadata (rarely useful)
**Need to run a command?**
- Static context โ Use `` !`command` `` in prompt
- AI-driven execution โ AI uses `run_terminal_cmd` tool
**Structure Example:**
Files (use @): Agents (use task): @docs/guide.md task(subagent_type="CodeReviewer", ...) @src/types.ts task(subagent_type="TestEngineer", ...) @.opencode/agents/ [agent name without @] taskmanager.md
---
---
## ๐ฏ THE PERFECT PROMPT TEMPLATE
Use this template to avoid ALL confusion and work seamlessly with OpenCode:
### Template Structure
markdown
CRITICAL: Read these files FIRST using the read_file tool:
Current git status:
Branch: !git branch --show-current
Recent changes: !git status --short
Project structure:
!find src -type d -maxdepth 2
IMPORTANT: DO NOT use @ syntax for agents. Use the task tool to invoke.
implementerPurpose: Complex feature implementation When to invoke: When implementing new features or major refactors How to invoke:
task(
subagent_type="implementer",
description="Implement feature X",
prompt="Create complete implementation of X following @docs/architecture.md patterns. Include error handling and validation."
)
testerPurpose: Test creation and execution When to invoke: After implementing features, before committing How to invoke:
task(
subagent_type="TestEngineer",
description="Test feature X",
prompt="Write comprehensive tests for X with >80% coverage. Run tests and report results."
)
reviewerPurpose: Code review and quality checks When to invoke: After code changes, before finalizing How to invoke:
task(
subagent_type="CodeReviewer",
description="Review feature X",
prompt="Review the implementation of X for code quality, security vulnerabilities, and adherence to @docs/coding-standards.md"
)
After implementing ANY code:
tester agent using task toolreviewer agent using task tool[Describe the specific task here]
@path/to/file.md syntaxtask(subagent_type="name", ...)@agent-name to invoke agentsAgent names are plain text: tester, reviewer, NOT @tester
---
### Real-World Example: Perfect Prompt
markdown
CRITICAL: Use read_file tool to load these before starting:
Git Context:
Branch: !git branch --show-current
Modified: !git status --short
Existing Auth Files:
!find src/auth -name "*.ts" -type f
Dependencies:
!npm list | grep -E "(jwt|bcrypt|passport)"
implementerPurpose: Feature implementation Invoke with:
task(
subagent_type="implementer",
description="Implement auth flow",
prompt="Create authentication system with JWT tokens, including login, logout, and session management. Follow patterns in @docs/AUTH_ARCHITECTURE.md. Include middleware, controllers, and services."
)
testerPurpose: Test creation Invoke with:
task(
subagent_type="TestEngineer",
description="Test auth system",
prompt="Write unit and integration tests for authentication module. Cover login, logout, token refresh, and session management. Ensure >85% coverage. Run tests and report results."
)
reviewerPurpose: Security and quality review Invoke with:
task(
subagent_type="CodeReviewer",
description="Review auth implementation",
prompt="Review authentication implementation for security vulnerabilities (SQL injection, XSS, CSRF), proper token handling, password security, and adherence to @docs/CODING_STANDARDS.md"
)
You MUST follow this workflow:
tester agent via task toolreviewer agent via task toolImplement a complete authentication system with:
Requirements:
@docs/file.mdtask(subagent_type="name", ...)@agent-name to invoke agentstester, NOT @testerShell commands auto-execute: !git status
---
## ๐ Anti-Pattern Examples (What NOT To Do)
### โ BAD PROMPT (Confusing)
markdown
Use @tester and @reviewer agents to test the code. Follow @guidelines and implement authentication.
**Problems:**
- Uses `@` for agents (only loads metadata, doesn't invoke)
- No clear invocation instructions
- Mixing file and agent syntax
- No explicit workflow
### โ
GOOD PROMPT (Clear)
markdown
Read these using read_file tool:
Agent: tester - Invoke with task tool:
task(subagent_type="TestEngineer", description="Test auth", prompt="...")
Agent: reviewer - Invoke with task tool:
task(subagent_type="CodeReviewer", description="Review auth", prompt="...")
Invoke reviewer agent via task tool
---
## ๐จ Prompt Templates by Use Case
### Template 1: Simple Feature Implementation
markdown
Read: @docs/standards.md
Git status: !git status --short
[Detailed description]
(Simple task, no agents required)
### Template 2: Complex Feature with Agents
markdown
!git status --short
!find src/[module] -name "*.ts"
Agent: implementer
Invoke: task(subagent_type="implementer", description="...", prompt="...")
Agent: tester
Invoke: task(subagent_type="TestEngineer", description="...", prompt="...")
Report results
### Template 3: Code Review Task
markdown
Files to review:
!git diff --name-only main...HEAD
Recent changes:
!git log --oneline -5
Agent: reviewer
Invoke immediately:
task(
subagent_type="CodeReviewer",
description="Review recent changes",
prompt="Review all changes in current branch for code quality, security, and adherence to standards"
)
Run code review and report findings.
### Template 4: Documentation Task
markdown
Implementation files:
!find src/[module] -name "*.ts"
Agent: documenter
Invoke: task(subagent_type="documenter", description="Document X", prompt="...")
Generate comprehensive documentation for [feature].
---
## ๐ Golden Rules for Perfect Prompts
1. **Files**: Always use `@path/to/file.md`
2. **Agents**: Always use `task(subagent_type="name", ...)`
3. **Shell**: Always use `` !`command` `` for dynamic context
4. **Clarity**: Separate files, agents, and tasks into clear sections
5. **Workflow**: Always specify the execution order
6. **Agent Names**: Plain text only - `tester`, never `@tester`
7. **Context First**: Load all context before describing the task
8. **Explicit Instructions**: Tell AI exactly when and how to invoke agents
---
## ๐ฏ REAL-WORLD EXAMPLE: Your Agent Setup
Based on your actual agent configurations (task-manager subagent + orchestration agent):
### Your Agent Files Structure & Naming
**CRITICAL**: Agents are defined in MARKDOWN files. The agent NAME comes from the FILE PATH!
.opencode/ agent/ # All agents as markdown files
subagents/
core/
task-manager.md # Agent name: "TaskManager"
orchestration-agent.md # Agent name: "orchestration-agent"
code/
reviewer.md # Agent name: "code/reviewer"
tester.md # Agent name: "code/tester"
**Markdown Agent File Format:**
description: "Brief description of agent" mode: subagent # or "primary" or "all" temperature: 0.2 tools: read: true write: true edit: true bash: true task: true permissions: edit:
"**/*.secret": "deny"
bash:
"rm -rf *": "deny"
Your agent instructions, personality, rules, etc. All the markdown content becomes the agent's system prompt.
**How OpenCode determines agent names (from source code):**
1. Scans `.opencode/agent/**/*.md` files recursively
2. Parses YAML frontmatter (between `---` markers) for config
3. Uses markdown content as the agent's system prompt
4. Agent name = file path from `agent/` directory (minus `.md`)
**Examples:**
- File: `.opencode/agent/task-manager.md` โ Name: `task-manager`
- File: `.opencode/agent/TaskManager.md` โ Name: `TaskManager`
- File: `.opencode/agent/code/reviewer.md` โ Name: `code/reviewer`
**No opencode.json needed!** Everything is in markdown.
### โ WRONG: Confusing Prompt
markdown Use @task-manager to break down the feature Have @orchestration-agent coordinate the work
**Problems:**
- Using `@` for agent invocation (only loads metadata)
- AI won't actually invoke the agents
- Wrong agent name - should include full path: `TaskManager`
- Confusing agent files with agent invocation
### โ
CORRECT: Clear Prompt
markdown
Agent Documentation (optional - only if you need to understand agent capabilities):
Project Documentation:
Current State:
Branch: !git branch --show-current
Files: !find src/dashboard -name "*.ts"
TaskManager (Subagent)IMPORTANT: Agent is defined in a MARKDOWN file. The agent name comes from the file path!
File location: .opencode/agent/TaskManager.md
Agent name: TaskManager (path from agent/ directory)
Format: Markdown with YAML frontmatter
File structure:
---
description: "Breaks down complex features into subtasks"
mode: subagent
temperature: 0.1
tools: { read: true, write: true, ... }
---
# Task Manager Agent Prompt
[Your agent instructions here...]
Purpose: Break down complex features into atomic subtasks
When to invoke:
How to invoke:
task(
subagent_type="TaskManager",
description="Break down dashboard feature",
prompt="Break down the user dashboard feature into atomic subtasks. Feature includes: profile widget, activity feed, notification center, and settings panel. Create structured task files in /tasks/ directory following your two-phase workflow."
)
What it does:
tasks/subtasks/{feature}/For complex features (4+ components):
Invoke task-manager to break down the feature
task(
subagent_type="TaskManager",
description="Break down dashboard",
prompt="Analyze and break down user dashboard feature with profile, activity, notifications, and settings components. Create task files with dependencies and acceptance criteria."
)
Review the task plan (agent will request approval)
Approve and let agent create files
Implement tasks sequentially based on dependencies
Validate each task against acceptance criteria
Implement a user dashboard feature with:
Requirements:
Since this is complex (4+ components), invoke the task-manager agent first.
.md in .opencode/agents/): Use @ to load as documentationtask(subagent_type="name", ...) to actually run the agenttask-manager, NOT @task-managerInvoke task-manager when you need feature breakdown
---
## ๐จ Prompt Templates for Your Specific Agents
### Template 1: Complex Feature (Needs Task Breakdown)
markdown
Read these files:
Current state:
!git status --short
!find src/[module] -type f
Invoke immediately for task breakdown:
task(
subagent_type="TaskManager",
description="Break down [feature]",
prompt="Break down [feature description] into atomic subtasks. Include:
- Component 1: [details]
- Component 2: [details]
- Component 3: [details]
Create task files in /tasks/ with dependencies, acceptance criteria, and test requirements. Follow your two-phase workflow (plan โ approve โ create files)."
)
[Detailed feature requirements]
Report completion
### Template 2: Simple Task (Direct Execution)
markdown
Read:
Current state:
!git status --short
[Task description - simple, 1-3 files]
Follow coding standards from @docs/coding-standards.md
### Template 3: Coordination Task (Uses Orchestration Features)
markdown
Read orchestration guidelines:
Current state:
!git status --short
This task requires coordination across multiple steps:
Agent: TaskManager - For feature breakdown
Invoke: task(subagent_type="TaskManager", description="...", prompt="...")
Agent: general - For delegated complex work (if needed)
Invoke: task(subagent_type="general", description="...", prompt="...")
[Complex coordinated task description]
From @.opencode/agents/orchestration-agent.md:
Confirm before cleanup
---
## ๐ฏ Key Insights for Your Setup
### Your Orchestration Agent (Primary)
- **Already active** - it's processing your prompts
- **Has task delegation** capability
- **Follows approval workflow**
- **Can invoke task-manager** when needed
### Your Task-Manager Subagent
- **Invoked via task tool** when you need breakdown
- **Two-phase workflow**: Plan โ Approve โ Create
- **Creates files** in `tasks/subtasks/{feature}/`
- **Returns structured** task plans
### Critical Distinctions
| What | File Syntax | Agent Invocation |
|------|-------------|------------------|
| Load agent docs | `@.opencode/agent/TaskManager.md` | N/A |
| Invoke task-manager | N/A | `task(subagent_type="TaskManager", ...)` |
| Reference in text | "the task-manager agent" or "TaskManager" | N/A |
| Load project docs | `@docs/standards.md` | N/A |
**KEY INSIGHT**: The agent name comes from the file path structure, NOT just the filename!
### Decision Flow
Is it complex (4+ components)? โ YES Invoke task-manager โ Get breakdown โ Implement tasks
โ NO Execute directly (orchestration agent handles it)
Need to understand agents? โ YES Load agent docs: @.opencode/agents/[agent].md
โ NO Skip - just invoke when needed
---
---
## ๐ค Design Philosophy: Why List Subagents?
**You might ask**: "Why do I need to tell the AI about subagents in my prompt when the `task` tool already lists them?"
**You're right - it's redundant!** Here's the reality:
### The Ideal World (How It Should Work)
tools:
Delegate complex work to specialized subagents.
The AI should:
1. โ
See the `task` tool
2. โ
Read the tool's description (which lists agents)
3. โ
Use it when appropriate
### The Real World (Current AI Limitations)
Current AI models don't always:
- โ Read tool descriptions carefully
- โ Remember to check available tools
- โ Connect "complex task" โ "delegate" โ "use task tool"
So we **compensate** by:
- Explicitly mentioning agents in prompts
- Providing invocation examples
- Repeating instructions
### Two Approaches
**Option 1: Minimal (Trust the Tool)**
markdown
For complex work, use the task tool to delegate to specialized subagents.
Available agents are documented in the task tool description.
- โ
Clean, minimal
- โ ๏ธ AI might not delegate when it should
**Option 2: Explicit (Be Redundant)**
markdown Available subagents via task tool:
Invoke with: task(subagent_type="...", description="...", prompt="...") ```
Recommendation:
Last Updated: 2024-11-21 OpenCode Version: Latest