A multi-agent governance-loop orchestration plugin for OpenCode, using the Tang Dynasty "Three Provinces and Six Ministries" metaphor to implement a draft→review→dispatch→execute→audit collaboration loop.
oh-my-tang-dynasty is an experimental multi-agent orchestration plugin for OpenCode that maps AI collaboration workflows onto the Tang Dynasty "Three Provinces and Six Ministries" governance structure: the Secretariat (中书省) drafts plans, the Chancellery (门下省) reviews (with rejection and re-draft), the Department of State Affairs (尚书省) dispatches tasks, the Six Ministries execute in parallel, and final review plus audit complete the governance loop.
Governance-Loop Orchestration
- Three Provinces and Six Ministries mapping: Secretariat (draft) → Chancellery (review) → Department of State Affairs (dispatch) → Six Ministries (execute) → Audit
- Retry-enabled review: Chancellery can reject plans for re-draft (up to
maxReviewRoundsrounds); failed execution results can also be rejected for re-dispatch
Reliability & Fallback
- Runtime + local deterministic dual-path fallback: prioritizes OpenCode runtime session, auto-switches to local heuristics on failure
- Audit entries record fallback provenance for traceability
Observability & Diagnostics
tang_pipeline: flow snapshot showing current stage, active tasks, and recent eventstang_audit: audit query with multi-dimensional filters and multiple views (summary/timeline/diagnostics/anomaly/hotspots/health)tang_doctor: health check outputting risk-weighted health score, riskLevel, riskPolicy, and prioritized findingstang_config: storage state, runtime mode, and execution limits
Execution & Resource Management
- Parallel ministry execution (
enableParallelExecution) bounded bymaxConcurrentMinistries - Per-ministry token budget tracking by the Ministry of Revenue (total budget
tokenBudgetLimit)
Extensibility
departmentscan override province names/system prompts;ministriescan add/remove execution rolesagentModelsallows per-role provider/model specification
Persistence
- Orchestration state saved to
.tang-dynasty/state.jsonfor cross-session review;tang_resetto clear
Exposed Tools: tang_process, tang_status, tang_pipeline, tang_agents, tang_edicts, tang_audit, tang_doctor, tang_config, tang_reset
Key Config (.oh-my-tang.json): maxConcurrentMinistries (default 3), maxReviewRounds (default 3), tokenBudgetLimit (default 100,000), healthRiskProfile (balanced/strict/relaxed), enableParallelExecution (default true), verbose (default false), agentModels
Installation: bun add oh-my-tang-dynasty, register in opencode.json with "plugin": ["oh-my-tang-dynasty"], config auto-generated on init. Non-plugin mode: import { TangDynastyOrchestrator } from "oh-my-tang-dynasty/lib".
Architecture Flow:
TangDynastyPlugin → TangDynastyOrchestrator.processRequest()
→ Secretariat (draft) → Chancellery (review, may reject)
→ Dept of State Affairs (dispatch) → Six Ministries (parallel, runtime or local fallback)
→ Chancellery (re-review results, may reject re-execution)
→ Dept of State Affairs (aggregate & persist) → Return final edict
Module Structure: src/plugin.ts (plugin entry), src/orchestrator.ts (orchestration core), src/config.ts/src/types.ts (Zod schema validation), src/runtime.ts (OpenCode runtime wrapper), src/agents/departments.ts/src/agents/ministries.ts (role definitions)
The author explicitly states this is a "public experiment and thought sample," primarily AI-generated code ("vibe coding"), with no guarantee of runnability or reproducibility, currently only adapted for the OpenCode runtime with no committed timeline for multi-platform expansion. Complements oh-my-opencode (broader general orchestration harness vs. this project's focus on governance semantics and audit visibility).