
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
JavaScript SDK for the Agent2Agent (A2A) Protocol - enabling communication between AI agents
This is a JavaScript SDK for the Agent2Agent (A2A) protocol, based on the A2A Python SDK.
The Agent2Agent (A2A) protocol addresses a critical challenge in the AI landscape: enabling gen AI agents, built on diverse frameworks by different companies running on separate servers, to communicate and collaborate effectively - as agents, not just as tools.
With A2A, agents can:
npm install a2a-js
npm install a2a-js uuid
import { v4 as uuidv4 } from 'uuid';
import { A2AClient } from 'a2a-js';
import { Role, TaskState, Part, TaskSendParams, SendTaskStreamingResponse, TaskStatusUpdateEvent, TaskArtifactUpdateEvent } from 'a2a-js';
async function main() {
// Create the A2A client directly
const client = new A2AClient('http://localhost:9999/', fetch);
console.log('Testing basic request...');
try {
const params: TaskSendParams = {
id: uuidv4(),
message: {
role: Role.User,
parts: [{ type: 'text', text: 'Hello' }],
},
};
const basicResponse = await client.sendTask(params);
console.log('Basic Response:', JSON.stringify(basicResponse, null, 2));
} catch (error) {
console.error('Basic request error:', error);
}
console.log('\nTesting streaming request...');
try {
const streamParams: TaskSendParams = {
id: uuidv4(),
message: {
role: Role.User,
parts: [{ type: 'text', text: 'Hello streaming' }],
},
};
const stream = client.sendTaskSubscribe(streamParams);
for await (const event of stream as AsyncGenerator<SendTaskStreamingResponse, void, unknown>) {
if (!event || (typeof event === 'object' && Object.keys(event).length === 0)) continue;
if ('result' in event && event.result) {
const result = event.result;
if (result.type === 'taskStatusUpdate') {
const statusEvent = result as TaskStatusUpdateEvent;
const state = statusEvent.status.state;
const message = statusEvent.status.message;
if (state === TaskState.Working && message && message.parts) {
const textParts = message.parts
.filter((part) => part.type === 'text')
.map((part) => (part as Part & { text: string }).text)
.join('');
if (textParts) {
console.log('Message content:', textParts);
}
} else if ([TaskState.Completed, TaskState.Canceled, TaskState.Failed, TaskState.InputRequired].includes(state)) {
console.log('Task completed:', JSON.stringify(statusEvent, null, 2));
}
} else if (result.type === 'taskArtifactUpdate') {
const artifactEvent = result as TaskArtifactUpdateEvent;
console.log('Artifact event:', JSON.stringify(artifactEvent, null, 2));
} else {
console.log('Stream Event:', JSON.stringify(result, null, 2));
}
} else if ('error' in event && event.error) {
console.error('Stream error:', JSON.stringify(event.error, null, 2));
} else {
console.log('Unknown stream event:', JSON.stringify(event, null, 2));
}
}
console.log('Streaming complete');
} catch (error) {
console.error('Streaming error:', error);
}
}
main().catch(error => {
console.error('Error:', error);
process.exit(1);
});
import {
Role as RoleEnum,
AgentCard,
AgentSkill,
A2AServer,
DefaultA2ARequestHandler,
Message,
Part,
Task,
OperationNotSupportedError,
SendMessageRequest,
SendMessageResponse,
SendMessageStreamingRequest,
SendMessageStreamingResponse,
CancelTaskRequest,
CancelTaskResponse,
TaskResubscriptionRequest
} from 'a2a-js';
class HelloWorldAgent {
async invoke(): Promise<string> {
return 'Hello World';
}
async *stream(): AsyncGenerator<{ content: string, done: boolean }, void, unknown> {
yield { content: 'Hello ', done: false };
await new Promise(resolve => setTimeout(resolve, 2000));
yield { content: 'World', done: false };
await new Promise(resolve => setTimeout(resolve, 1000));
yield { content: '!', done: true };
}
}
class HelloWorldAgentExecutor {
private agent: HelloWorldAgent;
constructor() {
this.agent = new HelloWorldAgent();
}
async onMessageSend(
request: SendMessageRequest,
task?: Task
): Promise<SendMessageResponse> {
const result = await this.agent.invoke();
const message: Message = {
role: RoleEnum.Agent,
parts: [{ type: 'text', text: result } as Part]
};
return {
jsonrpc: '2.0',
id: request.id,
result: message
};
}
async *onMessageStream(
request: SendMessageStreamingRequest,
task?: Task
): AsyncGenerator<SendMessageStreamingResponse, void, unknown> {
for await (const chunk of this.agent.stream()) {
const message: Message = {
role: RoleEnum.Agent,
parts: [{ type: 'text', text: chunk.content } as Part]
};
yield {
jsonrpc: '2.0',
id: request.id,
result: message
};
}
}
async onCancel(
request: CancelTaskRequest,
task: Task
): Promise<CancelTaskResponse> {
return {
jsonrpc: '2.0',
id: request.id,
error: new OperationNotSupportedError()
};
}
async *onResubscribe(
request: TaskResubscriptionRequest,
task: Task
): AsyncGenerator<SendMessageStreamingResponse, void, unknown> {
yield {
jsonrpc: '2.0',
id: request.id,
error: new OperationNotSupportedError()
};
}
}
const skill: AgentSkill = {
id: 'hello_world',
name: 'Returns hello world',
description: 'just returns hello world',
tags: ['hello world'],
examples: ['hi', 'hello world'],
};
const agentCard: AgentCard = {
name: 'Hello World Agent',
description: 'Just a hello world agent',
url: 'http://localhost:9999/',
version: '1.0.0',
defaultInputModes: ['text'],
defaultOutputModes: ['text'],
capabilities: { streaming: true },
skills: [skill],
authentication: {
schemes: ['public'],
}
};
const requestHandler = new DefaultA2ARequestHandler(
new HelloWorldAgentExecutor()
);
const port = process.env.PORT ? parseInt(process.env.PORT, 10) : 9999;
const server = new A2AServer(agentCard, requestHandler);
server.start({ port });
Check the examples/ directory for more usage examples:
examples/helloworld/client.ts and examples/helloworld/server.ts)examples/common-workflows/):
The SDK also supports long-running tasks using the task management system defined in src/server/task_store.ts.
Contributions are welcome! Please read the contributing guidelines first.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
FAQs
JavaScript SDK for the Agent2Agent (A2A) Protocol - enabling communication between AI agents
We found that a2a-js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.