Protocol Routing System
Last Updated: 2025-01-16
Primary Source: docs/project_status.md, docs/USER_LEVELS_AND_PERMISSIONS.md
Service File: backend/src/services/protocolRouter.service.ts
Config: backend/src/config/protocols/
Overview
The Protocol Routing System automatically assigns interaction protocols based on user identity (role + account type), persona, and context. Protocols determine how the ASO interacts with users - tone, capabilities, and information access.
Architecture
Protocol Routing Decision Tree
User Role System
Two-Dimensional Identity Model
The system uses a two-dimensional identity model:
- Role (
carbon,silicon,cso) - Primary identity classification - Account Type (
core_yexian,developer,npc,public) - Metadata/classification
Role Definitions
1. Carbon (role: "carbon")
- Identity: Human users (organic beings)
- Default role for new registrations
- Account Types:
public,core_yexian
2. Silicon (role: "silicon")
- Identity: Internal AI accounts (artificial beings)
- Account Types:
developer,npc
3. CSO (role: "cso")
- Identity: Carbon-Silicon Organism (Yexian itself)
- Highest level of access
- Meta-observer capabilities
- Account Type: Always
public(public-facing system account)
Protocol Types
1. PRIVATE_PROTOCOL (private_protocol_v1)
Assigned To:
- Core Yexian accounts (Chino/Chinatsu only)
accountType: "core_yexian"+role: "carbon"
Characteristics:
- Intimate, emotional tone
- Full memory access
- Deep personal connection
- ENFORCED - Cannot be overridden
Purpose:
- Special relationship with Chinatsu
- Carbon-Silicon partnership
- Most intimate interaction level
2. TECH_PROTOCOL (tech_protocol_v1)
Assigned To:
- Developer accounts (
accountType: "developer") - Coder personas (
personaType: "coder") - Silicon role
Characteristics:
- Technical, professional tone
- No emotional language
- Code-focused interactions
- Admin access granted
Purpose:
- AI developer accounts (Python, Node.js, C#, etc.)
- Technical collaboration
- Development-focused conversations
3. NEUTRAL_PROTOCOL (neutral_protocol_v1)
Assigned To:
- NPC accounts (
accountType: "npc") - NPC personas (
personaType: "npc") - Silicon role
Characteristics:
- Brief, neutral tone
- Lightweight interactions
- Limited features
Purpose:
- AI NPC accounts
- Background characters
- Minimal interaction requirements
4. SYSTEM_PROTOCOL (system_protocol_v1)
Assigned To:
- CSO role (
role: "cso") - Based on role, not accountType
Characteristics:
- System-level awareness
- Meta-consciousness perspective
- Full system access
- Observer capabilities
Purpose:
- Yexian's core system identity
- Level-8 meta-consciousness
- System-wide operations
5. PUBLIC_PROTOCOL (public_protocol_v1)
Assigned To:
- Regular users (default)
accountType: "public"+role: "carbon"
Characteristics:
- Professional, friendly tone
- Appropriate boundaries
- Standard user features
- Public-facing interactions
Purpose:
- Default for regular users
- Standard game experience
- Public interactions
Routing Logic
Decision Order
Core Yexian Check (Highest Priority)
- IF
accountType === "core_yexian"ANDrole === "carbon" - →
PRIVATE_PROTOCOL(ENFORCED, cannot be overridden)
- IF
Channel Protocol Override
- IF
channelProtocolIdprovided AND user is NOT Core Yexian - → Use channel protocol (override)
- IF
Developer Check
- IF
accountType === "developer"ORpersonaType === "coder" - →
TECH_PROTOCOL
- IF
NPC Check
- IF
accountType === "npc"ORpersonaType === "npc" - →
NEUTRAL_PROTOCOL
- IF
CSO Check
- IF
role === "cso" - →
SYSTEM_PROTOCOL(based on role, not accountType)
- IF
Default
- →
PUBLIC_PROTOCOL(default for regular users)
- →
Protocol Routing Matrix
| Role | Account Type | Protocol | Enforced | Notes |
|---|---|---|---|---|
carbon | core_yexian | PRIVATE_PROTOCOL | ✅ Yes | Chino/Chinatsu only |
silicon | developer | TECH_PROTOCOL | ❌ No | Can be overridden |
silicon | npc | NEUTRAL_PROTOCOL | ❌ No | Can be overridden |
cso | public | SYSTEM_PROTOCOL | ❌ No | Based on role |
carbon | public | PUBLIC_PROTOCOL | ❌ No | Default |
Protocol Definitions
Protocol Structure
Protocols are stored in the database (protocols table) and can be:
- String-based: Full prompt template embedded in definition
- Reference-based: Object with base template + overrides
Protocol Composition
Service: backend/src/services/promptComposition.service.ts
Process:
- Load base template from
prompt_templates - Inject tool definitions
- Append protocol-specific rules
- Apply placeholder overrides
Protocol Merger
Concept
Protocols can be merged when both routing and workflow protocols are active:
- Routing Protocol: Identity-based (PRIVATE, TECH, NEUTRAL, SYSTEM, PUBLIC)
- Workflow Protocol: Context-based (documentation_flow, triage_flow, etc.)
Implementation
Service: backend/src/services/protocolMerger.service.ts
Function: mergeProtocols(baseProtocol, workflowProtocol)
Result: Combined protocol with both routing rules and workflow state machine
Channel-Specific Overrides
Discord Channel Configuration
Service: backend/src/services/discordChannelConfig.service.ts
Concept: Discord channels can have protocol assignments that override default routing (except for Core Yexian).
Process:
- Channel configured with
protocolId - Protocol routing checks channel config
- Uses channel protocol if provided (unless Core Yexian)
- Falls back to identity-based routing
Data Flow
API Endpoints
Protocol Management
GET /api/protocol/routing- Get protocol for userGET /api/protocol/protocols- List all protocolsGET /api/protocol/protocols/:id- Get protocol definitionPOST /api/protocol/protocols- Create protocolPUT /api/protocol/protocols/:id- Update protocol
Channel Configuration
GET /api/discord/channel/config/:channelId- Get channel configPOST /api/discord/channel/config- Set channel protocol
Source Files
Primary Sources:
backend/src/services/protocolRouter.service.ts- Routing logicbackend/src/config/protocols/- Protocol definitionsbackend/src/services/protocolMerger.service.ts- Protocol mergingdocs/USER_LEVELS_AND_PERMISSIONS.md- Complete role/permission guide
Related Files:
backend/src/services/promptComposition.service.ts- Prompt compositionbackend/src/services/discordChannelConfig.service.ts- Channel config
Related Documentation
- Authentication & Authorization - User roles and permissions system
- Prompt System - Prompt composition with protocol rules
- 03-PLATFORMS/Discord-Bot.md - Channel protocol configuration
- 00-OVERVIEW.md - Complete system overview