Skip to main content

ADR-191: Intent Classification System

Status

Accepted - December 15, 2025

Context

CODITECT needs a way to understand user intent from natural language queries and route them to the appropriate agents, commands, or workflows. Without intent classification, users must know exact command syntax and agent names.

Problem Statement

  1. Barrier to Entry: Users must learn specific command syntax (/agent senior-architect "design system")
  2. Agent Discovery: Users don't know which of 776 agents is best for their task
  3. Workflow Routing: Complex tasks require multiple agents in sequence
  4. Context Awareness: Same query may require different routing based on project context

Requirements

  • Classify natural language into actionable intents
  • Route to appropriate CODITECT components (agents, commands, skills)
  • Support multi-intent queries (e.g., "review code and deploy to staging")
  • Maintain context awareness across session
  • Integrate with MoE verification layer

Decision

Implement a Multi-Stage Intent Classification System with three classification layers:

Architecture

┌─────────────────────────────────────────────────────────────────────┐
│ INTENT CLASSIFICATION SYSTEM │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ User Query: "Help me debug the authentication error" │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ LAYER 1: COARSE CLASSIFICATION │ │
│ │ Intent Categories: │ │
│ │ • development (code, debug, test) │ │
│ │ • infrastructure (deploy, scale, monitor) │ │
│ │ • documentation (write, update, review) │ │
│ │ • analysis (research, analyze, compare) │ │
│ │ • management (plan, track, report) │ │
│ │ • meta (help, list, configure) │ │
│ └───────────────────────┬─────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ LAYER 2: FINE CLASSIFICATION │ │
│ │ Sub-intents for "development": │ │
│ │ • code_review, code_write, code_refactor │ │
│ │ • debug_error, debug_performance │ │
│ │ • test_write, test_run, test_fix │ │
│ │ │ │
│ │ Matched: debug_error │ │
│ └───────────────────────┬─────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ LAYER 3: COMPONENT ROUTING │ │
│ │ Candidate Agents: │ │
│ │ 1. debugging-specialist (95% match) │ │
│ │ 2. backend-development (82% match) │ │
│ │ 3. senior-architect (71% match) │ │
│ │ │ │
│ │ Selected: debugging-specialist │ │
│ │ Fallback: backend-development │ │
│ └───────────────────────┬─────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ MoE VERIFICATION │ │
│ │ Route through Constitutional Court if: │ │
│ │ • Confidence < 0.8 │ │
│ │ • Multi-intent detected │ │
│ │ • Security-sensitive operation │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘

Intent Taxonomy

Level 1: Coarse Categories

CategoryKeywordsPrimary Track
developmentcode, debug, test, fix, implementA, B
infrastructuredeploy, scale, monitor, configureC
documentationdocument, write, explain, readmeF
securityaudit, secure, vulnerability, complianceD
analysisanalyze, research, compare, evaluateH
managementplan, track, report, statusJ
metahelp, list, configure, settings-

Level 2: Fine-Grained Intents

development:
- code_write: "implement", "create", "add", "build"
- code_review: "review", "check", "audit code"
- code_refactor: "refactor", "clean up", "optimize"
- debug_error: "debug", "fix error", "troubleshoot"
- debug_performance: "slow", "performance", "profile"
- test_write: "write test", "add test", "test coverage"
- test_run: "run tests", "execute tests"
- test_fix: "fix test", "flaky test"

infrastructure:
- deploy: "deploy", "release", "publish"
- scale: "scale", "autoscale", "resize"
- monitor: "monitor", "alert", "dashboard"
- configure: "configure", "setup", "initialize"

Classification Algorithm

from typing import Tuple, List, Dict
from dataclasses import dataclass

@dataclass
class IntentResult:
coarse_category: str
fine_intent: str
confidence: float
candidate_agents: List[Tuple[str, float]]
requires_moe: bool
extracted_entities: Dict[str, str]

def classify_intent(query: str, context: dict) -> IntentResult:
"""
Classify user query into actionable intent.

Uses three-stage classification:
1. Coarse category detection (rule-based + embedding)
2. Fine intent classification (embedding similarity)
3. Component routing (agent matching)
"""

# Stage 1: Coarse classification
coarse_category, coarse_confidence = classify_coarse(query)

# Stage 2: Fine classification
fine_intent, fine_confidence = classify_fine(query, coarse_category)

# Stage 3: Agent routing
candidate_agents = route_to_agents(fine_intent, context)

# Extract entities (file names, error messages, etc.)
entities = extract_entities(query)

# Determine if MoE verification needed
requires_moe = (
fine_confidence < 0.8 or
is_multi_intent(query) or
is_security_sensitive(fine_intent)
)

return IntentResult(
coarse_category=coarse_category,
fine_intent=fine_intent,
confidence=fine_confidence,
candidate_agents=candidate_agents,
requires_moe=requires_moe,
extracted_entities=entities
)

Storage Integration (ADR-118 Compliant)

Intent classification results are stored for learning and analytics:

# Store in sessions.db (Tier 3 - regenerable)
from scripts.core.paths import get_sessions_db_path

def store_intent_classification(result: IntentResult, session_id: str):
"""Store intent classification for analytics and learning."""
conn = sqlite3.connect(get_sessions_db_path())
conn.execute("""
INSERT INTO intent_classifications
(session_id, query, coarse_category, fine_intent,
confidence, selected_agent, timestamp)
VALUES (?, ?, ?, ?, ?, ?, ?)
""", (session_id, query, result.coarse_category,
result.fine_intent, result.confidence,
result.candidate_agents[0][0] if result.candidate_agents else None,
datetime.utcnow().isoformat()))
conn.commit()

Entity Extraction

The system extracts structured entities from queries:

Entity TypePatternExample
file_path/path/to/file, *.py"Fix error in src/auth.py"
error_messageQuoted text, stack trace"Getting 'undefined is not a function'"
task_idX.N.N.N format"Work on task A.3.1.2"
agent_nameKnown agent names"Use senior-architect"
technologyLanguage/framework names"In TypeScript React"

Implementation

Files

FilePurpose
scripts/intent_classifier.pyMain classification logic
config/intent-taxonomy.yamlIntent hierarchy definition
config/agent-intent-mapping.jsonAgent to intent mapping
skills/intent-classification/SKILL.mdSkill for manual classification

Command Integration

# Implicit (via /orient or natural language)
"Help me debug this authentication error"
# → Classifies as: development/debug_error
# → Routes to: debugging-specialist

# Explicit override
/intent classify "deploy the new version"
# → Shows classification details without executing

# Batch classification
/intent analyze session
# → Analyzes all queries in session, shows patterns

Consequences

Positive

  1. Natural Language Interface: Users can express intent naturally
  2. Agent Discovery: System finds best agent without user knowing catalog
  3. Context Awareness: Classification considers project context
  4. Learning: Classification improves over time via feedback

Negative

  1. Latency: Classification adds ~50-100ms per query
  2. Ambiguity: Some queries have multiple valid interpretations
  3. Maintenance: Intent taxonomy needs regular updates

Risks

RiskMitigation
MisclassificationMoE verification for low confidence
Outdated taxonomyQuarterly taxonomy review cycle
Context leakageSession-scoped context only

Author: CODITECT Team Approved: December 15, 2025 Migration: Migrated from cloud-infra per ADR-150 on 2026-02-03