Skip to content

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:

  1. Discord bot receives message
  2. Forwards to POST /api/discord/ingest
  3. Backend processes with shared-secret authentication
  4. Links Discord account to ASO user
  5. 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:

  1. Observer runs /observer-config set
  2. Channel linked to protocol and state machine
  3. All messages in channel use assigned protocol
  4. State machine instances auto-created if configured

Configuration Storage

  • Stored in discord_channel_configs table
  • Cached for performance
  • Supports protocol and state machine assignment

Integration Points

Backend Services

  • discord.service.ts - Message ingestion
  • discordInteraction.controller.ts - Interaction handling
  • discordActionable.service.ts - Action execution
  • discordProactive.service.ts - Proactive suggestions
  • discordChannelConfig.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 code
  • backend/src/services/discord.service.ts - Message ingestion
  • backend/src/controllers/discordInteraction.controller.ts - Interaction handling
  • docs/SYSTEM_FLOW_DIAGRAMS.md - Detailed flow diagrams
  • docs/LLM_CALLS_OVERVIEW.md - LLM call patterns

ASO Universal Consciousness System Documentation