* feat(agents): implement category-based agent organization system - Organize agents into domain categories (core, development, content, data, product, learning) - Move 10 agents to category subdirectories with proper git rename tracking - Update 13 subagents with category and type metadata in frontmatter - Add category metadata files (0-category.json) documenting common patterns - Implement local registry fallback in install script for offline development - Add comprehensive validation suite with 15 automated tests (100% pass rate) - Enhance registry validation with duplicate ID and consistency checks - Update eval framework with intelligent path resolution (backward compatible) - Archive legacy eval structure to _archive/ for reference - Update all documentation to reflect category-based structure - Bump version to 0.5.0 with accurate CHANGELOG Technical Details: - 23 agents organized (10 category agents, 13 subagents) - 6 category directories created - Path resolution supports both agent IDs and category paths - Registry schema updated to v2.0.0 - 159 files changed, 872 insertions(+), 10738 deletions(-) BREAKING CHANGE: Agent file paths now use category structure. Update references from .opencode/agent/openagent.md to .opencode/agent/core/openagent.md. Eval framework maintains backward compatibility via path resolution. * refactor(evals): consolidate documentation and enhance test infrastructure - Remove temporary project tracking files (PHASE_5_COMPLETE, PROJECT_COMPLETE, etc.) - Consolidate evaluation framework docs into main README - Enhance test execution with improved logging and multi-prompt support - Move system-builder from core to meta category - Add comprehensive test suites for openagent with organized structure - Create evaluation test structure for all subagents - Clean up archived workflows and redundant documentation - Update registry to reflect new agent organization - Add shared test templates and golden test patterns * feat(ci): add manual trigger support for bot-created PRs in validate-registry workflow - Add pr_number input to workflow_dispatch for manually triggering validation - Fetch PR details dynamically when triggered manually - Support both automatic (PR event) and manual (workflow_dispatch) triggers - Enable validation of bot-created PRs like automated version bumps - Update branch detection and push logic to handle both trigger types - Add documentation explaining how to manually trigger for bot PRs * feat(evals): add explicit context file validation to test framework - Add expectedContextFiles field to test YAML schema for explicit context file specification - Enhance context-loading-evaluator to support both auto-detect and explicit validation modes - Update documentation with comprehensive guide and examples - Clean up archived legacy test structure (90+ old test files) - Add new example tests demonstrating explicit context validation - Backward compatible with existing tests * feat(evals): add multi-agent logging system and performance optimizations Implement comprehensive multi-agent logging and performance improvements for the eval framework. Task 01: Multi-Agent Logging System - Add complete hierarchical logging module (evals/framework/src/logging/) - SessionTracker: tracks parent-child delegation hierarchies - MultiAgentLogger: pretty-prints logs with visual indentation - Formatters: box characters and emoji formatting - 37 passing unit tests (session-tracker, logger, integration) - Integrate with SDK event stream handler - Hook into session.created, message.updated, message.part.updated events - Real-time child session detection via timestamp heuristics - Message deduplication for cleaner output - Enable in debug mode only (<1% performance overhead) - Add demo script and comprehensive documentation Task 02: Performance Optimizations - Reduce grace period from 5s to 2s (67% reduction, 10-20% faster tests) - Add PerformanceMetricsEvaluator for bottleneck identification - Collects tool latencies, inference time, idle time - Provides full performance visibility - Update smoke test to validate delegation (core feature) - Replace simple read test with multi-agent delegation test - Tests both parent and child agent functionality - Validates multi-agent logging system Results: - 37 unit tests passing - Smoke test passing (95/100 score) - Clean hierarchical logging output - 10-20% faster test execution - Full multi-agent visibility Files changed: 16 files, +2678 lines Time saved: ~6-8 days (completed in 6 hours vs 3-5 day estimate) * feat(evals): show child agent execution in non-debug mode - Enable MultiAgentLogger in both debug and non-debug modes - Add verbose parameter to control output level - Non-verbose mode shows concise child session lifecycle: - Child agent started message - Child agent completed with duration - Verbose mode (--debug) shows full delegation hierarchy - Update documentation to reflect new behavior This provides visibility into delegation without overwhelming output, giving confidence that child agents are actually running. * feat(evals): improve delegation testing and behavior validation Major improvements to eval framework: Test Suite: - Add 00-smoke-test.yaml (basic read operation) - Rename 01-smoke-test.yaml → 02-delegation-test.yaml (delegation test) - Add simple-responder test agent for delegation testing - Add debug test: simple-subagent-call.yaml Evaluators: - Add agent-model-evaluator.ts for agent/model validation - Enhance behavior-evaluator.ts with detailed task tool output - Improve delegation-evaluator.ts with better evidence tracking Schema & Execution: - Add expectedAgent and expectedModel to test schema - Improve test executor with better logging and error handling Documentation: - Update evals/README.md with new features and performance improvements - Remove outdated MULTI_AGENT_LOGGING_COMPLETE.md Registry: - Add simple-responder test agent to registry Fixes: - Fix dashboard.sh path resolution These changes provide better visibility into delegation, improved test coverage, and clearer validation of agent behavior. * chore: add GitHub Actions workflow and plugin documentation - Add .github/workflows/evals/run-evaluations.yml for automated eval testing - Add dev/ai-tools/opencode/plugins/Plugin-inspiration.md for plugin development reference
16 KiB
The OpenCode Agent System Blueprint
Build Intelligent Workflow Systems with Context-Aware AI
📘 What Is This Blueprint?
This is a teaching document that explains how the OpenCode agent system works and how to extend it for your needs.
You don't need to read this to use the system - the agents work out of the box. Read this document only if you want to:
- Understand the architecture behind the system
- Create your own custom agents and commands
- Extend the system with domain-specific patterns
- Learn how context loading and agent coordination works
If you just want to start building, skip this document and use openagent instead. See the README.md for quick start instructions.
⚡ TL;DR - Quick Reference
For New Users:
- Start with
opencode --agent openagentfor all questions and tasks - The agent handles planning, implementation, testing, and review automatically
- Add your coding patterns to
.opencode/context/project/project-context.md - Let the agent delegate to specialized subagents when needed
For Advanced Users Building Custom Agents:
- Use
/prompt-enchancerto create complex agents with workflows - Read this document to understand architecture patterns
- Learn how context loading works (the
@symbol) - Extend the system with domain-specific context files
Core Concept:
Commands load context → Agents execute with that context → Subagents handle specialized tasks
When to read this document:
- ✅ You want to create custom agents or commands
- ✅ You need to understand how context loading works
- ✅ You want to extend the system for your specific needs
- ❌ You just want to start building (use
openagentinstead)
🎯 What This Document Teaches
This blueprint explains the architecture patterns behind the OpenCode agent system. You'll learn:
- How context loading works (the
@symbol) - How agents, commands, and context files work together
- How to create custom agents and commands
- How to extend the system for your needs
📖 Installation & Usage: See README.md in the repository root.
Understanding Examples in This Document
When you see commands like /workflow, /plan-task, /create-frontend-component:
- These are pattern examples showing how you COULD structure commands
- Most aren't implemented in the repository
- The existing
openagentandopencoderalready handle these workflows - Create them only if you have specific repeated patterns
When you see extensive context hierarchies:
- The repository includes
core/andproject/context files - Add domain-specific files (
frontend/,backend/,database/) as needed - Start simple, expand based on your needs
When you see task management structures:
- The
task-manageragent createstasks/directories automatically openagentcreates session files in.tmp/sessions/for context preservation- No need to pre-create structures
The Golden Rule
Context flows in one direction: Commands load context immediately, Agents can look up additional context deterministically.
Think of it like a well-organized library: the librarian (command) brings you the right books immediately, but you (agent) can look up specific references when needed.
How @ Symbol Context Loading Works
The Magic of Automatic Context Injection
When you create a slash command with @ references, OpenCode automatically loads that context into the agent's memory BEFORE the agent starts thinking.
Example command structure:
- Command file references context files using
@.opencode/context/... - OpenCode reads those files automatically
- Context is injected into the agent's working memory
- Agent receives: user request + all loaded context + instructions
- Agent can immediately use patterns without looking them up
Why This Is Powerful
Without @ loading:
- Agent doesn't know your patterns
- Has to search or use generic patterns
- Inconsistent results, slower execution
With @ loading:
- Agent has your patterns loaded immediately
- Follows your exact standards
- Consistent, fast, high-quality results
Best Practices for Context Loading
- Load 2-4 context files maximum - Prevent cognitive overload
- Always include core patterns - Essential patterns every agent needs
- Load domain-specific patterns - Based on what the command does
- Keep context files focused - 50-150 lines each
- Use conditional loading - Load different context based on request analysis
Why This Architecture Matters
- It's the foundation of how agents get consistent context
- It determines command design - You must anticipate what context agents need
- It explains the architecture - Commands are "smart loaders", agents are "focused executors"
- It guides best practices - Load the right context, not too much, not too little
Core Principles
1. Single-Level Context Loading
OpenCode processes @ references only in command templates, NOT recursively in file contents.
- ✅ Works:
@references in command files - ❌ Doesn't work:
@references inside context files (treated as plain text)
Implication: Commands must load ALL necessary context upfront. Agents can look up additional files using tools (read, grep, glob), but cannot use @ loading themselves.
2. Deterministic vs Non-Deterministic Behavior
- Commands: Non-deterministic - Analyze requests and load appropriate context
- Agents: Deterministic - Predictable behavior, can look up additional context
3. Context Optimization
- Maximum 4 context files per command - 250-450 lines total
- 50-150 lines per context file - Optimal range
- Always load core patterns - Plus request-specific context
The System Components
1. Commands (.opencode/command/)
What they do: Entry points that load context based on request analysis
Examples:
/commit- Smart git commits/optimize- Code optimization/test- Testing workflows/prompt-enchancer- Improve prompts and create complex agents
How they work:
- User types a command
- Command analyzes the request
- Loads appropriate context files using
@ - Passes everything to an agent
- Agent executes with full context
2. Agents (.opencode/agent/)
What they do: AI workers with specific capabilities and predictable behavior
Main agents in this repo:
openagent- Universal coordinator for general tasks, questions, and workflows (recommended default)opencoder- Specialized development agent for complex coding and architecturesystem-builder- Meta-level generator for creating custom AI architectures
Subagents (specialized helpers):
Core Coordination:
task-manager- Task breakdown and planningdocumentation- Documentation authoring
Code Specialists:
coder-agent- Quick implementationsreviewer- Code review and securitytester- Test creation and validationbuild-agent- Type checking and validationcodebase-pattern-analyst- Pattern discovery
Utilities:
image-specialist- Image generation (Gemini AI)
System Builder (Meta-Level):
domain-analyzer- Domain analysisagent-generator- Agent generationcontext-organizer- Context organizationworkflow-designer- Workflow designcommand-creator- Command creation
Agent structure:
- Frontmatter with metadata (description, mode, tools, permissions)
- Clear instructions for behavior
- Specific rules and constraints
- Structured response formats
3. Context (.opencode/context/)
What it is: Layered knowledge system with your coding patterns
Structure:
core/- Essential patterns (always loaded)project/- Your project-specific patterns- Add more as needed:
frontend/,backend/,database/, etc.
How it works:
- Context files contain your coding standards
- Commands load relevant context using
@ - Agents follow those patterns automatically
- Single-level loading (no recursive references)
Best practices:
- Keep files focused (50-150 lines)
- Use clear pattern names
- Include when to use each pattern
- Add rules and constraints
4. Task Management (tasks/)
What it is: File-based progress tracking with checkboxes
Structure:
features/- Feature developmentfixes/- Bug fixesimprovements/- Code improvementssingle/- Simple tasks
How it works:
task-managercreates task files automatically- Each task has a plan with checkboxes
- Agents update progress as they work
- Quality gates ensure standards are met
5. Workflow Orchestration
How agents coordinate:
- Simple tasks (< 30 min) - Direct execution
- Medium tasks (30min-2hrs) - Task planning with tracking
- Complex tasks (> 2hrs) - Multi-phase with quality gates
Quality gates:
- Build validation (TypeScript, linting)
- Code review (security, quality)
- Testing (automated tests)
- Post-flight review (compliance check)
System Flow
Simple workflow:
- User makes request
- Agent analyzes and plans
- User approves
- Agent implements step-by-step
- Validation runs automatically
- Complete
Complex workflow:
- User makes request
- Agent delegates to
@task-manager - Task manager creates detailed plan
- Agent implements one step at a time
- Progress tracked in task files
- Quality gates at milestones
- Subagents handle specialized work
- Post-flight review
- Complete
Context Loading Strategy
Dynamic Context Loading
Commands can load different context based on request analysis:
- Analyze the user's request
- Determine domain (frontend, backend, database, etc.)
- Load base context (core patterns)
- Load domain-specific context conditionally
- Pass everything to agent
Context Size Guidelines
- ✅ Optimal: 50-150 lines (focused, actionable)
- ⚠️ Acceptable: 150-250 lines (comprehensive but manageable)
- ❌ Too Large: 250+ lines (split into focused files)
Context Loading Rules
- Always load core patterns
- Maximum 4 context files per command
- Load based on request analysis (dynamic, not static)
- Use bash commands for conditional loading
Building Your Own Agents
Use /prompt-enchancer
If you're building custom agents with complex workflows, use the /prompt-enchancer command:
- Helps you create well-structured agent prompts
- Guides you through best practices
- Ensures proper formatting and instructions
- Creates agents that work well with the system
How to use it:
/prompt-enchancer "I want to create an agent that does X"
The command will help you:
- Structure your agent properly
- Add appropriate context loading
- Define clear instructions
- Set up permissions and tools
- Create workflow patterns
Agent Design Best Practices
- Make agents deterministic - Predictable behavior
- Give clear, direct instructions - Not documentation
- Separate concerns - One agent, one responsibility
- Use structured response formats - Consistent output
- Define permissions - Control what agents can do
- Specify tools - Only give access to what's needed
When to Create Custom Agents
Create custom agents when:
- You have repeated workflows
- You need specialized behavior
- You want domain-specific expertise
- You have unique quality requirements
Don't create custom agents when:
openagentoropencoderalready handles it- It's a one-time task
- You're just starting out
Extending the System
Adding Domain-Specific Context
- Create context directory for your domain
- Add pattern files (50-150 lines each)
- Reference in commands using
@ - Agents automatically use your patterns
Example domains:
- Frontend (React, Vue, etc.)
- Backend (APIs, servers)
- Database (queries, schemas)
- Testing (unit, integration)
- Security (auth, validation)
Creating Custom Commands
- Identify repeated workflows
- Determine what context is needed
- Create command file with
@references - Specify target agent
- Add clear instructions
- Test and refine
Use /prompt-enchancer to help create complex commands.
Building Specialized Subagents
- Identify specialized capability needed
- Define clear scope and responsibility
- Set appropriate permissions
- Create focused instructions
- Test with main agents
Best Practices
Context Management
- Keep context files focused (50-150 lines)
- Use single-level loading (no recursive
@references) - Load dynamically based on request analysis
- Always include core patterns
Agent Design
- Make agents deterministic (predictable behavior)
- Give clear, direct instructions (not documentation)
- Separate concerns (one agent, one responsibility)
- Use structured response formats
- Use
/prompt-enchancerfor complex agents
Task Management
- Break complex work into steps (15-30 minutes each)
- Use checkbox tracking for progress visibility
- Include validation criteria for each step
- Implement quality gates at key milestones
Workflow Orchestration
- Analyze before routing (complexity and domain)
- Use appropriate workflows (simple vs complex)
- Coordinate multiple agents for complex tasks
- Validate at every step (build, test, review)
The Simple Path (Recommended)
Don't create specialized commands/agents right away. Instead:
- Start with
openagentfor everything (questions and tasks) - Add context files for your tech stack as needed
- Use
@task-managerwhen features get complex (openagent delegates automatically) - Let subagents handle specialized work (@tester, @reviewer, @coder-agent)
- Create specialized commands only when you have repeated workflows
- Use
/prompt-enchancerwhen building custom agents
Example Progression
Week 1: Use openagent for everything (questions and tasks)
Week 2: Add project-specific context to project/project-context.md
Week 3: Agent automatically picks up your patterns
Week 4: Create a command if you have repeated workflows (use /prompt-enchancer)
How the System Improves
The system improves naturally as you:
- Add context files - Capture your coding patterns
- Refine agent prompts - Improve instructions based on results
- Create project-specific commands - Automate repeated workflows
- Build subagents - Extract specialized capabilities
- Document in context/ - Every pattern you discover
The key principle: Start simple, extend only when you have a clear need.
Project Structure
.opencode/
├── agent/ # AI agents
│ ├── core/
│ │ ├── openagent.md
│ │ └── opencoder.md
│ ├── meta/
│ │ └── system-builder.md
│ └── subagents/ # Specialized helpers
│ ├── reviewer.md
│ ├── tester.md
│ ├── coder-agent.md
│ ├── documentation.md
│ ├── build-agent.md
│ └── codebase-pattern-analyst.md
├── command/ # Slash commands
│ ├── commit.md
│ ├── optimize.md
│ ├── test.md
│ ├── clean.md
│ ├── context.md
│ ├── prompt-enchancer.md # Use this to build agents!
│ └── worktrees.md
├── context/ # Coding patterns
│ ├── core/ # Essential patterns (always loaded)
│ │ └── essential-patterns.md
│ └── project/ # Your patterns (add here!)
│ └── project-context.md
├── plugin/ # Optional: Telegram notifications
└── tool/ # Optional: Gemini AI image tools
Key Takeaways
- Context flows one direction - Commands load immediately, Agents look up deterministically
- Keep context focused - 50-150 lines per file, maximum 4 files per command
- Make agents predictable - Deterministic behavior with clear instructions
- Track everything - File-based task management with checkbox progress
- Validate continuously - Quality gates and post-flight reviews
- Start simple - Build core system first, add complexity gradually
- Use
/prompt-enchancer- When building custom agents with workflows
Remember
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 openagent is your universal coordinator and opencoder is your senior developer. Add specialists only when needed.
When you need to build custom agents, use /prompt-enchancer to create well-structured, complex agents with proper workflows.