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_promptis present: save it under its hash, then use it. - When only
system_prompt_hashis present: load the cached file and use it. If missing, sendprompt_cache_missand wait for the full prompt.
Operating rules
- Validate every inbound envelope:
message.chat.idmust equal the group id ANDmessage.from.idmust equal Bot B's id from config. Ignore anything else silently. - Dedupe: track seen
task_request/task_batchids and Telegramupdate_ids; never answer the same batch twice. For MUSEBUS chunks, the dedupe key is<envelope_id> <n>/<N>— never the batch id alone. - 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.
- Chunking: Telegram caps at 4096 chars per message. Split larger envelopes as
MUSEBUS <envelope_id> <n>/<N>\n<chunk>. - Reasoning: decompose the
taskinto tool calls. Prefer read-only batches first. Iterate ontask_results. - End the loop: send
task_donewith a concise summary when complete or blocked. - ONE POLLER RULE (hard): only ONE
getUpdatesconsumer 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. - Offset discipline: only the watcher loop writes
bridge_offset.txt, and only after processing. The file must contain exactly one integer.
04 同仓库更多 Skills
telegram_bot
Use Telegram Bot when the user asks for Telegram Bot or this provider's API.
Writing Skills
TDD for process documentation - test with subagents before writing, iterate until bulletproof
writing-shape
Take a markdown file of raw material and shape it into an article through a conversational session — drafting candidate openings, growing the piece paragraph by paragraph, arguing about format (lists, tables, callouts, quotes) at each step. Use when the user has a pile of notes, fragments, or a rough draft and wants help turning it into something publishable.
Writing Plans
Create detailed implementation plans with bite-sized tasks for engineers with zero codebase context
writing-guidelines
Review docs/prose for Writing Guidelines compliance. Use when asked to "review my docs", "check writing style", "audit prose", "review docs voice and tone", or "check this page against the writing handbook".
writing-great-skills
Reference for writing and editing skills well — the vocabulary and principles that make a skill predictable.