opencode-threadweaver
v0.1.8
Published
ThreadWeaver — Multi-Agent Debate Plugin for OpenCode. Grok 4.20-style parallel analysis, cross-critique, and weighted synthesis.
Maintainers
Readme
opencode-threadweaver
Multi-Agent Debate Plugin for OpenCode. Spawns 4-16 specialized agents that independently analyze, cross-critique, revise, and synthesize a weighted final answer.
Install
# In your OpenCode config directory
npm install opencode-threadweaverAdd to opencode.jsonc:
{
"plugin": [
"opencode-threadweaver"
]
}How It Works
User Query
|
v
Complexity Router --> standard (4 agents) or heavy (4 core + up to 12 specialists)
|
v
Round 1: PARALLEL ANALYSIS -- each agent independently analyzes the query
Round 2: CROSS-CRITIQUE -- agents critique each other's outputs
Round 3: REVISION -- agents revise based on critiques
|
v
SYNTHESIS: Captain merges all outputs with dynamic weights
|
v
Result: synthesis + weights + dissents + round detailsCore Agents (Standard Mode)
| ID | Role | Focus | |----|------|-------| | captain | Captain | Task decomposition, mediation, final synthesis | | verifier | Verifier | Fact-checking, evidence validation, data verification | | reasoner | Reasoner | Logical analysis, step-by-step reasoning | | creator | Creator | Blind spot detection, alternative perspectives |
Specialist Agents (Heavy Mode)
Activated via sparse activation when the query touches specific domains:
- Verifier specialists: security, performance, architecture
- Reasoner specialists: math, algorithms, systems
- Creator specialists: naming, simplification, alternatives
- Captain specialists: priorities, risks, communication
Dynamic Weighting
Each agent's contribution is weighted by:
final_weight = normalize(
selfConfidence * 0.25 +
crossAgreement * 0.45 +
domainRelevance * 0.30
)Consensus (crossAgreement) carries the highest weight -- conclusions agreed upon by multiple agents are prioritized.
Keyword Triggers
The plugin auto-activates when these keywords appear in a message (outside code blocks):
debate | weave | threadweave | multi-perspectiveJapanese keywords:
debate | threadweave | weaveConfiguration
Create opencode-threadweaver.jsonc in your OpenCode config directory (~/.config/opencode/):
{
// Model for all debate agents
"model": "openai/gpt-4o",
// Per-role model overrides ("*" = default for unspecified roles)
"roleModels": {
"captain": "openai/gpt-4o",
"*": "anthropic/claude-sonnet-4"
},
// Number of debate rounds (1-5)
"debateRounds": 3,
// Complexity score threshold for heavy mode (1+)
"heavyThreshold": 5,
// Force complexity level: "standard" | "heavy" | null (auto)
"forceComplexity": null,
// Minimum domain relevance for specialist activation (0-1)
"activationThreshold": 0.3,
// Timeout per round (ms)
"roundTimeoutMs": 120000,
// Total timeout (ms)
"totalTimeoutMs": 600000,
// Disable specific hooks
"disabled_hooks": [],
// Concurrency control
"concurrency": {
"defaultConcurrency": 4,
"providerConcurrency": {},
"modelConcurrency": {}
}
}Project-level config can be placed at .opencode/opencode-threadweaver.jsonc (overrides user-level).
Profiles
Define multiple configurations and switch between them via activeProfile or the THREADWEAVER_PROFILE environment variable:
{
"activeProfile": "cloud",
"profiles": {
"cloud": {
"forceComplexity": "standard",
"roleModels": { "captain": "openai/gpt-4o", "*": "anthropic/claude-sonnet-4" },
"debateRounds": 1
},
"cloud-heavy": {
"forceComplexity": "heavy",
"roleModels": { "captain": "openai/gpt-4o", "*": "anthropic/claude-sonnet-4" },
"debateRounds": 3
},
"local": {
"forceComplexity": "standard",
"roleModels": { "captain": "ollama/llama3:70b", "*": "ollama/mistral:7b" },
"debateRounds": 1
},
"local-heavy": {
"forceComplexity": "heavy",
"roleModels": { "captain": "ollama/llama3:70b", "*": "ollama/mistral:7b" },
"debateRounds": 2
}
}
}Switch profiles at runtime:
# Via environment variable (takes priority)
THREADWEAVER_PROFILE=local opencode exec "debate: best caching strategy"
# Or set activeProfile in config for the defaultProfile settings are merged on top of any base config values defined outside profiles.
Direct Tool Usage
threadweaver({ query: "Compare React vs Vue for a large-scale enterprise app" })With options:
threadweaver({
query: "Security implications of microservices vs monolith",
complexity: "heavy",
rounds: 3,
json: true
})CLI (non-interactive)
opencode run --format json "debate: React vs Vue"Output
The tool returns:
- synthesis -- the final merged answer
- weights -- per-agent confidence, agreement, and final weight
- dissents -- topics where agents did not reach consensus
- round details -- collapsible per-round outputs
JSON mode (json: true) returns the full structured result for pipeline integration.
Architecture
src/
index.ts -- Plugin entry, keyword detector, hooks
types.ts -- All TypeScript type definitions
complexity-router.ts -- standard/heavy routing + sparse activation
roles.ts -- 4 core + 12 specialist role definitions
protocol.ts -- Debate loop (runThreadWeaver)
weighting.ts -- Dynamic weights, confidence extraction, critique parsing
prompts.ts -- Round prompt templates
threadweaver-tool.ts -- Tool registration + output formatting
config.ts -- Config loading (user + project level) + profile resolution
shared.ts -- Utilities (sanitizer, concurrency pool, resilience, TtlMap)Development
bun install
bun test # 39 tests
bun run build # outputs to dist/Gotchas
- Do NOT export non-function values from the plugin entry point. OpenCode treats all exports as plugin instances and will try to call them. Only export the plugin function and type-only exports.
- The plugin is standalone -- no dependency on
opencode-ultra. - All shared utilities (sanitizer, concurrency pool, etc.) are inlined in
shared.ts.
License
See LICENSE.md
