@ag-ui/a2a

中文文档
0.0.7发布于 2026/10/13MITTypeScriptESM + CJS构建来源已验证近 30 天下载 2.7万

A TypeScript integration that connects AG-UI agents with remote services that expose the A2A protocol. It converts AG-UI conversations into A2A payloads, forwards them through the official A2A SDK, and replays the responses back into A

原始使用文档
文档目录9 节
  1. Features
  2. Installation
  3. Quick start
  4. Configuration reference
  5. Environment variables & authentication
  6. Utilities
  7. Testing
  8. Examples
  9. Release checklist

@ag-ui/a2a

A TypeScript integration that connects AG-UI agents with remote services that expose the A2A protocol. It converts AG-UI conversations into A2A payloads, forwards them through the official A2A SDK, and replays the responses back into AG-UI event streams.

Status: Experimental. APIs may change while the integration stabilises.

Features

  • Message conversion helpers between AG-UI and A2A formats (user, assistant, tool, binary payloads).
  • A2AAgent implementation that streams or performs blocking requests against A2A endpoints.
  • Optional fallback from streaming to blocking requests when an agent does not support SSE.
  • Event conversion utilities that surface A2A messages, task status updates, and artifact chunks as AG-UI events.
  • Helper tool schema (send_message_to_a2a_agent) for orchestration scenarios.
  • Example client and Vitest tests to validate conversions and streaming flows.

Installation

Once dependencies are installed in the monorepo:

pnpm install
pnpm --filter @ag-ui/a2a build

Quick start

import { A2AAgent } from "@ag-ui/a2a";

import { A2AClient } from "@a2a-js/sdk/client";

const client = new A2AClient("https://my-a2a-agent");

const agent = new A2AAgent({
  a2aClient: client,
  initialMessages: [{ id: "user-1", role: "user", content: "Plan a team offsite" } as any],
});

const { result, newMessages } = await agent.runAgent();
console.log(result);
console.log(newMessages);

You can inject your own A2AClient instance via the client option, override default instructions, or force blocking mode by setting strategy: "blocking".

Configuration reference

OptionDescription
a2aClientRequired. Provide an A2AClient instance (with any auth headers or custom fetch logic you need).

Environment variables & authentication

The integration relies on the underlying A2A agent for authentication. Common patterns include:

  • A2A_AGENT_URL – set in deployment environments to point to the remote agent base URL.
  • A2A_API_KEY or A2A_BEARER_TOKEN – consumed by a wrapped fetch inside a custom A2AClient instance if the remote agent enforces API key or bearer authentication.

Pass any credentials to the A2AClient you provide to A2AAgent, or configure an HTTP proxy that injects the correct headers.

Utilities

  • convertAGUIMessagesToA2A(messages, options) — reshapes AG-UI history into A2A message objects, forwarding only user/assistant/tool turns and preserving the tool payloads.
  • convertA2AEventToAGUIEvents(event, options) — maps an A2A stream event to AG-UI text and tool events (TEXT_MESSAGE_CHUNK, TOOL_CALL_*, TOOL_CALL_RESULT).
  • sendMessageToA2AAgentTool — JSON schema describing a send_message_to_a2a_agent tool for orchestration agents.

Testing

pnpm --filter @ag-ui/a2a test

The suite covers conversion edge cases and streaming / fallback behaviour using mocked A2A clients.

Examples

  • examples/basic.ts – minimal script. If you set A2A_AGENT_URL, it will connect to that agent through the real A2AClient. Otherwise it falls back to a tiny in-memory mock client so you can observe the integration without hitting a remote endpoint.

Release checklist

  1. pnpm --filter @ag-ui/a2a build
  2. pnpm --filter @ag-ui/a2a test
  3. Update CHANGELOG / release notes.
  4. Publish with pnpm publish --filter @ag-ui/a2a.

版本与发布记录

@ag-ui/a2a 共发布 7 个版本,首次发布于 2025/10/23;过去 12 个月发布了 2 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.0.7latest2026/10/1325 天前
0.0.62025/12/1710 个月前
0.0.52025/10/241 年前
0.0.42025/10/231 年前
0.0.32025/10/231 年前
0.0.22025/10/231 年前

关于 @ag-ui/a2a 的常见问题

@ag-ui/a2a 是什么?

A TypeScript integration that connects AG-UI agents with remote services that expose the A2A protocol. It converts AG-UI conversations into A2A payloads, forwards them through the official A2A SDK, and replays the responses back into A

如何安装 @ag-ui/a2a?

在项目目录运行 npm install @ag-ui/a2a,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@ag-ui/core(>=1.0.0)、@ag-ui/client(>=1.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@ag-ui/a2a 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ag-ui/a2a 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@ag-ui/a2a 可以商用吗?

@ag-ui/a2a 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ag-ui/a2a 的下载量有多少?

根据 npm 官方下载统计,@ag-ui/a2a 在 2026/10/05 – 2026/11/03 这 30 天内被下载 27,216 次,日均约 907 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ag-ui/a2a 还在维护吗?

最新版本 0.0.7 发布于 2026/10/13(25 天前);至今共发布 7 个版本,其中过去 12 个月发布了 2 个;首次发布于 2025/10/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。