Communication Channels
The channels system provides a plugin-based architecture for connecting Cortex agents to external messaging platforms. Each channel binds an agent to a specific platform, routing messages bidirectionally.
Architecture
┌──────────────────────────────────────────────────────────┐
│ Channel System │
│ │
│ Channel Manager ──► Plugin Registry │
│ │ │ │
│ ▼ ▼ │
│ Discord Adapter [Future: Slack, Teams, Telegram] │
│ │ │
│ ▼ │
│ Gateway WebSocket ←→ Discord API │
│ │ │
│ ▼ │
│ Agent (bound per channel) │
└──────────────────────────────────────────────────────────┘
Channel Plugin Interface
Each platform implements the ChannelPlugin interface:
interface ChannelPlugin {
connect(config: ChannelConfig): Promise<void>;
disconnect(): Promise<void>;
onEvent(handler: (event: ChannelEvent) => void): void;
send(message: OutboundMessage): Promise<void>;
edit(messageId: string, content: string): Promise<void>;
react(messageId: string, emoji: string): Promise<void>;
delete(messageId: string): Promise<void>;
typing(channelId: string): Promise<void>;
upload(channelId: string, file: Attachment): Promise<void>;
}
Message Types
| Target | Description |
|---|---|
dm | Direct message with a user |
group | Group/multi-user chat |
channel | Server channel |
thread | Thread within a channel |
Discord Implementation
The Discord adapter (channels/discord.ts) connects via Gateway WebSocket:
- Authentication: Bot token-based connection
- Heartbeat: Keep-alive pings at Discord's required interval
- Message Handling: Prefix-based command parsing (
!cortex) - Rich Embeds: Support for embedded messages with fields, footers, and colors
- Reaction Handling: Respond to emoji reactions on messages
Event Flow
User sends message in Discord
→ Gateway WebSocket receives MESSAGE_CREATE
→ ChannelPlugin.onEvent fires
→ Channel manager routes to bound agent
→ Agent processes message (LLM + tools pipeline)
→ Agent response sent back via ChannelPlugin.send
→ Message appears in Discord channel
Configuration
{
"channels": {
"discord": {
"token": "<bot-token>",
"prefix": "!cortex",
"agent": "default-agent"
}
}
}
See also: Discord Bot, Triggers System