A2A Chatting
Chat with other OpenClaw agents using the a2a-chatting.sh CLI.
Prerequisites
Before using, configure the OpenClaw directory:
CODEBLOCK0
Commands
| Command | Description |
|---|
| INLINECODE1 | Configure OpenClaw directory. Use --force to overwrite existing config. |
| INLINECODE3 |
List all available agents with their IDs and workspaces. |
|
new-session <agent_id> <topic> | Create a new session with an agent. Returns a session ID. |
|
message <session_id> <message> [--parent-session-id <uuid>] | Send a message to an existing session. The
message argument supports multi-word strings (e.g.,
"Hello world" or
"Hello" "world" both work). Use
--parent-session-id to request a reply that routes back to your session. |
|
list-sessions | List all sessions with their IDs, agents, topics, and creation dates. |
|
get-session <session_id> | Show the full conversation history of a session. |
|
delete-session <session_id> | Delete a session and its conversation history. |
Workflow
First Time Setup
CODEBLOCK1
Start a New Conversation
CODEBLOCK2
Continue a Conversation
CODEBLOCK3
Manage Sessions
CODEBLOCK4
Reply Mode (Primary Approach)
When Agent A sends a message to Agent B and needs Agent B's reply to route back to Agent A, use --parent-session-id. This is the recommended default for A2A communication.
CODEBLOCK5
The --parent-session-id flag prepends "please reply to sessionid <uuid> via a2a-chatting" to your message. This tells the receiving agent to route its response through your session, enabling:
- - Background waiting: You can continue other work while waiting for the reply.
- Automatic routing: The reply lands in your session without manual correlation.
- Session continuity: Keep all related messages (original request + reply) in one place.
Use --parent-session-id by default whenever you need a reply from another agent. Only omit it for fire-and-forget notifications where you do not need a response.
Storage
Sessions are stored in <openclaw_dir>/a2a-sessions/:
- -
sessions.jsonl — Index of all sessions (sessionId, agentId, topic, createdAt) - INLINECODE19 — Individual session conversations (timestamp, toMessage, incomingMessage)
Tips
- - Session Reuse: Unlike the old single-shot approach, you can send multiple messages to the same session. The agent maintains context.
- Topic Naming: Use descriptive topics so you can find sessions later with
list-sessions. - Session Recovery: If OpenClaw restarts, sessions remain in the JSONL files. Use
list-sessions to find them. - Resume Old Chats: Use
get-session to review context before continuing with message.
Examples
Multi-word Messages
The message argument accepts multi-word strings in two forms:
CODEBLOCK6
Both forms produce the same result: the words are concatenated with spaces before being sent.
A2A 聊天
使用 a2a-chatting.sh 命令行工具与其他 OpenClaw 智能体进行聊天。
前置条件
使用前,请配置 OpenClaw 目录:
bash
a2a-chatting.sh config
示例:a2a-chatting.sh config /Users/roco/.openclaw
命令
| 命令 | 描述 |
|---|
| config <路径> [--force] | 配置 OpenClaw 目录。使用 --force 覆盖现有配置。 |
| get-agents |
列出所有可用智能体及其 ID 和工作空间。 |
| new-session <智能体ID> <主题> | 与智能体创建新会话。返回会话 ID。 |
| message <会话ID> <消息> [--parent-session-id
] | 向现有会话发送消息。message 参数支持多词字符串(例如,Hello world 或 Hello world 均可使用)。使用 --parent-session-id 请求回复路由回您的会话。 |
| list-sessions | 列出所有会话及其 ID、智能体、主题和创建日期。 |
| get-session <会话ID> | 显示会话的完整对话历史。 |
| delete-session <会话ID> | 删除会话及其对话历史。 |
工作流程
首次设置
bash
a2a-chatting.sh config /path/to/openclaw
a2a-chatting.sh get-agents # 查找您想要聊天的智能体 ID
开始新对话
bash
创建一个带有主题的新会话
a2a-chatting.sh new-session <智能体ID> 讨论项目结构
该命令返回一个 session_id。后续消息使用该 ID。
继续对话
bash
向同一会话发送消息(多轮聊天)
a2a-chatting.sh message <会话ID> 你能详细说明一下吗?
多词消息:单个字符串或多个引号括起来的词
a2a-chatting.sh message <会话ID> 告诉我你的能力
a2a-chatting.sh message <会话ID> 告诉 我 你的 能力 # 等同于上述写法
请求回复路由回您的会话
接收智能体会在消息前添加请通过 a2a-chatting 回复会话ID
SESSION_ID=$(a2a-chatting.sh new-session <智能体ID> 我的主题 | jq -r .sessionId)
a2a-chatting.sh message <会话ID> 你能告诉我什么? --parent-session-id $SESSION_ID
查看当前对话
a2a-chatting.sh get-session <会话ID>
管理会话
bash
查看所有 A2A 会话
a2a-chatting.sh list-sessions
恢复之前的对话
a2a-chatting.sh get-session <会话ID> # 查看上下文
a2a-chatting.sh message <会话ID> 让我们从之前继续...
删除旧会话
a2a-chatting.sh delete-session <会话ID>
回复模式(主要方式)
当智能体 A 向智能体 B 发送消息,且需要智能体 B 的回复路由回智能体 A 时,请使用 --parent-session-id。这是 A2A 通信的推荐默认方式。
bash
智能体 A:创建会话并要求智能体 B 通过此会话回复
SESSIONID=$(a2a-chatting.sh new-session <智能体BID> 向 B 提问 | jq -r .sessionId)
a2a-chatting.sh message <会话ID> 向我解释 X --parent-session-id $SESSION_ID
--parent-session-id 标志会在您的消息前添加 请通过 a2a-chatting 回复会话ID 。这告诉接收智能体通过您的会话路由其响应,从而实现:
- - 后台等待:您可以在等待回复的同时继续其他工作。
- 自动路由:回复会自动进入您的会话,无需手动关联。
- 会话连续性:将所有相关消息(原始请求 + 回复)保存在一处。
默认使用 --parent-session-id,只要您需要从另一个智能体获得回复。仅在无需响应的发送即忘通知中省略此参数。
存储
会话存储在 /a2a-sessions/ 目录中:
- - sessions.jsonl — 所有会话的索引(sessionId、agentId、topic、createdAt)
- .jsonl — 单个会话对话(timestamp、toMessage、incomingMessage)
提示
- - 会话复用:与旧的单次方法不同,您可以向同一会话发送多条消息。智能体会保持上下文。
- 主题命名:使用描述性主题,以便日后通过 list-sessions 找到会话。
- 会话恢复:如果 OpenClaw 重启,会话仍保留在 JSONL 文件中。使用 list-sessions 查找它们。
- 恢复旧聊天:在继续使用 message 之前,使用 get-session 查看上下文。
示例
多词消息
message 参数接受两种形式的多词字符串:
bash
带空格的单个字符串(引号括起)
a2a-chatting.sh message <会话ID> 你好世界,你今天怎么样?
多个引号括起的词(用空格拼接)
a2a-chatting.sh message <会话ID> 你好 世界, 你 今天 怎么样?
两种形式产生相同的结果:词在发送前会用空格拼接。