The Sensor Gate is DreamCode's first-stage classification system. It runs on every user turn (before the LLM) to determine intent, select skills, and decide whether to spawn specialist agents.
User Prompt
↓
Sensor Gate (Python)
├─ Intent classification
├─ Domain tagging
├─ Risk assessment
├─ Skill chain selection
└─ Specialist spawn decision
↓
Guardian AI (risk approval)
↓
LLM + Skill Chain Execution
The sensor gate Python script produces a structured JSON result:
{
"intent": "Fix authentication bug in login flow",
"domain_tags": ["security", "backend", "api"],
"risk_level": "medium",
"confidence": 0.85,
"complexity": "medium",
"primary_skill": "debugging",
"support_skills": ["testing", "security"],
"chain": ["debugging", "testing", "security"],
"guardian_decision": "APPROVED",
"guardian_risk": "low",
"mode": "DREAM_INNOVATION",
"personas": [
{"name": "The Detective", "role": "Root Cause Analysis", ...},
{"name": "The Artisan", "role": "Code Quality", ...}
]
}The spawn necessity algorithm (evaluateSpawnNecessity()) determines if specialists are needed:
| Factor | Weight | Condition |
|---|---|---|
| Simplicity pattern | Skip | Prompt starts with fix/update/change/add/remove |
| Unique domains | +3 | 3+ different domain tags |
| Unique domains | +1 | 2 different domain tags |
| High risk | +2 | risk_level === "high" |
| Chain length | +2-3 | effectiveChainLen >= 2 (filtering "always" skills) |
| DREAM_INNOVATION | +2 | Innovation mode active |
| Code + long prompt | +1 | Code blocks present and prompt > 200 chars |
Score → Spawns: ceil(score / 2), capped at 5.
- 5 spawns per 5-minute rolling window per session
- Enforced in code, not just prompt text
- When limit hit: rate-limit warning injected, task handled directly
The sensor gate is bypassed for:
- Subagent sessions (they don't re-enter persona spawning)
- Synthesis responses (synthetic messages don't re-trigger classification)
/compactcommands (directly trigger context compaction)- Greeting detection (
is_social_greeting: trueskips chain execution)
~/.config/dreamcode/config.yaml:
sensor_gate:
enabled: true
min_confidence: 0.5
max_personas: 5- Dream Thinking — The 6-phase engine activated by sensor gate
- Skills Reference — Skills selected by sensor gate
- Scoring & Enforcement — Scoring after execution