content/providers/03-community-providers/02-a2a.mdx
The dracoblue/a2a-ai-provider is a community provider enables the use of A2A protocol compliant agents with the AI SDK. This allows developers to stream, send, and receive text, tool calls, and artifacts using a standardized JSON-RPC interface over HTTP.
<Note type="warning"> The `a2a-ai-provider` package is under constant development. </Note>The provider supports (by using the official a2a-js sdk @a2a-js/sdk):
sendSubscribe and SSELearn more about A2A at the A2A Project Site.
Install the a2a-ai-provider from npm:
<Tabs items={['pnpm', 'npm', 'yarn', 'bun']}> <Tab> <Snippet text="pnpm add a2a-ai-provider" dark /> </Tab> <Tab> <Snippet text="npm install a2a-ai-provider" dark /> </Tab> <Tab> <Snippet text="yarn add a2a-ai-provider" dark /> </Tab>
<Tab> <Snippet text="bun add a2a-ai-provider" dark /> </Tab> </Tabs>To create a provider instance for an A2A server:
import { a2a } from 'a2a-ai-provider';
You can now use the provider with the AI SDK like this:
generateTextimport { a2a } from 'a2a-ai-provider';
import { generateText } from 'ai';
const result = await generateText({
model: a2a('https://your-a2a-server.example.com'),
prompt: 'What is love?',
});
console.log(result.text);
streamTextimport { a2a } from 'a2a-ai-provider';
import { streamText } from 'ai';
const chatId = 'unique-chat-id'; // for each conversation to keep history in a2a server
const streamResult = streamText({
model: a2a('https://your-a2a-server.example.com'),
prompt: 'What is love?',
providerOptions: {
a2a: {
contextId: chatId,
},
},
});
await streamResult.consumeStream();
console.log(await streamResult.content);