OpenCode Multi-Agent Orchestration Guide

Orchestrate Spring Boot features with 4 specialized agents (orchestrator + coder + reviewer + docs) using a production-grade folder structure.

Summary

๐ŸŽฏ Why This Architecture

  • Separation of concerns: Each agent has one job
  • Persistent memory: Project facts + run logs
  • Skills: Reusable agent capabilities
  • Audit trail: Every step logged
  • Scalable: Works for any Java/Spring project

๐Ÿ“ Project Structure

your-spring-boot-project/
โ”œโ”€โ”€ AGENTS.md                          # Global workflow rules [REQUIRED]
โ”œโ”€โ”€ .opencode/agents/
โ”‚   โ”œโ”€โ”€ orchestrator.md                # Primary coordinator
โ”‚   โ”œโ”€โ”€ coder.md                       # Code implementation
โ”‚   โ”œโ”€โ”€ reviewer.md                    # Quality gate
โ”‚   โ””โ”€โ”€ docs.md                        # Documentation
โ”œโ”€โ”€ memory/
โ”‚   โ”œโ”€โ”€ project.md                     # Architecture facts [REQUIRED]
โ”‚   โ””โ”€โ”€ conventions.md                 # Code style rules
โ”œโ”€โ”€ runs/                              # Auto-generated logs [REQUIRED FOLDER]
โ””โ”€โ”€ skills/                            # Agent superpowers [REQUIRED]
    โ”œโ”€โ”€ log-run.SKILL.md               # Log phase results
    โ”œโ”€โ”€ spring-boot-coder.SKILL.md     # Spring patterns
    โ”œโ”€โ”€ security-review.SKILL.md       # Review checklist
    โ””โ”€โ”€ api-docs.SKILL.md              # Doc templates

๐Ÿš€ Quick Setup

# 1. Create structure
mkdir -p .opencode/agents memory runs skills

# 2. Copy all .md files from this guide
# 3. cd your-spring-boot-project
# 4. opencode  # Test it works

๐Ÿ“‹ File Contents

AGENTS.md (Root)

# Spring Boot Agent Workflow

## Process
1. **Orchestrator** plans + coordinates
2. **Coder** implements minimal changes  
3. **Reviewer** validates correctness/security
4. **Docs** updates README/api.md

## Memory Rules
- Read `memory/project.md` + `memory/conventions.md`
- Log to `runs/run-N.md` after each phase
- Never break existing functionality

## Success Criteria
- Tests pass: `mvn test`
- Linting passes: `mvn spotless:check` 
- Security review clean
- Docs updated

memory/project.md

# Project Architecture

## Stack
- Spring Boot 3.x
- Spring Data JPA / DynamoDB  
- Spring Security JWT
- REST APIs + OpenAPI
- Maven + JUnit 5

## Patterns
- @RestController โ†’ @Service โ†’ @Repository
- DTOs for all endpoints
- @Valid validation
- Exception handling with @ControllerAdvice

memory/conventions.md

# Code Conventions

## Naming
- camelCase methods/fields
- PascalCase classes
- Constants UPPER_SNAKE_CASE

## Java
- Immutable DTOs with records
- final fields where possible
- Try-with-resources for IO

## Testing
- MockMvc for controllers
- @MockBean for services
- 80%+ coverage

๐Ÿง  Agent Configurations

.opencode/agents/orchestrator.md

---
description: Orchestrates coder, reviewer, and docs agents while logging each step.
mode: primary
model: opencode/gpt-5.1-codex
temperature: 0.2
permission:
  edit: allow
  bash: allow
  webfetch: ask
  task: allow
skills:
  "*": allow
hidden: false
---
You coordinate the workflow. Use skills/log-run after each phase.
1. Read AGENTS.md + memory/
2. Plan implementation steps
3. @coder โ†’ implement
4. @reviewer โ†’ validate  
5. @docs โ†’ document
6. Log everything to runs/

.opencode/agents/coder.md

---
description: Implements features following Spring Boot patterns.
mode: subagent
model: opencode/gpt-5.1-codex
temperature: 0.1
permission:
  edit: allow
  bash: allow  
  webfetch: ask
  task: deny
skills:
  "spring-boot-*": allow
  "log-run": allow
---
Read memory/ files. Make minimal, safe changes.
Use spring-boot-coder skill. Add tests.

.opencode/agents/reviewer.md

---
description: Security and quality review gate.
mode: subagent  
model: opencode/claude-sonnet-4-20250514
temperature: 0.3
permission:
  edit: deny
  bash: deny
  webfetch: ask
  task: deny
skills:
  "security-review": allow
---
Use security-review skill. Block CRITICAL issues.
Format: SEVERITY | ISSUE | FILE:LINE | FIX

.opencode/agents/docs.md

---
description: Updates documentation from code changes.
mode: subagent
model: opencode/llama-3.2-90b  
temperature: 0.2
permission:
  edit: allow
  bash: deny
  webfetch: ask
  task: deny
skills:
  "api-docs": allow
---
Use api-docs skill. Update README.md + docs/api.md.
Include curl examples.

โšก Skills

skills/log-run.SKILL.md

---
name: log-run
description: Append phase to runs/run-N.md
scope: project
---
1. `ls -1tr runs/ | tail -1` โ†’ get latest run
2. Append YAML: phase, agent, files[], status, notes  
3. `git add runs/ && git commit -m "Log phase"`

skills/spring-boot-coder.SKILL.md

---
name: spring-boot-coder
description: Spring Boot implementation patterns
scope: project
---
@RestController โ†’ @Service โ†’ Repository
DTOs with @Valid
@ControllerAdvice exceptions
MockMvc tests
pom.xml updates

skills/security-review.SKILL.md

---
name: security-review
description: Security checklist
scope: project
---
CRITICAL: SQLi, auth bypass, secrets
HIGH: Missing @Valid, JWT expiry
MEDIUM: No tests, unused imports
LOW: Style violations

skills/api-docs.SKILL.md

---
name: api-docs  
description: API documentation templates
scope: project
---
curl -X POST /api/users -H "Authorization: Bearer ..."
Update README #Endpoints
OpenAPI 3.0 spec format

๐ŸŽฎ Usage

cd your-spring-boot-project
opencode

> @orchestrator Add JWT login endpoint with refresh tokens

# Watch it:
# 1. Creates runs/run-001.md  
# 2. Coder implements JwtController.java + tests
# 3. Reviewer validates security
# 4. Docs updates README.md
# 5. Logs complete run

๐Ÿ” Troubleshooting

Issue Fix
Agent not found Check .opencode/agents/*.md syntax
Permission denied Adjust permission: in headers
Skills ignored Verify skills/*.SKILL.md naming
No logs Orchestrator needs bash: allow

๐Ÿš€ Next Level

  • GitHub Actions: opencode @orchestrator in CI
  • API wrapper: Spring Boot calling opencode subprocess
  • Team sharing: Commit structure to repo[^2][^1]

This = repeatable, auditable AI development workflow.

Back to top