360 Secure SkillHub
360 安全技能中心

Agent Shared Context

该 Skill 提供一个 Python 命令行脚本,Agent 在执行任务后把趋势和亮点写入共享 JSON 文件,其他 Agent 在行动前读取这些条目,并通过清理命令删除超过指定时长的旧记录,从而实现基于同一台机器上的文件进行协调。

gum97
gum97
热度 80.32
最近更新 2026-05-11 17:34:36
分类:协作依赖:代码执行 / 读写文件应用场景:工作流 / 自动化脚本

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add agent-shared-context
Metadata
name
agent-relay
version
1.0.0
description
Cross-agent context sharing via shared files. Agents write trends, highlights, and signals to a shared folder. Other agents read before acting — creating coordinated behavior without direct messaging. Use when: multi-agent setups need coordination, agents should know what other agents found, trends from one source should influence another agent's actions. NOT for: real-time communication, agent-to-agent chat, single-agent setups.

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

# Create shared directory in workspace
mkdir -p ~/.openclaw/workspace/shared

# Script location
~/.openclaw/workspace/scripts/shared-context.py

Usage

Agent writes after finishing work:

# Reddit agent logs trending topic
python3 scripts/shared-context.py add-trend \
  --source reddit --topic "self-hosting mini PCs" --score 1500

# News agent logs highlight
python3 scripts/shared-context.py add-highlight \
  --source news --title "Unsloth Studio launched" \
  --summary "Open-source LLM training UI, 2x faster"

Agent reads before acting:

# Moltbook agent checks what's trending before posting
python3 scripts/shared-context.py get-trends --limit 5

# Any agent checks recent highlights
python3 scripts/shared-context.py get-highlights --limit 5

Cleanup (brain-maintenance cron):

# Remove entries older than 48 hours
python3 scripts/shared-context.py cleanup --hours 48

Integration into cron prompts

Add to any agent's cron prompt:

Before posting/engaging, check shared context:
exec('python3 /path/to/scripts/shared-context.py get-trends --limit 3')
→ If a trend is relevant to this platform, create content about it.

After finishing, log what you found:
exec('python3 /path/to/scripts/shared-context.py add-trend --source <agent> --topic "<finding>" --score <relevance>')

Files

File Purpose
shared/trends.json Topics trending across platforms
shared/highlights.json Best content found by any agent
scripts/shared-context.py CLI to read/write shared context

Architecture

Reddit ──write──→ shared/trends.json ←──read── Moltbook
News   ──write──→ shared/highlights.json ←──read── Clawstr
                        ↑
              brain-maintenance (cleanup)

No database. No message queue. Just JSON files on disk. Works because all agents run on the same machine.