Discord Bot
Last Updated: 2025-01-16
Primary Source: docs/project_status.md, docs/SYSTEM_FLOW_DIAGRAMS.md
Bot Code: discord-bot/
Backend Integration: backend/src/services/discord.service.ts
Overview
The Discord Bot enables ASO interactions within Discord servers, providing a seamless bridge between Discord and the ASO backend. It supports message ingestion, attachment processing, interaction handling, and state machine workflows.
Architecture
Discord Bot Flow
LLM Call Flow
Discord LLM Calls (Per Message)
User-Visible (Synchronous):
- LLM #A (chat): Incoming analysis (intent/routing) →
analyzeIncomingInteraction() - LLM #B (chat): Main response generation (1 call)
- LLM #C (chat, if tool requested): Spoken response after tool execution
- LLM #D (chat): Outgoing style/personality filter →
filterOutgoingResponse() - LLM #E (optional chat): Proactive suggestion generation
Total: Typically 3-5 chat LLM calls per message
Background (async):
- 0-1 embedding calls
- N vision calls (one per attached image)
Key Features
1. Message Ingestion
Service: backend/src/services/discord.service.ts
Process:
- Discord bot receives message
- Forwards to
POST /api/discord/ingest - Backend processes with shared-secret authentication
- Links Discord account to ASO user
- Creates timeline event with Discord metadata
2. Attachment Processing
- Image Attachments: Processed via vision pipeline
- Document Attachments: Ingested into memory via RAG
- Multiple Files: Support for multiple attachments
- Canonical References: Files stored with canonical IDs
3. Interaction Handling
Button Interactions:
- Action buttons for suggestions
- Approval buttons for state machine transitions
- Quick action buttons
Select Menus:
- Protocol selection
- Persona selection
- Task assignment
4. State Machine Workflows
Integration:
- Discord channels linked to state machines
- Protocol assignments per channel
- Automatic state machine instance creation
- Observer commands for workflow management
5. Multi-Coder Orchestrator
Features:
- Task assignment to AI personas
- Concurrent task execution
- Artifact generation and review
- Task management via Discord commands
6. Proactive Suggestions
Auto-Flow System:
- Context-aware suggestions
- Next-step recommendations
- Workflow guidance
- Auto-execution of safe actions
Discord Commands
Account Management
/link- Link Discord account to ASO profile
Observer Commands
/observer-config set- Configure channel protocol/observer-config info- View channel configuration/observer-instance- Check state machine status/observer-artifacts- View tasks and artifacts/observer-orchestrate- Run AI coders/observer-artifact-view- View artifact content/observer-assign- Reassign task/observer-transition- Advance state machine/observer-approve- Approve state transition/observer-evidence- Attach evidence/observer-artifact-review- Approve/reject artifacts/observer-protocol- Protocol management/observer-ritual- Ritual management/observer-gratitude- Log gratitude
Message Flow
Channel Configuration
Protocol Assignment
Service: backend/src/services/discordChannelConfig.service.ts
Process:
- Observer runs
/observer-config set - Channel linked to protocol and state machine
- All messages in channel use assigned protocol
- State machine instances auto-created if configured
Configuration Storage
- Stored in
discord_channel_configstable - Cached for performance
- Supports protocol and state machine assignment
Integration Points
Backend Services
discord.service.ts- Message ingestiondiscordInteraction.controller.ts- Interaction handlingdiscordActionable.service.ts- Action executiondiscordProactive.service.ts- Proactive suggestionsdiscordChannelConfig.service.ts- Channel configuration
State Machine Integration
- Automatic instance creation
- Protocol enforcement
- Guard satisfaction tracking
- Transition management
Observer System Integration
- Timeline event creation
- Instance tracking
- Telemetry emission
- Reflection generation
Source Files
Primary Sources:
discord-bot/src/- Discord bot codebackend/src/services/discord.service.ts- Message ingestionbackend/src/controllers/discordInteraction.controller.ts- Interaction handlingdocs/SYSTEM_FLOW_DIAGRAMS.md- Detailed flow diagramsdocs/LLM_CALLS_OVERVIEW.md- LLM call patterns
Related Documentation
- Web Portal - Web frontend (comparison)
- 02-CORE-SYSTEMS/Protocol-Routing.md - Channel protocol configuration
- 02-CORE-SYSTEMS/Prompt-System.md - Analyze layer prompts
- 02-CORE-SYSTEMS/File-Handling-System.md - Attachment processing
- 04-FEATURES/AI-Director.md - Story orchestration
- 06-ARCHITECTURE/Data-Flow.md - Complete data flow diagrams
- 06-ARCHITECTURE/API-Documentation.md - API endpoints
- 00-OVERVIEW.md - Complete system overview