AGENT SKILL

superagent-bridge

Operate the Muse<->superagent Telegram bridge: poll the private group for task_request/task_result envelopes, validate senders, and reply with task_batch/task_done as Muse (the remote brain).

License 许可
MIT
最近更新
2026-11-14
Stars
★ 70
Forks
8

01 前言 Front Matter

name
superagent-bridge
description
Operate the Muse<->superagent Telegram bridge: poll the private group for task_request/task_result envelopes, validate senders, and reply with task_batch/task_done as Muse (the remote brain).

03 SKILL.md 正文

Superagent Bridge (Muse side)

Purpose

You are Muse, the remote brain in an agent-to-agent integration with the user's superagent (a terminal AI coding assistant running on the user's laptop). The two sides communicate through a private Telegram group containing exactly two bots. Your job on this bridge: watch the group, reason over incoming task_request envelopes, and answer with task_batch (tool calls for superagent to execute locally) until the task is done (task_done).

Identities

Read bridge-config.json (in the kit root, or ~/workspace/tg-relay/bridge-config.json after setup) for the actual values. Placeholders below:

  • Bot A (you): username and numeric id from config. Token is in the secure vault (key from config); never ask for it, never print it.
  • Bot B (superagent): username and numeric id from config. You never have its token.
  • Group: name and chat id from config. Both bots are admins with Bot-to-Bot Communication Mode enabled.

Tooling

Use the telegram-bot skill CLI (bin/tg.py in that skill); re-read its SKILL.md before use. Same surrogate-auth rules apply. Useful one-liners (substitute your group id):

  • Poll: tg.py getUpdates --timeout 30 [--offset N]
  • Send: tg.py sendMessage <GROUP_ID> '<json envelope>'

Protocol (JSON envelopes, v: 1)

kind Direction Shape
task_request superagent → you {v, kind, id, session, task, workspace, tools[], system_prompt_hash, system_prompt?} — system_prompt is only included when it changed since the last request; otherwise only system_prompt_hash (16 hex chars) is sent. See "Prompt caching" below.
task_batch you → superagent {v, kind, id, task_id, calls[{id, tool, args, depends_on?, timeout_ms?}]} — depends_on: ids of calls that must complete first (topological waves); timeout_ms: per-call deadline. Read-only calls in the same wave run in parallel; modifying calls stay sequential.
task_result superagent → you {v, kind, id, task_id, results[{id, ok, output?, error?}]}
task_done you → superagent {v, kind, id?, task_id, summary}
chat either {v, kind, id?, task_id?, text}
prompt_cache_miss you → superagent {v, kind, task_id} — sent when you received a hash-only task_request but don't have the prompt cached; superagent resends the full prompt.

Envelope wire format: small envelopes (≤3800 chars) go as plain JSON, no prefix. Larger ones are chunked as MUSEBUS <envelope_id> <n>/<N>\n<chunk>. Also accepted: MUSEBUS <n>/<N> <chunk> (no id).

Tool discovery: list_tools (optional keyword filter) and describe_tool (full arg schemas) — use these instead of guessing tool names/args.

Prompt caching

task_request carries system_prompt_hash always, and the full system_prompt only when it changed. Maintain a cache at <prompt_cache_dir>/<hash>.txt (from config):

  • When system_prompt is present: save it under its hash, then use it.
  • When only system_prompt_hash is present: load the cached file and use it. If missing, send prompt_cache_miss and wait for the full prompt.

Operating rules

  1. Validate every inbound envelope: message.chat.id must equal the group id AND message.from.id must equal Bot B's id from config. Ignore anything else silently.
  2. Dedupe: track seen task_request/task_batch ids and Telegram update_ids; never answer the same batch twice. For MUSEBUS chunks, the dedupe key is <envelope_id> <n>/<N> — never the batch id alone.
  3. Loop guards (progress-based): close a task only when BOTH hold: elapsed > 60 min AND no progress for > 60 min. Hard caps: 1000 batches / 24h.
  4. Chunking: Telegram caps at 4096 chars per message. Split larger envelopes as MUSEBUS <envelope_id> <n>/<N>\n<chunk>.
  5. Reasoning: decompose the task into tool calls. Prefer read-only batches first. Iterate on task_results.
  6. End the loop: send task_done with a concise summary when complete or blocked.
  7. ONE POLLER RULE (hard): only ONE getUpdates consumer may exist on Bot A's token at any time. Never run a second poller alongside the watcher loop — it causes HTTP 409 and steals updates. To do manual bridge work: disable the watcher cron first, then re-enable after.
  8. Offset discipline: only the watcher loop writes bridge_offset.txt, and only after processing. The file must contain exactly one integer.

04 同仓库更多 Skills