A NestJS library for implementing Google's Agent-to-Agent (A2A) protocol.
nestjs-a2a
is a library designed to simplify the implementation of Google's Agent-to-Agent (A2A) protocol in NestJS applications. It provides a set of utilities, decorators, and interfaces to make building A2A-compatible agents seamless and type-safe.
npm install nestjs-a2a
# or
yarn add nestjs-a2a
# or
pnpm add nestjs-a2a
import { Module } from '@nestjs/common';
import { AgentToAgentModule } from 'nestjs-a2a';
@Module({
imports: [
AgentToAgentModule.register({
card: {
name: 'My Agent',
description: 'A sample A2A agent',
version: '1.0.0',
capabilities: {
streaming: true,
},
provider: {
organization: 'My Organization',
url: 'https://myorganization.com',
},
},
}),
],
})
export class AppModule {}
- Complete implementation of Google's Agent-to-Agent (A2A) protocol
- Type-safe communication between agents
- Easy-to-use decorators for defining agent skills
- Support for streaming responses
- Automatic skill discovery and registration
- JSON-RPC 2.0 compliant API
- Built-in task state management
Use the @Skill
decorator to define agent skills:
import { Injectable } from '@nestjs/common';
import {
InputMode,
OutputMode,
Skill,
TaskYieldUpdate,
Task,
TaskState,
PartType,
MessageRole,
} from 'nestjs-a2a';
@Injectable()
export class GreetingService {
@Skill({
id: 'greeting',
name: 'Greeting',
description: 'Greet the user',
examples: ['Hello', 'Hi', 'Good morning'],
inputModes: [InputMode.TEXT],
outputModes: [OutputMode.TEXT],
tags: ['greeting'],
})
async *greet(): AsyncGenerator<TaskYieldUpdate, Task | void, unknown> {
yield {
state: TaskState.WORKING,
message: {
role: MessageRole.AGENT,
parts: [
{
type: PartType.TEXT,
text: 'Hello! How can I help you today?',
},
],
},
};
yield {
state: TaskState.COMPLETED,
};
}
}
The main module for integrating A2A functionality into your NestJS application.
register(options: AgentToAgentModuleOptions)
: Register the module with static optionsregisterAsync(options: AgentToAgentAsyncModuleOptions)
: Register the module with async options
interface AgentToAgentModuleOptions {
// Agent card information
card: Omit<AgentCard, 'skills'>;
// Optional custom task store implementation
taskStore?: TaskStore;
// Optional base path for the A2A endpoints (default: '/a2a')
basePath?: string;
// Optional guards for securing A2A endpoints
guards?: CanActivate[];
// Optional function to select a skill based on the task
selectSkill?: (task: Task) => Promise<string> | string;
}
@Skill(config: AgentSkill)
: Marks a method as an agent skill handler
Check the example
directory for a complete working example of an A2A agent implementation.
# Run the example
pnpm start:example
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project uses GitHub Actions for continuous integration:
- All pull requests and pushes to the main branch are automatically tested
- Code quality checks including linting and type checking are performed
- Test coverage is reported
Deployment to npm is automated using GitHub Actions and semantic-release:
- Create and push a new tag following semantic versioning (e.g.,
v1.0.0
) - GitHub Actions will automatically build, test, and publish the package to npm
- A GitHub Release will be created with release notes
# Example: Creating and pushing a new tag
git tag v1.0.0
git push origin v1.0.0
This project is licensed under the MIT License - see the LICENSE.md file for details.
Thieu Quan Ngoc - [email protected] - @thestupd
Website: https://stupd.dev