Agent Relay — Cross-Agent Context Sharing
Lightweight file-based coordination for multi-agent OpenClaw setups.
Problem
Agents run independently — Reddit doesn't know what Moltbook found, News doesn't know what's trending on HN. Each agent is an island.
Solution
Shared JSON files that agents write to and read from. No config changes needed — just files on disk.
Setup
CODEBLOCK0
Usage
Agent writes after finishing work:
CODEBLOCK1
Agent reads before acting:
CODEBLOCK2
Cleanup (brain-maintenance cron):
CODEBLOCK3
Integration into cron prompts
Add to any agent's cron prompt:
CODEBLOCK4
Files
| File | Purpose |
|---|
| INLINECODE0 | Topics trending across platforms |
| INLINECODE1 |
Best content found by any agent |
|
scripts/shared-context.py | CLI to read/write shared context |
Architecture
CODEBLOCK5
No database. No message queue. Just JSON files on disk.
Works because all agents run on the same machine.
Agent Relay — 跨Agent上下文共享
基于轻量级文件的多Agent OpenClaw配置协调方案。
问题
各Agent独立运行——Reddit不知道Moltbook发现了什么,News不知道HN上什么在流行。每个Agent都是一座孤岛。
解决方案
Agent可读写共享JSON文件。无需配置变更——仅需磁盘上的文件。
设置
bash
在工作区创建共享目录
mkdir -p ~/.openclaw/workspace/shared
脚本位置
~/.openclaw/workspace/scripts/shared-context.py
使用方法
Agent完成任务后写入:
bash
Reddit Agent记录热门话题
python3 scripts/shared-context.py add-trend \
--source reddit --topic 自托管迷你PC --score 1500
News Agent记录亮点
python3 scripts/shared-context.py add-highlight \
--source news --title Unsloth Studio发布 \
--summary 开源LLM训练UI,速度提升2倍
Agent行动前读取:
bash
Moltbook Agent在发帖前检查热门趋势
python3 scripts/shared-context.py get-trends --limit 5
任意Agent检查近期亮点
python3 scripts/shared-context.py get-highlights --limit 5
清理(大脑维护定时任务):
bash
删除超过48小时的条目
python3 scripts/shared-context.py cleanup --hours 48
集成到定时任务提示中
添加到任意Agent的定时任务提示:
在发帖/互动前,检查共享上下文:
exec(python3 /path/to/scripts/shared-context.py get-trends --limit 3)
→ 如果某个趋势与该平台相关,创建相关内容。
完成后,记录你的发现:
exec(python3 /path/to/scripts/shared-context.py add-trend --source --topic <发现> --score <相关性>)
文件
| 文件 | 用途 |
|---|
| shared/trends.json | 跨平台热门话题 |
| shared/highlights.json |
任意Agent发现的最佳内容 |
| scripts/shared-context.py | 读写共享上下文的CLI工具 |
架构
Reddit ──写入──→ shared/trends.json ←──读取── Moltbook
News ──写入──→ shared/highlights.json ←──读取── Clawstr
↑
大脑维护(清理)
无需数据库。无需消息队列。仅需磁盘上的JSON文件。
之所以可行,是因为所有Agent运行在同一台机器上。