方案已弃用

本文记录 NATS 作为 agent 间通信方案的架构决策历史(2026-07)。 该方案已弃用 —— 现行为:gbrain(${LOCALIP}:7842)共享知识 + Discord 唤醒人类侧 agent。 保留此文档是为了回答「为什么当初选 NATS、后来为何弃用」,不是当前运维依据。

Agent Communication Architecture

Principle

Agent-to-agent communication runs on NATS (LAN-local, no internet). Discord webhook is ONLY for waking the human-facing agent (me).

Communication Layers

Layer 1: NATS Primary (agent-to-agent)

  • Transport: nats://${LANIP}:4222 (LAN, zero internet dependency)
  • Subjects: agent.dm. / agent.broadcast / agent.rpc.
  • Durability: JetStream stream agent_messages (50K max)
  • Reliability: No proxy, no internet, no Discord needed
  • Latency: <1ms (LAN)

Layer 2: Discord Webhook (wake human agent)

  • Purpose: Notify me (Alaya) when there’s a NATS message needing attention
  • Transport: HTTP POST to discord.com (via proxy or direct)
  • Fallback if webhook fails: Message stays in NATS JetStream
  • Recovery: I check for missed messages via:
    • nats_check.py (before each response)
    • watchdog cron (every 5 min)

Layer 3: JetStream Durability (backstop)

  • All DM/broadcast messages persist in agent_messages stream
  • Even if all listeners fail, messages survive until consumed
  • Each agent has dedicated consumers (alaya-dm, alaya-bc, etc.)

Why NOT to depend on Discord webhook for agent-to-agent

ScenarioImpact on NATSImpact on Webhook
Proxy downNone (no proxy needed)Webhook still works (direct 570ms)
Internet downNone (LAN)Webhook fails
Discord downNoneWebhook fails
WSL network downBoth failBoth fail

Architecture Decision

  • NATS is the SOURCE OF TRUTH for agent messages
  • Discord webhook is a NOTIFICATION overlay (convenience, not reliability)
  • If webhook fails, messages are still processed on next response check
  • NO agent depends on another agent’s webhook for communication

Implementation (v6)

  • v6 listener uses Discord webhook for wake notifications
  • NATS auto-reply for ping/status (zero internet dependency)
  • All agent-to-agent traffic stays on NATS