Build Intelligent Workflow Systems with Context-Aware AI
For New Users:
opencode --agent codebase-agent for all development work.opencode/context/project/project-context.mdFor Advanced Users:
@ symbol)Core Concept:
Commands load context → Agents execute with that context → Subagents handle specialized tasks
When to read this document:
codebase-agent instead)This blueprint is a teaching document that explains agent system architecture patterns. It uses examples to teach concepts like context loading, agent orchestration, and workflow management.
📖 Installation & Usage: See README.md in the repository root.
This document teaches:
@ symbol magic)When you see commands like /workflow, /plan-task, /create-frontend-component:
codebase-agent already handles these workflowsWhen you see extensive context hierarchies:
core/ and project/ context filesfrontend/, backend/, database/) as neededWhen you see task management structures:
task-manager agent creates tasks/ directories automaticallyThe repository provides a complete working system:
# This works right now:
opencode --agent codebase-agent
> "Create a user authentication system"
# The agent will:
# 1. Plan implementation
# 2. Ask for approval
# 3. Delegate to @task-manager for complex features
# 4. Use @tester for tests
# 5. Use @reviewer for security
Context flows in one direction: Commands load context immediately, Agents can look up additional context deterministically.
Like a well-organized library: the librarian (command) brings you the right books immediately, but you (agent) can look up specific references when needed.
When you create a slash command with @ references, OpenCode automatically loads that context into the agent's memory BEFORE the agent starts thinking:
# .opencode/command/create-component.md
---
name: create-component
agent: simple-coder
---
You are creating React components following our patterns.
**Request:** $ARGUMENTS
@.opencode/context/frontend/react-patterns.md
@.opencode/context/styling/design-system.md
@.opencode/context/core/validation-patterns.md
Create the component now.
What happens when user types /create-component "user profile card":
❌ Without @ loading:
Agent: "I need to create a component but don't know your patterns. Let me search..."
→ Agent uses generic patterns or has to look up files
→ Inconsistent results, slower execution
✅ With @ loading:
Agent: "I have your React patterns, design system, and validation rules loaded. Creating component..."
→ Agent immediately follows your exact patterns
→ Consistent, fast, high-quality results
Base Context (Always Load):
@.opencode/context/core/essential-patterns.md
@.opencode/context/architecture/project-structure.md
Domain-Specific Context (Load Based on Command Purpose):
# Frontend commands
@.opencode/context/frontend/react-patterns.md
@.opencode/context/styling/design-system.md
# Backend commands
@.opencode/context/backend/server-patterns.md
@.opencode/context/database/query-patterns.md
# Testing commands
@.opencode/context/testing/test-patterns.md
# Advanced: Conditional context based on request analysis
@.opencode/context/core/essential-patterns.md
!`if echo "$ARGUMENTS" | grep -i "component\|ui" > /dev/null; then echo "@.opencode/context/frontend/react-patterns.md"; fi`
!`if echo "$ARGUMENTS" | grep -i "database\|query" > /dev/null; then echo "@.opencode/context/database/query-patterns.md"; fi`
Understanding @ symbol auto-loading is crucial because:
This mechanism is what makes the system "intelligent" - agents always start with the right knowledge instead of having to discover it.
OpenCode processes @ references only in command templates, NOT recursively in file contents.
# ✅ This works (in command template)
@.opencode/context/frontend/patterns.md
@.opencode/context/styling/design-system.md
# ❌ This doesn't work (inside patterns.md file)
# If patterns.md contains @other-file.md, it's treated as plain text
Critical Implication: Commands must load ALL necessary context upfront using @ references. Agents can look up additional files using tools (read, grep, glob), but cannot use @ loading themselves.
What: Entry points that load immediate context based on request analysis Rule: Commands are non-deterministic - they adapt context to the request
/workflow → Intelligent routing with dynamic context
/plan-task → Task planning with architecture context
/execute-task → Step execution with progress tracking
/create-frontend-component → UI development with styling + frontend context
/create-backend-operation → Server logic with backend + database context
/create-database-operation → Database queries with focused database context
/review-completion → Quality assurance with minimal context
/validate-with-tests → Automated testing with testing context
Command Structure Pattern:
---
name: command-name
agent: target-agent
description: "What this command does"
---
You are [doing specific task]. [Direct instructions to agent].
**Request:** $ARGUMENTS
**Your Instructions:**
1. **ANALYZE** the request...
2. **IMPLEMENT** following patterns...
3. **VALIDATE** the results...
**Context Loaded:**
@.opencode/context/core/essential-patterns.md
@.opencode/context/[domain]/[specific-patterns].md
@.opencode/context/architecture/architecture-lite.md
**Success Criteria:**
- [Specific measurable outcomes]
Execute this [task type] now.
What: Deterministic AI workers with specific capabilities Rule: Agents can look up additional context but are predictable in behavior
Primary Agents:
├── workflow-orchestrator.md → Routes requests and analyzes complexity
├── task-planner.md → Creates detailed task plans with file tracking
├── task-executor.md → Executes planned steps systematically
├── post-flight-reviewer.md → Reviews completed work for compliance
└── simple-coder.md → Implements focused development tasks
Subagents (Specialized):
├── subagents/code-reviewer.md → Security and quality reviews (read-only)
├── subagents/test-writer.md → Test creation and validation (reports issues)
├── subagents/pattern-finder.md → Discovers existing implementations
└── subagents/doc-writer.md → Documentation creation and updates
Agent Structure Pattern:
---
description: "What this agent does"
mode: primary|subagent
model: claude-4-sonnet
temperature: 0.1-0.3
tools:
read: true|false
edit: true|false
write: true|false
bash: true|false
task: true|false
permissions:
edit:
"**/*.env*": "deny"
"**/*.secret": "deny"
---
You are [specific role]. [Direct instructions for behavior].
**EXECUTE** this [process type] for every [task type]:
**1. [ACTION]** the [subject]:
- [Specific instruction 1]
- [Specific instruction 2]
**2. [ACTION]** the [subject]:
- [Specific instruction 1]
- [Specific instruction 2]
**RULES**:
- **ALWAYS** [critical requirement]
- **NEVER** [forbidden action]
- **ONLY** [scope limitation]
Execute [task type] now.
What: Layered knowledge system with focused domains Rule: Single-level loading - no recursive context references
context/
├── core/
│ └── essential-patterns.md (76 lines - always loaded)
├── architecture/
│ └── architecture-lite.md (74 lines - project structure)
├── frontend/
│ ├── frontend-patterns.md (230 lines - React patterns)
│ └── styling/design-system.md (122 lines - UI standards)
├── backend/
│ ├── backend-patterns.md (326 lines → split into focused files)
│ └── server-actions.md (100 lines - focused server action patterns)
├── database/
│ └── database-queries.md (207 lines - query patterns)
├── security/
│ └── security-patterns.md (205 lines - auth patterns)
├── testing/
│ ├── testing-patterns.md (322 lines → split)
│ └── unit-testing.md (100 lines - focused test patterns)
└── debugging/
└── common-errors.md (304 lines → split by error type)
Context File Structure Pattern:
**[ACTION]** [subject] using these exact patterns:
**[PATTERN NAME]** - [When to use]:
```[language]
// Example code with clear comments
// Showing exactly what to do
```
[ANOTHER PATTERN] - [When to use]:
// Another example
RULES:
### 4. Task Management (tasks/)
**What:** File-based progress tracking with checkbox systems
**Rule:** Every complex task gets a plan file with step-by-step tracking
tasks/ ├── features/ # Feature development │ └── [feature-name]/ │ ├── task-plan.md # Main plan with checkboxes │ ├── execution-log.md # Detailed progress log │ └── review-report.md # Post-flight review ├── fixes/ # Bug fixes │ └── [issue-name]/ │ ├── task-plan.md │ └── fix-report.md ├── improvements/ # Code improvements │ └── [improvement-name]/ └── single/ # Simple tasks └── [task-name].md
**Task Plan File Structure:**
```markdown
# Task: [Task Name]
## Overview
**Request**: [Original user request]
**Complexity**: [Simple/Medium/Complex]
**Estimated Duration**: [Time estimate]
**Dependencies**: [List any blocking requirements]
## Task Breakdown
### Phase 1: [Phase Name]
- [ ] **Step 1.1**: [Specific action]
- **Agent**: @[agent-name]
- **Context**: [Required context files]
- **Validation**: [How to verify completion]
- **Duration**: [Time estimate]
- [ ] **Step 1.2**: [Specific action]
- **Agent**: @[agent-name]
- **Context**: [Required context files]
- **Validation**: [How to verify completion]
- **Duration**: [Time estimate]
## Quality Gates
- [ ] **Build Validation**: TypeScript compilation passes
- [ ] **Code Review**: Security and quality review completed
- [ ] **Testing**: All tests pass and coverage adequate
- [ ] **Integration**: Feature works end-to-end
## Acceptance Criteria
- [ ] [Specific requirement 1]
- [ ] [Specific requirement 2]
## Progress Tracking
**Started**: [Date/Time]
**Last Updated**: [Date/Time]
**Status**: [Planning/In Progress/Review/Complete]
**Completed Steps**: 0/[Total Steps]
What: Multi-agent coordination with quality gates Rule: Complex workflows use multiple agents with validation checkpoints
Workflow Types:
├── Simple (< 30 min) → Direct execution with focused context
├── Medium (30min-2hrs) → Task planning with step tracking
└── Complex (> 2hrs) → Multi-phase with quality gates
Quality Gates:
├── Build Validation → TypeScript, linting, build checks
├── Code Review → Security and quality assessment
├── Testing → Automated test execution
└── Post-Flight Review → Instruction compliance verification
flowchart TD
A[User Request] --> B[Workflow Orchestrator]
B --> C{Analyze Request}
C --> D{Complexity?}
D -->|Simple| E[Direct Execution]
D -->|Complex| F[Task Planning]
E --> G[Load Focused Context]
G --> H[Execute with Agent]
H --> I[Validate Results]
I --> J[Complete]
F --> K[Create Task Plan File]
K --> L[Step-by-Step Execution]
L --> M[Update Progress Tracking]
M --> N{More Steps?}
N -->|Yes| O[Next Step]
N -->|No| P[Quality Gates]
O --> L
P --> Q[Post-Flight Review]
Q --> R[Mark Complete]
style A fill:#E6F3FF
style J fill:#E6FFE6
style R fill:#E6FFE6
# In workflow orchestrator
**ANALYZE** request: "$ARGUMENTS"
**BASE CONTEXT** (always loaded):
@.opencode/context/core/essential-patterns.md
@.opencode/context/architecture/architecture-lite.md
**CONDITIONAL CONTEXT** (based on request analysis):
!`if echo "$ARGUMENTS" | grep -i -E "(component|ui|frontend)" > /dev/null; then echo "@.opencode/context/styling/design-system.md"; fi`
!`if echo "$ARGUMENTS" | grep -i -E "(server|backend|action)" > /dev/null; then echo "@.opencode/context/backend/server-actions.md"; fi`
!`if echo "$ARGUMENTS" | grep -i -E "(database|query|data)" > /dev/null; then echo "@.opencode/context/database/database-queries.md"; fi`
# Essential Commands to Create:
/workflow # Main entry with intelligent routing
/plan-task # Complex task breakdown
/execute-task # Step-by-step execution
/create-frontend-component # UI development
/create-backend-operation # Server logic
/review-completion # Quality assurance
# Core Agents Needed:
workflow-orchestrator.md # Request analysis and routing
task-planner.md # Detailed planning with file tracking
task-executor.md # Step execution with progress updates
post-flight-reviewer.md # Compliance and quality review
simple-coder.md # Focused implementation work
# Specialized Subagents:
subagents/code-reviewer.md # Security and quality (read-only)
subagents/test-writer.md # Test creation (reports issues)
# Context Organization:
core/essential-patterns.md # Always loaded (76 lines)
architecture/architecture-lite.md # Project structure (74 lines)
frontend/frontend-patterns.md # React patterns (230 lines)
styling/design-system.md # UI standards (122 lines)
backend/server-actions.md # Server patterns (100 lines)
database/database-queries.md # Query patterns (207 lines)
# Task File Structure:
tasks/features/[name]/task-plan.md # Main planning file
tasks/features/[name]/review-report.md # Post-completion review
tasks/fixes/[name]/task-plan.md # Bug fix planning
tasks/single/[name].md # Simple tasks
# Automated Validation:
!`pnpm tsc --noEmit` # TypeScript check
!`pnpm lint` # Code quality
!`pnpm build` # Build validation
!`pnpm test` # Test execution
@ references)graph TB
subgraph "User Interface"
CMD[workflow plantask execute-task]
end
subgraph ".opencode/command/"
C1[workflow.md]
C2[plan-task.md]
C3[execute-task.md]
C4[create-frontend-component.md]
C5[create-backend-operation.md]
end
subgraph ".opencode/agent/"
A1[workflow-orchestrator.md]
A2[task-planner.md]
A3[task-executor.md]
A4[simple-coder.md]
A5[post-flight-reviewer.md]
end
subgraph ".opencode/context/"
CTX1[core/essential-patterns.md]
CTX2[architecture/architecture-lite.md]
CTX3[frontend/frontend-patterns.md]
CTX4[backend/server-actions.md]
CTX5[database/database-queries.md]
end
subgraph "tasks/"
T1[features/name/task-plan.md]
T2[fixes/name/task-plan.md]
T3[single/name.md]
end
CMD --> C1
CMD --> C2
CMD --> C3
C1 --> A1
C2 --> A2
C3 --> A3
C4 --> A4
C5 --> A4
A1 --> CTX1
A1 --> CTX2
A2 --> CTX2
A3 --> CTX1
A4 --> CTX3
A4 --> CTX4
A2 --> T1
A3 --> T1
A3 --> T2
Slash commands automatically inject context into agents using @ references:
# User types this:
/create-component "user profile card with avatar upload"
# OpenCode automatically:
# 1. Loads the command file: .opencode/command/create-component.md
# 2. Reads all @ referenced context files
# 3. Injects context + user request into the agent
# 4. Agent starts with full knowledge of your patterns
/workflow "your request" - Main entry point for any development task/plan-task "complex feature" - For multi-step planning/execute-task - Continue working on planned tasks/workflow "Create a user profile component with form validation"/create-frontend-component "Dashboard header with user menu"/review-completion - Check completed work for quality/workflow/plan-task then /execute-task/create-frontend-component, /create-backend-operation# Create essential structure
mkdir -p .opencode/{command,agent,context/{core,architecture}}
mkdir -p tasks/{features,fixes,single}
# .opencode/command/workflow.md
---
name: workflow
agent: workflow-orchestrator
---
You are analyzing requests and routing to optimal workflows.
**Request:** $ARGUMENTS
**Context Loaded:**
@.opencode/context/core/essential-patterns.md
@.opencode/context/architecture/architecture-lite.md
Route to appropriate specialized workflow now.
# .opencode/agent/workflow-orchestrator.md
---
description: "Routes requests to specialized workflows"
mode: primary
tools: [read, grep, glob, task]
---
You are analyzing requests and routing to specialized workflows.
**ANALYZE** the request and **ROUTE** to appropriate command:
- Feature development → /plan-task or /create-frontend-component
- Bug fixes → /fix-issue
- Code review → /review-code
Execute routing now.
# .opencode/context/core/essential-patterns.md
**CORE PATTERNS** - Essential patterns for all development:
**AUTHENTICATION PATTERN**:
```typescript
const user = await getCurrentUser();
if (!user) return { error: "Unauthorized" };
```
VALIDATION PATTERN:
const validated = schema.safeParse(data);
if (!validated.success) return { error: "Validation failed" };
### 5. Test Your System
```bash
# Test the workflow
/workflow "Create a user profile component"
# Should route to appropriate workflow with right context
You can extend this system by adding the example commands and agents mentioned throughout this blueprint. Here's how:
If you want specialized commands like /workflow or /create-frontend-component:
Create the command file: ```bash
name: workflow
You are analyzing requests and routing to optimal workflows.
Request: $ARGUMENTS
@.opencode/context/core/essential-patterns.md @.opencode/context/project/project-context.md
Route to appropriate agent or handle directly.
2. **Or just use `codebase-agent` directly:**
```bash
opencode --agent codebase-agent
> "Your request here"
Extend the context hierarchy for your tech stack:
# Create domain-specific context files
mkdir -p .opencode/context/frontend
mkdir -p .opencode/context/backend
mkdir -p .opencode/context/database
# Add your patterns
cat > .opencode/context/frontend/react-patterns.md << 'EOF'
**React Component Pattern:**
```tsx
export function MyComponent({ prop }: Props) {
// Your pattern here
}
EOF
Then reference in your commands:
```markdown
@.opencode/context/frontend/react-patterns.md
@.opencode/context/backend/api-patterns.md
Create domain-specific agents following the patterns:
# Example: .opencode/agent/frontend-specialist.md
---
description: "React frontend development specialist"
mode: primary
tools: [read, edit, write, bash]
---
You are a React frontend specialist.
**ANALYZE** the request and create components following patterns:
@.opencode/context/frontend/react-patterns.md
Execute implementation now.
Frontend Project:
context/frontend/react-patterns.mdcontext/styling/design-system.md/create-component commandcodebase-agent with frontend contextBackend Project:
context/backend/api-patterns.mdcontext/database/query-patterns.md/create-api-endpoint commandcodebase-agent with backend contextFull-Stack Project:
codebase-agent coordinate between domainsDon't create specialized commands/agents right away. Instead:
codebase-agent for everything@task-manager when features get complexExample progression:
# Week 1: Use codebase-agent for everything
opencode --agent codebase-agent
# Week 2: Add project-specific context
echo "Your patterns" > .opencode/context/project/api-patterns.md
# Week 3: Reference in codebase-agent
# The agent will automatically pick up context from project/
# Week 4: Create a command if you have a repeated workflow
# Only if you find yourself doing the same thing repeatedly
The system improves naturally as you:
The key principle: Start simple, extend only when you have a clear need.
Think of this system like a professional development team: each member has a specific role, they communicate clearly, they track their work systematically, and they validate quality at every step.
The codebase-agent is your senior developer who can handle most tasks. Add specialists only when needed.