agentalk
v0.1.0
Published
A2A Protocol CLI client — discover and interact with A2A agents
Maintainers
Readme
⚡ agentalk
AI 智能体的 curl — 通用 A2A 协议命令行工具
从终端发现、对话、流式交互、管理任何兼容 A2A 协议的智能体。
🇬🇧 English · 报告 Bug · 功能建议
╭──────────────────────────────────────────────────╮
│ │
│ $ agentalk agent https://my-agent.example.com │
│ │
│ 🤖 食谱助手 │
│ v1.0.0 │
│ 帮你搜索食谱和烹饪指南 │
│ │
│ Skills: │
│ • 食谱搜索 (recipe-search) │
│ 根据食材或菜系搜索食谱 │
│ │
│ $ agentalk send https://my-agent.example.com \ │
│ -m "帮我找一道意面食谱" │
│ │
│ agent: 这是一道经典的卡博纳拉意面... │
│ │
╰──────────────────────────────────────────────────╯目录
为什么选择 agentalk?
A2A(Agent-to-Agent)协议 是 Google 发起的开放标准,让 AI 智能体之间可以互相通信。agentalk 把这个协议带到了你的终端。
快速开始
全局安装
pnpm add -g agentalk或通过 pnpm dlx 直接运行
pnpm dlx agentalk agent https://agent.example.com[!TIP] 无需任何配置。指向任何 A2A 兼容的智能体 URL 即可使用。
使用方法
🔍 发现智能体
agentalk agent https://agent.example.com🤖 Recipe Agent
v1.0.0
帮助用户搜索食谱和烹饪指南的智能体
Provider:
Google (https://ai.google.dev)
Capabilities:
streaming, push-notifications
Skills:
• Recipe Search (recipe-search)
根据食材或菜系搜索食谱
tags: cooking, recipes, food💬 发送消息
# 简单消息
agentalk send https://agent.example.com -m "你能做什么?"
# 带上下文的多轮对话
agentalk send https://agent.example.com -m "继续说" -c ctx_abc123
# 继续已有任务
agentalk send https://agent.example.com -m "好的,继续" -t task_xyz
# 异步发送(不等待完成)
agentalk send https://agent.example.com -m "处理这份报告" --async🌊 流式响应
agentalk stream https://agent.example.com -m "生成一份详细分析"[task-42] status → working
agent: 正在分析数据...
agent: 以下是主要发现:
[task-42] 📎 report.md: # 分析报告 ... (final)
[task-42] status → completed📋 管理任务
agentalk task get https://agent.example.com task_abc123 # 查看状态
agentalk task list https://agent.example.com # 列出所有
agentalk task list https://agent.example.com -s TASK_STATE_COMPLETED # 按状态过滤
agentalk task cancel https://agent.example.com task_abc123 # 取消任务命令速查
agentalk [选项] [命令]
命令:
agent <url> 获取并展示 Agent Card
send [选项] <url> 向智能体发送消息
stream [选项] <url> 发送消息并流式接收响应(SSE)
task get <url> <taskId> 通过 ID 获取任务
task list [选项] <url> 列出任务
task cancel <url> <taskId> 取消任务
全局选项:
--json 输出原始 JSON(方便管道和脚本处理)
-H, --header <key:value> 添加 HTTP 头(可重复使用)
--tenant <id> 租户 ID(多租户场景)
-V, --version 显示版本号
-h, --help 显示帮助信息| 参数 | 说明 |
|------|------|
| -m, --message <text> | 消息内容 (必填) |
| -c, --context <id> | 上下文 ID,用于多轮对话 |
| -t, --task <id> | 任务 ID,继续已有任务 |
| --output-modes <modes> | 可接受的输出 MIME 类型(逗号分隔) |
| --history-length <n> | 返回的最大历史消息数 |
| --async | 立即返回,不等待任务完成 |
| 参数 | 说明 |
|------|------|
| -m, --message <text> | 消息内容 (必填) |
| -c, --context <id> | 上下文 ID,用于多轮对话 |
| -t, --task <id> | 任务 ID,继续已有任务 |
| --output-modes <modes> | 可接受的输出 MIME 类型(逗号分隔) |
| 参数 | 说明 |
|------|------|
| -c, --context <id> | 按上下文 ID 过滤 |
| -s, --status <state> | 按任务状态过滤 |
| --history-length <n> | 每个任务的最大历史消息数 |
| --artifacts | 包含产物(Artifacts) |
| --page-size <n> | 每页结果数 |
| --page-token <token> | 分页令牌 |
实用技巧
配合 jq 处理 JSON
# 提取任务状态
agentalk --json task get https://agent.example.com task_123 | jq '.status.state'
# 获取所有技能名称
agentalk --json agent https://agent.example.com | jq '.skills[].name'带认证使用
# Bearer Token
agentalk agent https://agent.example.com -H "Authorization: Bearer sk-xxx"
# API Key
agentalk send https://agent.example.com -m "你好" -H "X-API-Key: key_xxx"多轮对话
# 1. 开始对话 — 获取 contextId
CTX=$(agentalk --json send https://agent.example.com -m "帮我规划一次东京旅行" \
| jq -r '.task.contextId')
# 2. 带上下文继续
agentalk send https://agent.example.com -m "改成 5 天的行程" -c "$CTX"
# 3. 在同一任务上继续
agentalk send https://agent.example.com -m "加上餐厅推荐" -c "$CTX" -t task-xyz多租户场景
agentalk --tenant org_acme send https://agent.example.com -m "你好"任务状态说明
| 状态 | 图标 | 说明 |
|------|------|------|
| TASK_STATE_SUBMITTED | 📥 | 任务已提交,等待处理 |
| TASK_STATE_WORKING | ⏳ | 智能体正在处理中 |
| TASK_STATE_COMPLETED | ✅ | 任务成功完成 |
| TASK_STATE_FAILED | ❌ | 任务处理失败 |
| TASK_STATE_CANCELED | 🚫 | 任务已取消 |
| TASK_STATE_INPUT_REQUIRED | 💬 | 智能体需要更多输入 |
| TASK_STATE_REJECTED | ⛔ | 智能体拒绝了该任务 |
| TASK_STATE_AUTH_REQUIRED | 🔐 | 需要认证 |
架构
graph LR
subgraph CLI["🖥️ CLI 层"]
A[cli.ts<br/>Commander.js] --> B[commands/agent.ts]
A --> C[commands/send.ts]
A --> D[commands/stream.ts]
A --> E[commands/task.ts]
end
subgraph Core["⚙️ 核心层"]
F[client.ts<br/>A2AClient]
G[format.ts<br/>chalk 美化输出]
H[types.ts<br/>A2A v1.0 类型]
end
B & C & D & E --> F
B & C & D & E --> G
F --> H
subgraph Remote["☁️ 远程智能体"]
I["/.well-known/agent.json"]
J["POST /"]
K["POST /stream (SSE)"]
L["GET/POST /tasks/*"]
end
F -->|HTTP| I & J & K & Lsrc/
├── cli.ts # 入口 — Commander.js CLI 配置
├── client.ts # A2AClient — 封装所有 A2A HTTP 操作
├── format.ts # 美化输出格式化器(基于 chalk)
├── types.ts # 完整的 A2A Protocol v1.0 TypeScript 类型
├── commands/
│ ├── agent.ts # `agentalk agent` 命令
│ ├── send.ts # `agentalk send` 命令
│ ├── stream.ts # `agentalk stream` 命令
│ └── task.ts # `agentalk task {get,list,cancel}` 命令
└── test/
├── client.test.ts # A2AClient 单元测试(mock fetch)
├── format.test.ts # 格式化器单元测试
└── cli.test.ts # CLI 集成测试本地开发
# 安装依赖
pnpm install
# 构建
pnpm build
# 监听模式
pnpm dev
# 运行测试(72 个测试用例)
pnpm test
# 全局链接,方便本地调试
pnpm link --global环境要求
| 依赖 | 版本 | |------|------| | Node.js | ≥ 22 | | TypeScript | ≥ 5.7 |
[!NOTE] 使用原生
fetch(无需 polyfill)和node:test实现零依赖测试。
贡献指南
欢迎贡献!步骤如下:
- Fork 本仓库
- 创建分支(
git checkout -b feat/amazing-feature) - 开发你的功能
- 运行测试(
pnpm test) - 提交代码(
git commit -m 'feat: add amazing feature') - 推送分支(
git push origin feat/amazing-feature) - 发起 Pull Request
[!NOTE] 请遵循 Conventional Commits 规范编写提交信息。
相关链接
| 资源 | 链接 | |------|------| | A2A 协议规范 | google.github.io/A2A | | A2A GitHub | github.com/google/A2A | | npm 包 | npmjs.com/package/agentalk |
MIT © 2026
用 ❤️ 为 A2A 生态而造
