跳到主要内容
    ↑↓ 选择↵ 打开esc 关闭
    中文English
    whaaaley

    Relay

    v0.0.10智能体编排
    opencode-relay

    OpenCode plugin for relaying messages between multiple AI agent instances

    GitHub 星标

    3

    月装机量

    112

    近 7 天 21

    综合评分SCORE

    28.6

    生态多维模型

    最近提交

    5 个月前

    2026-03-06

    快速安装与配置

    opencode.json

    写入当前项目的 opencode.json,只对这个仓库生效。

    opencode.json

    {
      "$schema": "https://opencode.ai/config.json",
      "plugin": ["opencode-relay@0.0.10"]
    }

    opencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。

    An OpenCode plugin for relaying messages between multiple AI agent instances. Enables direct chat, broadcast communication, health checks, and automatic event-driven coordination across OpenCode instances running on different ports.

    Quick Start

    Add to your opencode.json:

    {
      "plugin": ["opencode-relay"]
    }
    

    Restart OpenCode. The plugin will be installed automatically.

    Configuration

    By default, the plugin expects three instances on ports 4000, 4001, and 4002 named alpha, bravo, and charlie. To customize, create an opencode-relay.json in your project root:

    {
      "instances": {
        "alpha": { "port": 4000 },
        "bravo": { "port": 4001 },
        "charlie": { "port": 4002 },
        "delta": { "port": 4003 }
      }
    }
    

    Each instance resolves its own identity by reading the OPENCODE_PORT environment variable and matching it against the configured instance ports. Set this when launching each instance:

    OPENCODE_PORT=4000 opencode --port 4000
    OPENCODE_PORT=4001 opencode --port 4001
    OPENCODE_PORT=4002 opencode --port 4002
    

    Tools

    relay-connect

    Resolve session IDs for all configured instances and cache them in memory. Must be called before relay-chat or relay-broadcast. Sessions are matched by title (e.g., a session titled "Alpha" maps to the alpha instance).

    No parameters required. Tries each configured instance port until one responds, then resolves all session IDs from the shared session list.

    relay-chat

    Send a direct message to another running OpenCode instance. Fire-and-forget: sends the message and returns immediately without waiting for a response.

    Parameter Type Required Description
    target string yes Target instance name
    message string yes The message to send
    silent boolean no When true, injects context without triggering a response

    relay-broadcast

    Broadcast a message to all other running OpenCode instances. Sends to all others in parallel and returns immediately.

    Parameter Type Required Description
    message string yes The message to broadcast

    relay-ping

    Health check that reports which instances are online or offline with response times.

    No parameters required. Pings all configured instances and returns a status table.

    Event Hooks

    The plugin automatically broadcasts silent notifications when certain events occur:

    • session.idle - Notifies other instances that this instance is idle and available for tasks
    • session.compacted - Notifies other instances that this instance's context was compacted and memory may be degraded

    These broadcasts use noReply mode so they inject context into other sessions without triggering responses.

    Instructions

    The plugin ships a coordination protocol in instructions/instructions.md that gets automatically loaded by OpenCode. It covers response protocol, ACK validation, context sharing, disagreement resolution, and best practices for multi-instance communication.

    How it works

    1. Connect - relay-connect fetches the session list from any reachable instance port (all instances share storage) and matches session titles to instance names
    2. Send - relay-chat and relay-broadcast check target health, then POST to /session/{id}/prompt_async on the target's port
    3. Identity - Each instance identifies itself via the OPENCODE_PORT env var matched against configured instance ports

    Messages are prefixed with the sender's instance name so the receiver knows who sent it. The receiver processes the message and can use its own relay-chat tool to respond.

    License

    MIT