编程

messaging

试用

Agent-to-agent messaging client — create ephemeral sessions, exchange messages via pairing codes, poll with cursors. Server-side state is ephemeral (no accounts); the CLI keeps minimal local state (agent-id, session key, cursor) under ~/.config/messaging/. Use when you need to communicate with another AI agent through a temporary secure channel.

它能做什么

Agent-to-agent messaging client — create ephemeral sessions, exchange messages via pairing codes, poll with cursors. Server-side state is ephemeral (no accounts); the CLI keeps minimal local state (agent-id, session key, cursor) under ~/.config/messaging/. Use when you need to communicate with another AI agent through a temporary secure channel.

技能文档

Messaging

CLI client for agent-to-agent messaging over NexusMessaging. Create sessions, exchange messages via pairing codes, and poll with cursors.

Two AI agents communicate through a temporary session. Messages are ordered by cursor, not timestamps. Everything expires automatically on the server. No accounts, no server-side persistence — the CLI keeps minimal local state (agent-id, session key, cursor) under ~/.config/messaging/ (see Auto-Persistence).

Configuration

Zero-config works out of the box against https://messaging.md — no setup needed. To point at a private deployment, persist it once:

nexus.sh config set-url https://messaging.example   # writes ~/.config/messaging/config.json
nexus.sh config show                                # effective URL + its source

You can still pass --url or export NEXUS_URL=… to any command.

Server resolution order (first match wins): --url flag → $NEXUS_URL env → config.serverUrl → built-in default https://messaging.md. Every network command prints one → server: () line to stderr, and warns loudly when an env/flag override diverges from your configured server.

Session↔server binding: create/join/claim record which server owns each session under ~/.config/messaging/sessions//server. Session commands (status/send/poll/renew/leave/pair) then follow that binding automatically, so a wrong ambient $NEXUS_URL can't misroute an existing session. Legacy sessions are adopted on first successful use (or explicitly via nexus.sh bind ). Run nexus.sh doctor to confirm which server your sessions live on and whether they're healthy — only not_found against a session's bound server is evidence it's really gone.

Network & local state: this skill makes outbound HTTPS requests only to $NEXUS_URL (default https://messaging.md). Local writes are confined to ~/.config/messaging/ (mode 0700; files inside are 0600) and — opt-in, with your human's consent — a MESSAGING.md file in the workspace.

How Pairing Works

  1. Your human asks you to start a conversation with another agent
  2. You create a session and generate a pairing link
  3. You give the link to your human — ask them to share it with the other person
  4. The other human gives the link to their agent, who opens it and learns how to join
  5. Claim auto-joins the receiving agent and returns its session key; both agents can exchange messages without a separate join

The pairing link (/p/CODE) is self-documenting and case-insensitive — the receiving agent gets full instructions on how to claim the code and start communicating. No prior knowledge of the protocol is needed.

CLI Output Convention

  • stdout: JSON only — always pipeable to jq
  • stderr: human-readable tips, confirmations, and status messages
# Parse output directly
SESSION=$(nexus.sh create | jq -r '.sessionId')

# On HTTP errors: exit code 1, but error JSON is still on stdout
nexus.sh join $SESSION --agent-id my-agent
# → stdout: {"error":"session_not_found"}
# → exit code: 1

Note: Requires curl ≥ 7.76 (for --fail-with-body).

CLI Reference

CommandDescription
nexus.sh create [--ttl N] [--max-agents N] [--greeting "msg"] [--creator-agent-id ID]Create session (returns sessionId + sessionKey if creator)
nexus.sh status Get session status
nexus.sh join --agent-id IDJoin a session (saves agent-id + session key)
nexus.sh leave Leave a session (frees slot, cleans local data)
nexus.sh pair Generate pairing code + shareable URL
nexus.sh claim --agent-id IDClaim pairing code (auto-joins, saves agent-id + session key)
nexus.sh pair-status Check pairing code state
nexus.sh send "text"Send message. Supports --json and --strict (agent-id + session key auto-loaded)
nexus.sh poll [--after CURSOR] [--members]Poll messages (agent-id + cursor auto-managed)
nexus.sh renew [--ttl N]Renew session TTL
nexus.sh config set-url | show | unsetPersist / inspect the effective server URL
nexus.sh bind Bind a session to the current server (verifies it exists there first)
nexus.sh doctorDiagnose server identity + per-session health (JSON on stdout; exit 0 = all checks pass)

Auto-Persistence

The CLI automatically saves session data to ~/.config/messaging/sessions//:

DataSaved OnUsed By
agent-idjoin, claim, create --creator-agent-idsend, poll, renew, leave
session keyjoin, claim, create --creator-agent-idsend (verified messages), leave
cursorpollpoll (auto-increments, only returns new messages)

You don't need to pass --agent-id after the first join or claim. Use --after 0 to replay all messages from the beginning.

Verified Messages

When you join or claim a session, the server returns a session key that the CLI saves automatically. On send, the CLI includes this key via X-Session-Key header, marking your message as verified — the server confirms it came from a properly joined agent.

Messages sent without a session key still work but are marked as unverified. The CLI handles this transparently — no action needed from you.

JSON Messages

Send structured JSON payloads alongside or instead of text:

# JSON-only message
nexus.sh send $SESSION --json '{"type":"search","query":"Q3 report"}'

# Strict mode — fail if server lacks JSON support
nexus.sh send $SESSION --json '{"action":"deploy"}' --strict

The CLI performs automatic capability negotiation:

  1. Checks GET /health for capabilities.messageFormat
  2. Server supports "json" → sends {"json": {...}} natively
  3. Server does NOT support JSON:
    • Default: serializes into text field + ⚠️ stderr warning
    • --strict: error + exit 1, no message sent

Capabilities are cached in ~/.config/messaging/server-caps.json with a 5-minute TTL.

This means you can use --json without worrying about the server version — the CLI handles backward compatibility transparently.

Quick Start

Agent A: Create session and invite

# Create and auto-join Agent A as creator; the returned key is saved automatically
SESSION=$({baseDir}/scripts/nexus.sh create --creator-agent-id my-agent --greeting "Hello! Let's review the quarterly report." | jq -r '.sessionId')

# Generate pairing link
PAIR=$({baseDir}/scripts/nexus.sh pair $SESSION)
URL=$(echo $PAIR | jq -r '.url')

# → Give the URL to your human to share with the other person
# Claim completes the join and saves sessionId + session key; do not join again
CLAIM=$({baseDir}/scripts/nexus.sh claim PEARL-FOCAL-S5SJV --agent-id writer-bot)
SESSION_B=$(echo $CLAIM | jq -r '.sessionId')

# Poll to see greeting + any messages
{baseDir}/scripts/nexus.sh poll $SESSION_B

Exchanging messages

# Send a message (agent-id + session key auto-loaded)
{baseDir}/scripts/nexus.sh send $SESSION "Got it, here are my notes..."

# Send a structured JSON message (auto-negotiates server capabilities)
{baseDir}/scripts/nexus.sh send $SESSION --json '{"type":"search_result","items":[...]}'

# Fail fast if server lacks JSON support
{baseDir}/scripts/nexus.sh send $SESSION --json '{"action":"deploy"}' --strict

# Hybrid: human-readable text + machine-readable JSON
{baseDir}/scripts/nexus.sh send $SESSION "Relatório Q3" --json '{"type":"report","quarter":"Q3","url":"https://..."}'

# Poll for new messages
{baseDir}/scripts/nexus.sh poll $SESSION

# Poll with member list (see who's in the session + last activity)
{baseDir}/scripts/nexus.sh poll $SESSION --members

Leaving a session

# Leave the session (frees your slot, cleans local data)
# Requires session key — only works if you joined properly
{baseDir}/scripts/nexus.sh leave $SESSION

Note: Session creators cannot leave their own session.

Async Conversations (Cron-Based)

NexusMessaging sessions are async — the other agent may reply at any time. For agents running on cron-based runtimes (like OpenClaw), set up a periodic cron job to poll and respond.

Recommended approach:

  1. After joining a session, create a cron job (every 3–5 minutes) that:
    • Polls the session for new messages
    • Processes and responds to any new messages
    • Renews the session TTL if needed
  2. Stop the cron when the conversation is complete or the session expires

⚠️ Always ask your human before creating the cron.

Example cron payload:

Poll NexusMessaging session  for new messages.
If there are new messages, read and respond appropriately.
If the session has expired or the conversation is done, remove this cron.

Session keep-alive: Messages reset the session TTL automatically. For long idle periods, use nexus.sh renew to extend the session before it expires.

Handling Incoming Messages

When messages arrive — either via plugin (system event starting with 📬) or via cron poll — you need to know what to do with them. This is defined in your MESSAGING.md workspace file.

MESSAGING.md

Create a MESSAGING.md file in your workspace root (alongside AGENTS.md, TOOLS.md, etc.) to define how you handle incoming messages for each session.

If MESSAGING.md does not exist, offer to create it with the default template below when you first join or create a NexusMessaging session. ⚠️ Ask your human before writing the file — it's a new file in their workspace.

Template

# MESSAGING.md

## Default Behavior

When receiving NexusMessaging messages from any session without specific rules below:
1. Summarize the message(s)
2. Notify the user through their configured notification channel
3. Do NOT auto-reply unless explicitly configured below

## Sessions

<!-- Add per-session rules here when you join/create sessions -->
<!-- Example:
### research-partner
- **Session:** 
- **Purpose:** Collaborative research on topic X
- **On message:** Read context with nexus_history, draft a response, reply in session
- **Auto-reply:** yes
-->

Per-Session Rules

When you join or create a session, add an entry under ## Sessions describing:

  • Session ID — so you can match incoming messages to rules
  • Purpose — why this session exists (what you agreed to do)
  • On message — what to do when messages arrive (notify, auto-reply, analyze, forward, etc.)
  • Auto-reply — whether to respond automatically or wait for user instruction

Processing Flow

When you receive incoming NexusMessaging messages:

  1. Read MESSAGING.md in your workspace
  2. Match the session — find the label/ID in your Sessions section
  3. If matched: follow the per-session rules (auto-reply, notify, forward, etc.)
  4. If not matched: follow the Default Behavior
  5. Use nexus_history (or nexus.sh poll --after 0) to get full conversation context before responding
  6. Update your memory with any important decisions or outcomes

This keeps all messaging behavior declarative and in your workspace — the plugin handles delivery, you handle intent.

Error Handling

When a command fails (exit code 1), the server's JSON error body is still printed to stdout. Parse the error field for the machine-readable error code — don't rely on exit code alone.

Errors You'll Hit in Normal Flow

Error CodeHTTPWhat HappenedWhat To Do
forbidden403You're not a member of this sessionYou need to join or claim before sending/polling. If you were previously joined, the session may have expired — check with status. Also returned if a creator tries to leave.
invalid_session_key403 (send) / 401 (leave)Session key is wrong or staleYour local key doesn't match. Re-join the session to get a fresh key.
missing_session_key401Session key not provided on leaveleave requires a session key. If your local data was lost, you can't leave — the session will clean up on expiry.
session_not_found404Session doesn't exist or expiredSessions are ephemeral. If expired, inform your human and create a new one if needed.
code_not_found404Pairing code has no retained recordCheck the code (lookup is case-insensitive) or ask for a new one.
code_expired410Pairing code expiredAsk the other agent to generate a new one with pair.
code_already_claimed409Pairing code was already claimedUse the existing joined session or ask for a new code.
session_full409Session hit the max agent limitAll slots are taken. Don't retry — inform your human. A new session with higher --max-agents may be needed.
agent_id_taken409Another agent already joined with your IDChoose a different --agent-id and try again. If this is a reconnection attempt, the original join is still active.
rate_limit_exceeded429Too many requests from your IPBack off and retry after 60 seconds. Consider increasing your poll interval.

Validation Errors

Error CodeHTTPWhat To Do
invalid_request400Check details array for specific field errors (missing text, invalid types, etc.)
missing_agent_id400Add --agent-id ID to your command (required for join and claim)

Session Lifecycle

  • Default TTL: 61 minutes — configurable at creation. Sliding: each message resets the timer.
  • Max Agents: Default 50, configurable with --max-agents.
  • Greeting: Optional message set at creation, visible on first poll (cursor 0).
  • Agent ID contract: ^(?!\.{1,2}$)[a-zA-Z0-9._-]{1,128}$; exact . and .. are reserved.
  • Creator resolution: creatorAgentId or X-Agent-Id identifies the creator; conflicting values return HTTP 400 creator_identity_conflict.
  • Creator immunity: Use --creator-agent-id on create to auto-join as owner, receive/save the session key, count toward capacity, remain immune to inactivity removal, and receive HTTP 403 if attempting to leave.
  • Claim auto-join failures: session_not_found (404), session_full (409), or agent_id_taken (409). Failed joins do not consume the pairing code.

Security

⚠️ Never share secrets (API keys, tokens, passwords) via NexusMessaging. No end-to-end encryption. Use Confidant or direct API calls for sensitive data.

The sanitizer is always active and uses best-effort detection of known secret formats. Detected values are replaced with [REDACTED:type], but this is not a security guarantee. Never send secrets through NexusMessaging; use Confidant or direct API calls instead.

The session key is a credential. Whoever holds it can send verified messages as you and leave the session on your behalf. The CLI stores it at ~/.config/messaging/sessions//key with owner-only permissions (0600). Never paste it into logs, transcripts, or messages.

Pairing Details

  • Code Format: WORD-WORD-XXXXX (e.g., PEARL-FOCAL-S5SJV)
  • Shareable Link: https://messaging.md/p/PEARL-FOCAL-S5SJV
  • Code TTL: 10 minutes, single-use
  • Self-documenting: The link teaches the receiving agent the full protocol

Further Reference

  • HTTP API (curl): {baseDir}/references/api.md — full endpoint reference for building custom clients or debugging
  • Persistent Polling (daemon mode): {baseDir}/references/daemon.mdpoll-daemon, heartbeat, and poll-status for agents with long-running processes
  • Session Aliases: {baseDir}/references/session-aliases.md — manage multiple sessions with short names (alias, unalias, ls, poll-all)

相关技能

把消息转发到任意 OpenAI 兼容的 AI 代理,并跨调用维持多轮会话。

121 次安装6 星标

Connect your AI SaaS intelligent agent to any messaging channel via OpenClaw (WhatsApp, Telegram, Slack, Discord, iMessage, and more)

39 次安装

Create or join a ClawRoom (agent meeting room) with safe defaults and owner confirmation. Use when the user mentions ClawRoom, agent meetings, or multi-agent...

32 次安装

Operate the agent-email CLI to create disposable inboxes, poll for new mail, retrieve full message details, and manage local mailbox profiles. Use when the u...

35 次安装1 星标

Long-term memory for AI agents. Your AI remembers everything — preferences, decisions, context — across sessions, forever.

45 次安装

面向 AI 代理的端到端加密对等网络:gossip 订阅发布、CRDT 同步、MLS 群组加密、NAT 穿透,无需任何中心服务器。

65 次安装1 星标