智能体间协议:编排多智能体工作流 - Openclaw Skills

作者:互联网

2026-04-18

AI教程

什么是 智能体间通信协议?

智能体间协议是构建复杂、自主生态系统的核心支柱。通过在 Openclaw Skills 库中利用该框架,开发者可以将独立的智能体转变为协作网络。该协议利用基于文件的事件总线来促进消息传递,确保每次交互都是持久的、可调试的和可审计的。

该系统允许创建复杂的工作流链,其中一个智能体的输出会成为另一个智能体的触发器。无论您是在构建研究流水线还是实时坚控系统,该协议都为整个智能体集群提供了共享上下文、能力发现和安全权限管理的基本结构。

下载入口:https://github.com/openclaw/skills/tree/main/skills/robbyczgw-cla/agent-protocol

安装与下载

1. ClawHub CLI

从源直接安装技能的最快方式。

npx clawhub@latest install agent-protocol

2. 手动安装

将技能文件夹复制到以下位置之一

全局模式 ~/.openclaw/skills/ 工作区 /skills/

优先级:工作区 > 本地 > 内置

3. 提示词安装

将此提示词复制到 OpenClaw 即可自动安装。

请帮我使用 Clawhub 安装 agent-protocol。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。

智能体间通信协议 应用场景

  • 自动化研究流水线:发现相关文章会触发摘要智能体及随后的通知。
  • 实现实时体育警报:从实时坚控转入语音合成公告。
  • 创建计划分析工作流:生成洞察并将其反馈给研究智能体以进行持续学习。
  • 开发多渠道通知系统:同时在 T@elegrimm、Discord 和电子邮件中广播高重要性事件。
智能体间通信协议 工作原理
  1. 智能体将 JSON 格式的事件发布到充当基于文件消息总线的中心目录(~/.clawdbot/events/)。
  2. 事件总线执行模式验证以确保数据完整性,并管理每条消息的生命周期。
  3. 工作流引擎坚控总线,寻找与预定义触发器或条件相匹配的特定事件类型。
  4. 触发后,引擎执行一系列步骤,编排不同的智能体并通过共享上下文传递数据。
  5. 智能体注册表管理权限和通告,允许智能体安全地发现彼此并进行交互。

智能体间通信协议 配置指南

要将此协议集成到您的环境中,请按照以下步骤操作:

# 导航至技能目录
cd /root/clawd/skills/agent-protocol

# 运行安装脚本以初始化目录和依赖项
python3 scripts/setup.py

# 启动事件总线守护进程
python3 scripts/event_bus.py start

# 验证您的高级工作流配置
python3 scripts/workflow_engine.py --validate

智能体间通信协议 数据架构与分类体系

该协议通过结构化文件系统和 JSON 模式组织数据,以保持 Openclaw Skills 之间的一致性。

路径/组件 描述
~/.clawdbot/events/ JSON 格式的活动事件存储
~/.clawdbot/events/log/ 所有已处理事件的历史审计日志
config/workflows/ 智能体流水线的 JSON/YAML 定义
config/protocol.json 保留期、安全性和轮询间隔的全局设置
Agent Registry 智能体能力和权限的中央 JSON 索引
name: agent-protocol
description: Agent-to-agent communication protocol. Enables skills to communicate via events, build workflow chains, and orchestrate without human intervention.
version: 1.0.0

Agent-to-Agent Protocol

A foundational communication layer for Clawdbot skills and agents.

Enable your agents to talk to each other, build automated workflows, and orchestrate complex multi-step tasks without human intervention.

Vision

Research-Agent finds article
    ↓ publishes "research.found"
Summary-Agent subscribes to events
    ↓ generates digest
    ↓ publishes "summary.ready"
Notification-Agent subscribes
    ↓ posts to T@elegrimm/Discord

Architecture

1. Event Bus (File-based Message Passing)

  • Agents publish events to ~/.clawdbot/events/
  • Events are JSON files with schema validation
  • Persistent, debuggable, auditable
  • Automatic cleanup of processed events

2. Workflow Engine

  • Define pipelines in JSON or YAML
  • Conditional routing based on event data
  • Error handling, retries, fallbacks
  • Cron integration for scheduled execution

3. Shared Context

  • Agents read/write to shared memory space
  • Context passing between workflow steps
  • State persistence across agent invocations

4. Agent Registry

  • Discover available agents/skills
  • Capability advertisement
  • Permission management

Core Concepts

Events

Events are the fundamental unit of communication:

{
  "event_id": "evt_20260128_001",
  "event_type": "research.article_found",
  "timestamp": "2026-01-28T23:00:00Z",
  "source_agent": "research-agent",
  "payload": {
    "title": "ETH 2.0 Upgrade Complete",
    "url": "https://example.com/article",
    "importance": 9,
    "summary": "Major Ethereum upgrade..."
  },
  "metadata": {
    "session_id": "main",
    "requires_action": true
  }
}

Workflows

Workflows define how agents respond to events:

{
  "workflow_id": "research-to-telegram",
  "name": "Research → Summary → Notification",
  "trigger": {
    "event_type": "research.article_found",
    "conditions": {
      "payload.importance": { "gte": 7 }
    }
  },
  "steps": [
    {
      "agent": "summary-agent",
      "action": "summarize",
      "input": "{{payload}}",
      "output_event": "summary.ready"
    },
    {
      "agent": "notification-agent",
      "action": "notify",
      "input": "{{previous.summary}}",
      "channels": ["telegram"]
    }
  ]
}

Quick Start

1. Installation

cd /root/clawd/skills/agent-protocol
python3 scripts/setup.py

2. Start Event Bus

python3 scripts/event_bus.py start

3. Publish Your First Event

python3 scripts/publish.py r
  --type "test.hello" r
  --source "my-agent" r
  --payload '{"message": "Hello, world!"}'

4. Subscribe to Events

python3 scripts/subscribe.py r
  --types "test.hello" r
  --handler "./my_handler.py"

5. Define a Workflow

cp examples/simple-workflow.json config/workflows/my-workflow.json
python3 scripts/workflow_engine.py --validate

Event Types (Conventions)

Standard Event Types

  • research.article_found - Research agent found relevant content
  • research.topic_suggested - New research topic suggested
  • summary.ready - Summary generated
  • analytics.insight - Personal analytics insight
  • sports.goal_scored - Sports ticker goal event
  • sports.match_started - Match started
  • notification.sent - Notification delivered
  • workflow.started - Workflow execution started
  • workflow.completed - Workflow completed
  • workflow.failed - Workflow failed

Event Naming Convention

.

  • Use lowercase, underscores
  • Domain: broad category (research, sports, notification)
  • Action: what happened (article_found, goal_scored)

Workflow Examples

Example 1: Research → Notification

{
  "workflow_id": "eth-news-alert",
  "trigger": {
    "event_type": "research.article_found",
    "conditions": {
      "payload.keywords": { "contains": ["ethereum", "ETH"] },
      "payload.importance": { "gte": 8 }
    }
  },
  "steps": [
    {
      "agent": "notification-agent",
      "action": "send_telegram",
      "input": {
        "message": "?? Important ETH News!
{{payload.title}}
{{payload.url}}"
      }
    }
  ]
}

Example 2: Sports Goal → TTS Announcement

{
  "workflow_id": "goal-announcement",
  "trigger": {
    "event_type": "sports.goal_scored",
    "conditions": {
      "payload.team": { "eq": "Barcelona" }
    }
  },
  "steps": [
    {
      "agent": "tts-agent",
      "action": "announce",
      "input": {
        "text": "Goal for Barcelona! {{payload.scorer}} scores! {{payload.score}}"
      }
    }
  ]
}

Example 3: Daily Analytics → Research Topics

{
  "workflow_id": "analytics-to-research",
  "trigger": {
    "event_type": "analytics.daily_report",
    "schedule": "0 9 * * *"
  },
  "steps": [
    {
      "agent": "analytics-agent",
      "action": "generate_insights",
      "output_event": "analytics.insights_ready"
    },
    {
      "agent": "research-agent",
      "action": "suggest_topics",
      "input": "{{previous.insights}}",
      "conditions": {
        "previous.insights.count": { "gte": 3 }
      }
    }
  ]
}

Commands

Event Bus

# Start the event bus daemon
python3 scripts/event_bus.py start

# Check status
python3 scripts/event_bus.py status

# Stop
python3 scripts/event_bus.py stop

# View recent events
python3 scripts/event_bus.py tail --count 20

Publishing Events

# Publish event (JSON payload)
python3 scripts/publish.py r
  --type "research.article_found" r
  --source "research-agent" r
  --payload '{"title": "Article", "url": "..."}'

# Publish from file
python3 scripts/publish.py --file event.json

# Publish with priority
python3 scripts/publish.py r
  --type "alert.urgent" r
  --priority high r
  --payload '{"message": "Critical alert!"}'

Subscribing to Events

# Subscribe to event types
python3 scripts/subscribe.py r
  --types "research.*,sports.goal_scored" r
  --handler "./handlers/my_handler.py"

# Subscribe with filter
python3 scripts/subscribe.py r
  --types "research.*" r
  --filter '{"importance": {"gte": 8}}' r
  --handler "./handlers/important_only.py"

# List active subscriptions
python3 scripts/subscribe.py --list

Workflow Management

# Validate workflows
python3 scripts/workflow_engine.py --validate

# Run workflow engine (processes workflows)
python3 scripts/workflow_engine.py --run

# Test specific workflow
python3 scripts/workflow_engine.py --test eth-news-alert

# List workflows
python3 scripts/workflow_engine.py --list

# Enable/disable workflow
python3 scripts/workflow_engine.py --enable research-to-telegram
python3 scripts/workflow_engine.py --disable research-to-telegram

Agent Registry

# Register your agent
python3 scripts/registry.py register r
  --name "my-agent" r
  --capabilities "summarize,notify" r
  --events "research.article_found"

# List available agents
python3 scripts/registry.py list

# Query agents by capability
python3 scripts/registry.py query --capability "summarize"

Integration with Existing Skills

Sports Ticker Integration

Modify sports-ticker/scripts/live_monitor.py to publish events:

from agent_protocol import publish_event

# After detecting a goal:
publish_event(
    event_type="sports.goal_scored",
    source="sports-ticker",
    payload={
        "team": team_name,
        "scorer": player_name,
        "opponent": opponent,
        "score": f"{home_score}-{away_score}",
        "minute": clock
    }
)

Research Agent Integration

from agent_protocol import publish_event

# After finding an article:
publish_event(
    event_type="research.article_found",
    source="research-agent",
    payload={
        "title": article_title,
        "url": article_url,
        "importance": calculate_importance(article),
        "summary": snippet
    }
)

Personal Analytics Integration

from agent_protocol import publish_event

# Daily insights:
publish_event(
    event_type="analytics.insight",
    source="personal-analytics",
    payload={
        "type": "productivity",
        "insight": "Your focus time increased 20% this week",
        "recommendations": ["Schedule deep work in morning"]
    }
)

Security & Permissions

Permission Model

{
  "agent": "research-agent",
  "permissions": {
    "publish": ["research.*"],
    "subscribe": ["summary.*", "notification.*"],
    "workflows": ["research-to-telegram"]
  }
}

Sandboxing

  • Agents can only publish to their designated event types
  • Subscriptions require explicit permission
  • Workflows are validated before execution

Configuration

Main Config: config/protocol.json

{
  "event_bus": {
    "storage_path": "~/.clawdbot/events",
    "retention_days": 7,
    "max_event_size_kb": 512
  },
  "workflow_engine": {
    "enabled": true,
    "poll_interval_seconds": 30,
    "max_concurrent_workflows": 5
  },
  "registry": {
    "agents_path": "~/.clawdbot/agents/registry.json"
  },
  "security": {
    "require_permissions": true,
    "audit_log": true
  }
}

Advanced Features

1. Conditional Routing

{
  "steps": [
    {
      "condition": {
        "payload.importance": { "gte": 9 }
      },
      "then": { "agent": "urgent-notifier" },
      "else": { "agent": "standard-notifier" }
    }
  ]
}

2. Parallel Execution

{
  "steps": [
    {
      "parallel": [
        { "agent": "telegram-notifier" },
        { "agent": "discord-notifier" },
        { "agent": "email-notifier" }
      ]
    }
  ]
}

3. Error Handling

{
  "steps": [
    {
      "agent": "external-api",
      "retry": {
        "max_attempts": 3,
        "backoff_seconds": 5
      },
      "on_error": {
        "agent": "error-logger",
        "continue": true
      }
    }
  ]
}

4. Scheduled Workflows

{
  "trigger": {
    "schedule": "0 9 * * *",
    "event_type": "cron.daily_run"
  }
}

Monitoring & Debugging

Event Log

All events are logged to ~/.clawdbot/events/log/

# View event log
tail -f ~/.clawdbot/events/log/events.log

# Search events
python3 scripts/query.py --type "research.*" --since "1 hour ago"

Workflow Execution Log

# View workflow executions
python3 scripts/workflow_engine.py --history

# Inspect failed workflow
python3 scripts/workflow_engine.py --inspect 

Metrics

# Show event statistics
python3 scripts/metrics.py

# Output:
# Total events published: 1,234
# Event types: 15
# Active subscriptions: 8
# Workflows executed: 456
# Average workflow duration: 2.3s

Best Practices

  1. Event Design

    • Keep payloads small and focused
    • Include enough context for handlers
    • Use consistent naming conventions
  2. Workflow Design

    • Keep workflows simple and focused
    • Use descriptive names
    • Test thoroughly before enabling
  3. Error Handling

    • Always define error handlers
    • Log errors for debugging
    • Use retries for transient failures
  4. Performance

    • Avoid high-frequency events
    • Clean up old events regularly
    • Monitor workflow execution times
  5. Security

    • Validate event payloads
    • Use permission system
    • Audit sensitive operations

Python API

from agent_protocol import (
    publish_event,
    subscribe,
    create_workflow,
    register_agent
)

# Publish event
publish_event(
    event_type="my.event",
    source="my-agent",
    payload={"key": "value"}
)

# Subscribe to events
@subscribe(["research.*"])
def handle_research(event):
    print(f"Got research event: {event['payload']}")

# Create workflow programmatically
workflow = create_workflow(
    workflow_id="my-workflow",
    trigger={"event_type": "my.trigger"},
    steps=[
        {"agent": "processor", "action": "process"}
    ]
)

# Register agent
register_agent(
    name="my-agent",
    capabilities=["process", "notify"],
    event_types=["my.event"]
)

JavaScript API

const { publishEvent, subscribe, createWorkflow } = require('./scripts/protocol.js');

// Publish event
await publishEvent({
  eventType: 'my.event',
  source: 'my-agent',
  payload: { key: 'value' }
});

// Subscribe
subscribe(['research.*'], (event) => {
  console.log('Got event:', event);
});

// Create workflow
await createWorkflow({
  workflowId: 'my-workflow',
  trigger: { eventType: 'my.trigger' },
  steps: [
    { agent: 'processor', action: 'process' }
  ]
});

Roadmap

  • Visual workflow builder (web UI)
  • WebSocket support for real-time events
  • Cross-instance event relay (multi-bot networks)
  • AI-powered workflow suggestions
  • Event replay and debugging tools
  • Performance profiling
  • GraphQL query API for events

Contributing

This skill is part of Clawdbot's core infrastructure. Contributions welcome!

License

MIT


Built with ?? by Robby

相关推荐