← Back to Plugins
Voice

A2a Client

supperdsj By supperdsj 👁 3 views ▲ 0 votes

OpenClaw A2A Client Plugin - Call external A2A (Agent-to-Agent) protocol agents from OpenClaw

GitHub

Install

openclaw plugins install openclaw-a2a-client

Configuration Example

{
  "plugins": {
    "a2a-client": {
      "peers": [
        {
          "name": "weather-agent",
          "url": "https://weather-agent.example.com",
          "auth": {
            "type": "bearer",
            "tokenEnv": "WEATHER_AGENT_TOKEN"
          },
          "description": "查询天气的 A2A 代理"
        },
        {
          "name": "search-agent",
          "url": "https://search.example.com",
          "auth": {
            "type": "bearer",
            "token": "sk-direct-token-here"
          }
        }
      ],
      "timeoutMs": 30000
    }
  }
}

README

# openclaw-a2a-client

OpenClaw 插件:从 OpenClaw 代理调用外部 [A2A (Agent-to-Agent)](https://github.com/google/A2A) 协议代理。

## 功能

- **a2a_discover** — 通过 `/.well-known/agent.json` 发现远程 A2A 代理的能力
- **a2a_call** — 向配置的 A2A 代理发送消息并获取结果
- 支持 Bearer Token 认证(环境变量或直接配置)
- 支持多轮对话(通过 contextId/taskId)
- 可配置超时时间
- 零外部依赖,使用原生 `fetch`

## 安装

```bash
openclaw plugins install openclaw-a2a-client
```

## 配置

在 OpenClaw 配置中添加插件配置:

```json
{
  "plugins": {
    "a2a-client": {
      "peers": [
        {
          "name": "weather-agent",
          "url": "https://weather-agent.example.com",
          "auth": {
            "type": "bearer",
            "tokenEnv": "WEATHER_AGENT_TOKEN"
          },
          "description": "查询天气的 A2A 代理"
        },
        {
          "name": "search-agent",
          "url": "https://search.example.com",
          "auth": {
            "type": "bearer",
            "token": "sk-direct-token-here"
          }
        }
      ],
      "timeoutMs": 30000
    }
  }
}
```

### 配置项

| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| `peers` | array | 否 | 已知的 A2A 代理列表 |
| `peers[].name` | string | 是 | 代理唯一名称(用于 `a2a_call` 的 `agent` 参数) |
| `peers[].url` | string | 是 | A2A 代理的基础 URL |
| `peers[].auth.type` | string | 否 | 认证类型,目前仅支持 `"bearer"` |
| `peers[].auth.token` | string | 否 | 直接指定 Bearer Token |
| `peers[].auth.tokenEnv` | string | 否 | 包含 Bearer Token 的环境变量名 |
| `peers[].description` | string | 否 | 代理描述(覆盖 Agent Card 中的描述) |
| `timeoutMs` | number | 否 | 请求超时(毫秒),默认 30000 |

### 认证

支持两种方式配置 Bearer Token:

1. **环境变量**(推荐)— 设置 `tokenEnv` 指向环境变量:
   ```json
   { "type": "bearer", "tokenEnv": "MY_AGENT_TOKEN" }
   ```
   然后设置环境变量:`export MY_AGENT_TOKEN=sk-xxx`

2. **直接配置** — 在 `token` 中直接写入 token(不推荐用于生产环境):
   ```json
   { "type": "bearer", "token": "sk-xxx" }
   ```

## 使用

### 发现代理

在对话中使用 `a2a_discover` 工具发现远程代理的能力:

```
请帮我发现 https://weather-agent.example.com 这个 A2A 代理的能力
```

工具会返回代理的名称、描述、技能列表等信息。

### 调用代理

使用 `a2a_call` 向已配置的代理发送消息:

```
请用 weather-agent 查询北京今天的天气
```

### 多轮对话

`a2a_call` 返回的 `taskId` 和 `contextId` 可用于后续调用以维持对话上下文:

```
继续上一轮对话,再问一下明天的天气预报
```

## 工具参考

### a2a_discover

| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| `url` | string | 是 | A2A 代理的基础 URL |

### a2a_call

| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| `agent` | string | 是 | 代理名称(必须匹配配置的 peer 名称) |
| `message` | string | 是 | 发送给代理的文本消息 |
| `contextId` | string | 否 | 多轮对话的上下文 ID |
| `taskId` | string | 否 | 继续已有任务的任务 ID |

## Skill 示例

可以为 A2A 代理编写 OpenClaw Skill:

```yaml
---
name: weather-agent
description: 通过 A2A 协议查询天气
metadata:
  {"openclaw": {
    "a2a": {
      "url": "https://weather-agent.example.com",
      "auth": {"type": "bearer", "tokenEnv": "WEATHER_AGENT_TOKEN"}
    }
  }}
---
你是一个天气查询助手。当用户询问天气时,使用 a2a_call 工具调用 weather-agent 获取天气信息。

示例:
- 用户:北京天气怎么样?
  → 调用 a2a_call(agent="weather-agent", message="What's the weather in Beijing?")
```

## 协议兼容性

本插件实现了 A2A 协议的客户端部分:
- 通过 `/.well-known/agent.json` 发现 Agent Card
- 通过 `message/send` JSON-RPC 方法发送消息
- 支持 Task 和 Message 两种响应格式
- 从响应的 parts/artifacts 中提取文本内容

## License

MIT
voice

Comments

Sign in to leave a comment

Loading comments...