A2A4J is a comprehensive Java implementation of the Agent2Agent Protocol, including server, client, examples, and starters.
๐ ไธญๆๆๆกฃ
Agent2Agent (A2A) providing an open standard for communication and interoperability between independent AI agent systems.
A2A4J A2A4J is a comprehensive Java implementation of the Agent2Agent (A2A) Protocol, including server, client, examples, and starters. Built on Reactor for reactive programming support, A2A4J enables agents to discover each other's capabilities, collaborate on tasks, and securely exchange information without needing access to each other's internal state.
a2a4j/
โโโ a2a4j-bom/ # A2A4J dependency management
โโโ a2a4j-core/ # Core A2A protocol implementation
โโโ a2a4j-spring-boot-starter/ # Spring Boot auto-configuration
โ โโโ a2a4j-server-spring-boot-starter/ # Server-side starter
โ โโโ a2a4j-client-spring-boot-starter/ # Client-side starter
โโโ a2a4j-samples/ # Example implementations
โ โโโ server-hello-world/ # Hello World server example
โ โโโ client-hello-world/ # Hello World client example
โโโ specification/ # A2A protocol specification
โโโ tools/ # Development tools and configuration
If youโre building on the SpringBoot framework, it is recommended to use a2a4j-server-spring-boot-starter.
<dependency>
<groupId>io.github.a2ap</groupId>
<artifactId>a2a4j-server-spring-boot-starter</artifactId>
<version>0.0.1</version>
</dependency>
For other frameworks, it is recommended to use a2a4j-core.
<dependency>
<groupId>io.github.a2ap</groupId>
<artifactId>a2a4j-core</artifactId>
<version>0.0.1</version>
</dependency>
@RestController
public class MyA2AController {
@Autowired
private A2AServer a2aServer;
@Autowired
private final Dispatcher a2aDispatch;
@GetMapping(".well-known/agent.json")
public ResponseEntity<AgentCard> getAgentCard() {
AgentCard card = a2aServer.getSelfAgentCard();
return ResponseEntity.ok(card);
}
@PostMapping(value = "/a2a/server", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<JSONRPCResponse> handleA2ARequestTask(@RequestBody JSONRPCRequest request) {
return ResponseEntity.ok(a2aDispatch.dispatch(request));
}
@PostMapping(value = "/a2a/server", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<ServerSentEvent<JSONRPCResponse>> handleA2ARequestTaskSubscribe(@RequestBody JSONRPCRequest request) {
return a2aDispatch.dispatchStream(request).map(event -> ServerSentEvent.<JSONRPCResponse>builder()
.data(event).event("task-update").build());
}
}
AgentExecutor Interface for Agent Task Execution@Component
public class MyAgentExecutor implements AgentExecutor {
@Override
public Mono<Void> execute(RequestContext context, EventQueue eventQueue) {
// your agent logic code
TaskStatusUpdateEvent completedEvent = TaskStatusUpdateEvent.builder()
.taskId(taskId)
.contextId(contextId)
.status(TaskStatus.builder()
.state(TaskState.COMPLETED)
.timestamp(String.valueOf(Instant.now().toEpochMilli()))
.message(createAgentMessage("Task completed successfully! Hi you."))
.build())
.isFinal(true)
.metadata(Map.of(
"executionTime", "3000ms",
"artifactsGenerated", 4,
"success", true))
.build();
eventQueue.enqueueEvent(completedEvent);
return Mono.empty();
}
}
Thatโs it โ these are the main steps. For detailed implementation, please refer to our Agent Demo example.
git clone https://github.com/a2ap/a2a4j.git
cd a2a4j
mvn clean install
cd a2a4j-samples/server-hello-world
mvn spring-boot:run
The server will start at http://localhost:8089.
curl http://localhost:8089/.well-known/agent.json
curl -X POST http://localhost:8089/a2a/server \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "message/send",
"params": {
"message": {
"role": "user",
"parts": [
{
"kind": "text",
"text": "Hello, A2A!"
}
],
"messageId": "9229e770-767c-417b-a0b0-f0741243c589"
}
},
"id": "1"
}'
curl -X POST http://localhost:8089/a2a/server \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-d '{
"jsonrpc": "2.0",
"method": "message/stream",
"params": {
"message": {
"role": "user",
"parts": [
{
"kind": "text",
"text": "Hello, streaming A2A!"
}
],
"messageId": "9229e770-767c-417b-a0b0-f0741243c589"
}
},
"id": "1"
}'
a2a4j-core)The core module provides the fundamental A2A protocol implementation:
a2a4j-server-spring-boot-starter)Auto-configuration for A2A servers with Spring Boot, providing:
a2a4j-client-spring-boot-starter)Auto-configuration for A2A clients with Spring Boot, providing:
a2a4j-samples)Complete working examples demonstrating A2A4J usage:
message/send - Send a message and create a taskmessage/stream - Send a message with streaming updatestasks/get - Get task status and detailstasks/cancel - Cancel a running tasktasks/resubscribe - Resubscribe to task updatestasks/pushNotificationConfig/set - Configure push notificationstasks/pushNotificationConfig/get - Get notification configurationWe welcome contributions! Please see our Contributing Guidelines for details.
git checkout -b feature/my-featuregit commit -am 'Add new feature'git push origin feature/my-featureThis project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Built with โค๏ธ by the A2AP Community
No configuration available
Related projects feature coming soon
Will recommend related projects based on sub-categories