### A2A Server Configuration Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-samples/server-hello-world/README.md Example configuration for the A2A server in `application.yml`. This includes server port, agent details, capabilities, and skills. ```yaml server: port: 8089 # Modify server port a2a: server: id: "server-hello-world" name: "A2A Java Server" description: "A sample A2A agent implemented in Java" version: "1.0.0" url: "http://localhost:${server.port}/a2a/server" provider: name: "A2AP Team" url: "https://github.com/a2ap" documentationUrl: "https://github.com/a2ap/a2a4j" capabilities: streaming: true pushNotifications: false stateTransitionHistory: true defaultInputModes: - "text" defaultOutputModes: - "text" skills: - name: "hello-world" description: "A simple hello world skill" tags: - "greeting" - "basic" examples: - "Say hello to me" - "Greet me" inputModes: - "text" outputModes: - "text" ``` -------------------------------- ### Configure Agent Properties Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-spring-boot-starter/a2a4j-server-spring-boot-starter/README_CN.md Example of configuring agent metadata and capabilities using application.yml for the A2A server. ```yaml a2a: server: name: "我的 A2A 智能体" description: "一个强大的 A2A 智能体" version: "1.0.0" url: "https://my-agent.example.com" capabilities: streaming: true push-notifications: false state-transition-history: true ``` -------------------------------- ### Clone Repository Source: https://github.com/a2ap/a2a4j/blob/main/CONTRIBUTING.md Clones the a2a4j repository from GitHub to your local machine. This is the first step for contributing code. ```shell git clone git@github.com:${YOUR_USERNAME}/a2a4j.git #Recommended ``` -------------------------------- ### Build and Run A2A4J Client Hello World Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-samples/client-hello-world/README_CN.md Commands to clone the repository, build the A2A4J project, navigate to the client-hello-world sample, and run the client using Maven or a packaged JAR file. ```bash # Clone the repository (if not already cloned) git clone https://github.com/a2ap/a2a4j.git cd a2a4j # Build the entire project mvn clean install # Enter the sample directory cd a2a4j-samples/client-hello-world # Run using Maven mvn spring-boot:run # Or run the compiled JAR package mvn clean package java -jar target/client-hello-world-*.jar ``` -------------------------------- ### Actuator Endpoints Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-samples/server-hello-world/README.md Examples of using curl to access Spring Boot Actuator endpoints for monitoring application info, health, and metrics. ```bash # View application info curl http://localhost:8089/actuator/info # View health status curl http://localhost:8089/actuator/health # View metrics curl http://localhost:8089/actuator/metrics ``` -------------------------------- ### Run A2A4J Server Hello World Example Source: https://github.com/a2ap/a2a4j/blob/main/README.md Provides bash commands to clone the A2A4J repository, navigate to the server-hello-world sample, build it using Maven, and run the Spring Boot application. ```bash git clone https://github.com/a2ap/a2a4j.git cd a2a4j mvn clean install cd a2a4j-samples/server-hello-world mvn spring-boot:run ``` -------------------------------- ### Configure A2A Agent Properties (Properties) Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-spring-boot-starter/a2a4j-server-spring-boot-starter/README.md Example of configuring A2A agent metadata and capabilities using properties in `application.properties`. ```properties a2a.server.name=My A2A Agent a2a.server.description=A powerful A2A agent a2a.server.version=1.0.0 a2a.server.url=https://my-agent.example.com a2a.server.capabilities.streaming=true a2a.server.capabilities.push-notifications=false a2a.server.capabilities.state-transition-history=true ``` -------------------------------- ### Configure A2A Agent Properties (YAML) Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-spring-boot-starter/a2a4j-server-spring-boot-starter/README.md Example of configuring A2A agent metadata and capabilities using YAML in `application.yml`. ```yaml a2a: server: name: "My A2A Agent" description: "A powerful A2A agent" version: "1.0.0" url: "https://my-agent.example.com" capabilities: streaming: true push-notifications: false state-transition-history: true ``` -------------------------------- ### Test Streaming Response with httpie Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-samples/server-hello-world/README_CN.md An example using the httpie command-line tool to test streaming responses from the A2A server. It sends a message and observes the Server-Sent Events. ```Bash echo '{ \ "jsonrpc": "2.0", \ "method": "message/stream", \ "params": { \ "message": { \ "role": "user", \ "parts": [{"kind": "text", "text": "创建一个数据结构示例"}] \ } \ }, \ "id": "1" \ }' | http POST localhost:8089/a2a/server \ Content-Type:application/json \ Accept:text/event-stream ``` -------------------------------- ### Testing Streaming Response Handling with httpie Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-samples/server-hello-world/README.md An example using the `httpie` tool to test streaming responses from the A2A server. It pipes a JSON-RPC request to the server and observes the event-stream output. ```bash # Use httpie to observe streaming responses echo '{ "jsonrpc": "2.0", "method": "message/stream", "params": { "message": { "role": "user", "parts": [{"kind": "text", "text": "Create a data structure example"}] } }, "id": "1" }' | http POST localhost:8089/a2a/server \ Content-Type:application/json \ Accept:text/event-stream ``` -------------------------------- ### Run A2A4J Server Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-core/README.md Starts the A2A4J server using Maven. The server will be accessible at http://localhost:8089. ```bash mvn spring-boot:run ``` -------------------------------- ### Run A2A4J Server Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-core/README_CN.md Starts the A2A4J server using Maven. The server will be accessible at http://localhost:8089. ```bash mvn spring-boot:run ``` -------------------------------- ### Custom Starter Dependencies Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-spring-boot-starter/a2a4j-server-spring-boot-starter/STARTER_API.md Example Maven dependencies for creating a custom starter that includes the A2A4J Server Spring Boot Starter and Spring Security/Data JPA. ```xml io.github.a2ap a2a4j-server-spring-boot-starter org.springframework.boot spring-boot-starter-security org.springframework.boot spring-boot-starter-data-jpa ``` -------------------------------- ### A2A Agent Card Discovery Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-samples/server-hello-world/README_CN.md Demonstrates how to retrieve the Agent Card, which contains metadata and capabilities of the intelligent agent, using a GET request to the /.well-known/agent.json endpoint. ```Bash curl -X GET http://localhost:8089/.well-known/agent.json ``` ```JSON { "id": "server-hello-world", "name": "A2A Java Server", "description": "A sample A2A agent implemented in Java", "url": "http://localhost:8089/a2a/server", "provider": { "organization": "A2A", "url": "https://github.com/google-a2a/a2a-samples" }, "version": "1.0.0", "documentationUrl": "https://google-a2a.github.io/A2A/", "capabilities": { "streaming": true, "pushNotifications": false, "stateTransitionHistory": true }, "defaultInputModes": [ "text" ], "defaultOutputModes": [ "text" ], "skills": [ { "id": "hello-world", "name": "hello-world", "description": "A simple hello world skill", "tags": [ "greeting", "basic" ], "examples": [ "Say hello to me", "Greet me" ], "inputModes": [ "text" ], "outputModes": [ "text" ] } ] } ``` -------------------------------- ### Custom Agent Card Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-spring-boot-starter/a2a4j-server-spring-boot-starter/README.md Provides an example of creating a custom AgentCard with detailed metadata, including name, description, URL, version, capabilities, skills, and default input/output modes. ```java @Bean @Primary public AgentCard customAgentCard() { return AgentCard.builder() .name("Advanced Agent") .description("An advanced A2A agent with custom capabilities") .url("https://advanced-agent.example.com") .version("2.0.0") .capabilities(AgentCapabilities.builder() .streaming(true) .pushNotifications(true) .stateTransitionHistory(true) .build()) .skills(List.of( AgentSkill.builder() .name("text-processing") .description("Process and analyze text content") .build(), AgentSkill.builder() .name("data-analysis") .description("Analyze data and generate insights") .build() )) .defaultInputModes(List.of("text", "file", "json")) .defaultOutputModes(List.of("text", "file", "json", "image")) .build(); } ``` -------------------------------- ### A2A Agent Card Discovery Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-samples/server-hello-world/README.md Demonstrates how to retrieve agent capabilities and metadata using a GET request to the /.well-known/agent.json endpoint. The expected response is a JSON object detailing the agent's properties. ```APIDOC GET /.well-known/agent.json - Retrieves agent capabilities and metadata. - Expected Response Example: { "id": "server-hello-world", "name": "A2A Java Server", "description": "A sample A2A agent implemented in Java", "url": "http://localhost:8089/a2a/server", "provider": { "organization": "A2A", "url": "https://github.com/google-a2a/a2a-samples" }, "version": "1.0.0", "documentationUrl": "https://google-a2a.github.io/A2A/", "capabilities": { "streaming": true, "pushNotifications": false, "stateTransitionHistory": true }, "defaultInputModes": [ "text" ], "defaultOutputModes": [ "text" ], "skills": [ { "id": "hello-world", "name": "hello-world", "description": "A simple hello world skill", "tags": [ "greeting", "basic" ], "examples": [ "Say hello to me", "Greet me" ], "inputModes": [ "text" ], "outputModes": [ "text" ] } ] } ``` -------------------------------- ### Custom TaskStore Implementation Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-spring-boot-starter/a2a4j-server-spring-boot-starter/STARTER_API.md Example of overriding the default TaskStore with a custom implementation, such as JdbcTaskStore, using @Primary annotation. ```java @Configuration public class CustomTaskStoreConfig { @Bean @Primary public TaskStore customTaskStore(DataSource dataSource) { return new JdbcTaskStore(dataSource); } } ``` -------------------------------- ### Synchronizing with Upstream Repository Source: https://github.com/a2ap/a2a4j/blob/main/CONTRIBUTING_CN.md Explains how to add the upstream repository as a remote and then pull the latest changes from the main branch into the local repository to stay updated. ```shell git remote add upstream https://github.com/a2ap/a2a4j.git #绑定远程仓库,如果已经执行过,则不需要再次执行 git checkout main git pull upstream main ``` -------------------------------- ### A2A Client Usage Examples Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-core/API_REFERENCE.md Demonstrates how to use the A2AClient for interacting with agents. This includes creating a client, sending messages, subscribing to streaming responses, retrieving task status, and cancelling tasks. ```java // Create client AgentCard targetAgent = AgentCard.builder() .url("https://target-agent.example.com") .build(); A2AClient client = new A2AClientImpl(targetAgent, new HttpCardResolver()); // Send message MessageSendParams params = MessageSendParams.builder() .message(Message.builder() .role("user") .parts(List.of(TextPart.builder() .text("Hello!") .build())) .build()) .build(); Task task = client.sendTask(params); // Stream messages Flux stream = client.sendTaskSubscribe(params); stream.subscribe( event -> { if (event instanceof TaskStatusUpdateEvent) { // Handle status update } else if (event instanceof TaskArtifactUpdateEvent) { // Handle artifact update } }, error -> System.err.println("Error: " + error), () -> System.out.println("Stream completed") ); // Get task status Task currentTask = client.getTask(TaskQueryParams.builder() .id(task.getId()) .build()); // Cancel task Task cancelledTask = client.cancelTask(TaskIdParams.builder() .id(task.getId()) .build()); ``` -------------------------------- ### Integration Testing A2A Server Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-spring-boot-starter/a2a4j-server-spring-boot-starter/README.md Provides examples for integration testing the A2A server using Spring Boot's TestRestTemplate. It includes tests for fetching the agent's well-known configuration and sending messages via JSON-RPC. ```java @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) class A2AServerIntegrationTest { @Autowired private TestRestTemplate restTemplate; @Test void testAgentCard() { ResponseEntity response = restTemplate.getForEntity( "/.well-known/agent.json", AgentCard.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getName()).isEqualTo("My A2A Agent"); } @Test void testMessageSend() { JSONRPCRequest request = JSONRPCRequest.builder() .method("message/send") .params(MessageSendParams.builder() .message(Message.builder() .role("user") .parts(List.of(TextPart.builder() .text("Hello!") .build())) .build()) .build()) .id("test-1") .build(); ResponseEntity response = restTemplate.postForEntity( "/a2a/server", request, JSONRPCResponse.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(response.getBody().getResult()).isNotNull(); } } ``` -------------------------------- ### Build and Run A2A4J Client Hello World Sample Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-samples/client-hello-world/README.md Commands to clone the repository, build the project using Maven, and run the client-hello-world sample application. This includes building the entire project and then specifically navigating to and running the client sample. ```bash # Clone repository (if you haven't already) git clone https://github.com/a2ap/a2a4j.git cd a2a4j # Build entire project mvn clean install # Navigate to sample directory cd a2a4j-samples/client-hello-world # Run with Maven mvn spring-boot:run # Or run compiled JAR mvn clean package java -jar target/client-hello-world-*.jar ``` -------------------------------- ### Integration Test Example Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-core/README.md An example of an integration test using Spring Boot's TestRestTemplate to send a JSON-RPC message and assert the response. This test verifies the message sending functionality of the A2A server. ```java @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) class A2AIntegrationTest { @Autowired private TestRestTemplate restTemplate; @Test void testMessageSend() { JSONRPCRequest request = JSONRPCRequest.builder() .method("message/send") .params(MessageSendParams.builder() .message(Message.builder() .role("user") .parts(List.of(new TextPart("Hello"))) .build()) .build()) .id("test-1") .build(); ResponseEntity response = restTemplate.postForEntity( "/a2a/server", request, JSONRPCResponse.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(response.getBody().getResult()).isNotNull(); } } ``` -------------------------------- ### Delete Remote Branch Source: https://github.com/a2ap/a2a4j/blob/main/CONTRIBUTING.md Deletes the remote development branch after the code has been merged. ```shell git push origin --delete a-dev-branch ``` -------------------------------- ### Delete Local Branch Source: https://github.com/a2ap/a2a4j/blob/main/CONTRIBUTING.md Deletes the local development branch after the code has been merged. ```shell git branch -d a-dev-branch ``` -------------------------------- ### Build and Run A2A4J Server Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-samples/server-hello-world/README_CN.md Instructions to clone the repository, build the project using Maven, and run the A2A4J server sample. It covers both running with Maven and executing the compiled JAR file. ```Bash # Clone the repository (if you haven't already) git clone https://github.com/a2ap/a2a4j.git cd a2a4j # Build the entire project mvn clean install # Navigate to the sample directory cd a2a4j-samples/server-hello-world # Run with Maven mvn spring-boot:run # Or run the compiled JAR mvn clean package java -jar target/server-hello-world-*.jar ``` -------------------------------- ### Push Changes Source: https://github.com/a2ap/a2a4j/blob/main/CONTRIBUTING.md Pushes the committed changes from the local feature branch to the remote repository. ```shell git push origin a-feature-branch ``` -------------------------------- ### Build and Run A2A4J Server Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-samples/server-hello-world/README.md Commands to clone the repository, build the project using Maven, and run the A2A4J server. It also includes instructions for running the compiled JAR file. ```bash # Clone repository (if you haven't already) git clone https://github.com/a2a4j/a2a4j.git cd a2a4j # Build entire project mvn clean install # Navigate to sample directory cd a2a4j-samples/server-hello-world # Run with Maven mvn spring-boot:run # Or run compiled JAR mvn clean package java -jar target/server-hello-world-*.jar ``` -------------------------------- ### Build and Run Hello World Sample Source: https://github.com/a2ap/a2a4j/blob/main/README_CN.md Instructions for cloning the A2A4J project, building it with Maven, and running the 'server-hello-world' sample application. ```bash git clone https://github.com/a2ap/a2a4j.git cd a2a4j mvn clean install cd a2a4j-samples/server-hello-world mvn spring-boot:run ``` -------------------------------- ### Sync Upstream Repository Source: https://github.com/a2ap/a2a4j/blob/main/CONTRIBUTING.md Synchronizes the local repository with the upstream repository by pulling the latest changes from the main branch. ```shell git remote add upstream https://github.com/a2ap/a2a4j.git #Bind the remote repository, if it has been executed, it does not need to be executed again git checkout main git pull upstream main ``` -------------------------------- ### Get Agent Card Source: https://github.com/a2ap/a2a4j/blob/main/README.md A curl command to retrieve the agent's card information from the running server. ```bash curl http://localhost:8089/.well-known/agent.json ``` -------------------------------- ### Deleting Local and Remote Branches Source: https://github.com/a2ap/a2a4j/blob/main/CONTRIBUTING_CN.md Illustrates the commands to remove a development branch locally and from the remote repository after its changes have been merged. ```shell git branch -d a-dev-branch git push origin --delete a-dev-branch ``` -------------------------------- ### Docker Deployment Configuration Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-samples/server-hello-world/README.md Dockerfile for deploying the A2A Java Server application. It specifies the base image, copies the JAR, exposes the port, and sets the entrypoint. ```dockerfile FROM openjdk:17-jre-slim COPY target/server-hello-world-*.jar app.jar EXPOSE 8089 ENTRYPOINT ["java", "-jar", "/app.jar"] ``` -------------------------------- ### Docker Deployment Dockerfile Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-samples/server-hello-world/README_CN.md A Dockerfile for deploying the A2A Java application. It uses a slim OpenJDK 17 JRE image, copies the application JAR, exposes the application port, and sets the entrypoint to run the JAR. ```dockerfile FROM openjdk:17-jre-slim COPY target/server-hello-world-*.jar app.jar EXPOSE 8089 ENTRYPOINT ["java", "-jar", "/app.jar"] ``` -------------------------------- ### Application Configuration Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-samples/server-hello-world/README_CN.md Configuration options for the A2A server, including port, server details, provider information, capabilities, and skills. This is typically set in the `application.yml` file. ```yaml server: port: 8089 a2a: server: id: "server-hello-world" name: "A2A Java Server" description: "A sample A2A agent implemented in Java" version: "1.0.0" url: "http://localhost:${server.port}/a2a/server" provider: name: "A2AP Team" url: "https://github.com/a2ap" documentationUrl: "https://github.com/a2ap/a2a4j" capabilities: streaming: true pushNotifications: false stateTransitionHistory: true defaultInputModes: - "text" defaultOutputModes: - "text" skills: - name: "hello-world" description: "A simple hello world skill" tags: - "greeting" - "basic" examples: - "Say hello to me" - "Greet me" inputModes: - "text" outputModes: - "text" ``` -------------------------------- ### Spring Boot Application Entry Point Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-spring-boot-starter/a2a4j-server-spring-boot-starter/README.md Standard Spring Boot application class to run the application. ```java @SpringBootApplication public class MyAgentApplication { public static void main(String[] args) { SpringApplication.run(MyAgentApplication.class, args); } } ``` -------------------------------- ### Create Feature Branch Source: https://github.com/a2ap/a2a4j/blob/main/CONTRIBUTING.md Creates a new branch for developing a feature or fixing a bug. It's recommended to use descriptive branch names. ```shell git checkout -b a-feature-branch #Recommended ``` -------------------------------- ### Custom QueueManager Implementation Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-spring-boot-starter/a2a4j-server-spring-boot-starter/STARTER_API.md Example of overriding the default QueueManager with a custom implementation, such as RedisQueueManager, using @Primary annotation. ```java @Configuration public class CustomQueueConfig { @Bean @Primary public QueueManager redisQueueManager(RedisTemplate redisTemplate) { return new RedisQueueManager(redisTemplate); } } ``` -------------------------------- ### Run Spring Boot Application Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-spring-boot-starter/a2a4j-server-spring-boot-starter/README_CN.md Standard Spring Boot application entry point to run the A2A server. ```java @SpringBootApplication public class MyAgentApplication { public static void main(String[] args) { SpringApplication.run(MyAgentApplication.class, args); } } ``` -------------------------------- ### Auto-Configured Components Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-spring-boot-starter/a2a4j-server-spring-boot-starter/README_CN.md Lists the core and supporting components automatically configured by the starter, which can be overridden. ```APIDOC Core Components: - QueueManager: Manages event queues for tasks (default: InMemoryQueueManager). - TaskStore: Stores task data and history (default: InMemoryTaskStore). - TaskManager: Manages task lifecycle (default: InMemoryTaskManager). - AgentExecutor: Executes agent logic (default: no-op implementation). - Dispatcher: Routes JSON-RPC requests (default: DefaultDispatcher). - A2AServer: The main server implementation (default: DefaultA2AServer). Supporting Components: - ObjectMapper: For JSON serialization/deserialization. - AgentCard: Agent metadata based on configuration properties. ``` -------------------------------- ### Concurrent Request Testing Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-samples/server-hello-world/README.md Demonstrates how to test the server's concurrency by sending multiple streaming requests simultaneously using a bash loop and `curl`. The `wait` command ensures all requests are completed before proceeding. ```bash # Start multiple concurrent requests for i in {1..5}; do 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\": \"Concurrent request $i\"}] } }, \"id\": \"concurrent-$i\" }" & done # Wait for all requests to complete wait ``` -------------------------------- ### A2A4J Spring Boot Starters API Source: https://github.com/a2ap/a2a4j/blob/main/README_CN.md Documentation for Spring Boot starters that simplify A2A integration. Includes server and client starters with auto-configuration for endpoints, Agent Card publishing, task management, and more. ```APIDOC A2A4J Spring Boot Starters: a2a4j-server-spring-boot-starter: Provides Spring Boot auto-configuration for A2A servers. Features: - Automatic endpoint configuration. - Agent Card publishing. - Task management. - SSE streaming support. a2a4j-client-spring-boot-starter: Provides Spring Boot auto-configuration for A2A clients. Features: - Agent discovery. - HTTP client configuration. - Reactive client support. ``` -------------------------------- ### Test Concurrent Requests Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-samples/server-hello-world/README_CN.md Demonstrates how to test the server's ability to handle multiple concurrent streaming requests. A loop sends several requests simultaneously and waits for them to complete. ```Bash # Start multiple concurrent requests for i in {1..5}; do 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\": \"并发请求 $i\"}] \ } \ }, \ \"id\": \"concurrent-$i\" \ }" & done # Wait for all requests to complete wait ``` -------------------------------- ### Committing Changes Source: https://github.com/a2ap/a2a4j/blob/main/CONTRIBUTING_CN.md Provides the command for staging changes and committing them with a message that follows the project's convention. This ensures clear and organized commit history. ```shell git add <修改的文件/路径> git commit -m '[docs]feature: 必要的说明' #推荐 ``` -------------------------------- ### Pushing Changes to Remote Source: https://github.com/a2ap/a2a4j/blob/main/CONTRIBUTING_CN.md Shows how to push the local feature branch with committed changes to the remote repository, making them available for creating a Pull Request. ```shell git push origin a-feature-branch ``` -------------------------------- ### Creating a Feature Branch Source: https://github.com/a2ap/a2a4j/blob/main/CONTRIBUTING_CN.md Demonstrates the recommended way to create a new branch for developing a feature or fix. This helps in organizing contributions and managing changes. ```shell git checkout -b a-feature-branch #推荐 ``` -------------------------------- ### TaskPushNotificationConfig Object Source: https://github.com/a2ap/a2a4j/blob/main/specification/specification.md Represents the parameters for setting and the result for getting push notification configurations for a specific task. It links a taskId with PushNotificationConfig details. ```typescript interface TaskPushNotificationConfig { taskId: string; pushNotificationConfig: PushNotificationConfig; } ``` -------------------------------- ### Cloning the Repository Source: https://github.com/a2ap/a2a4j/blob/main/CONTRIBUTING_CN.md This snippet shows how to clone the A2A4J repository from GitHub using SSH. It's a fundamental step for any contributor wanting to work on the project locally. ```shell git clone git@github.com:${YOUR_USERNAME}/a2a4j.git #推荐 ``` -------------------------------- ### Custom Agent Executor Implementation Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-samples/server-hello-world/README.md Java code demonstrating how to implement a custom `AgentExecutor` by extending the `AgentExecutor` interface. This allows for custom agent logic. ```java @Component public class MyCustomExecutor implements AgentExecutor { @Override public Mono execute(RequestContext context, EventQueue eventQueue) { // Implement custom logic return Mono.empty(); } @Override public Mono cancel(String taskId) { // Implement cancellation logic return Mono.empty(); } } ``` -------------------------------- ### Commit Changes Source: https://github.com/a2ap/a2a4j/blob/main/CONTRIBUTING.md Stages changes and commits them with a message following a specific format: '[module name or type name]feature or bugfix or doc: custom message'. ```shell git add git commit -m '[docs]feature: necessary instructions' #Recommended ``` -------------------------------- ### Custom AgentExecutor Implementation Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-spring-boot-starter/a2a4j-server-spring-boot-starter/STARTER_API.md Example of implementing a custom AgentExecutor to handle agent logic, including message processing and task cancellation. ```java @Component public class MyCustomAgentExecutor implements AgentExecutor { @Override public Mono execute(RequestContext context, EventQueue eventQueue) { return Mono.fromRunnable(() -> { // Your custom agent logic here processMessage(context.getMessage(), context.getTaskId(), eventQueue); eventQueue.close(); }); } @Override public Mono cancel(String taskId) { return Mono.fromRunnable(() -> { // Handle cancellation handleTaskCancellation(taskId); }); } private void processMessage(Message message, String taskId, EventQueue eventQueue) { // Implementation details } private void handleTaskCancellation(String taskId) { // Implementation details } } ``` -------------------------------- ### Custom Enhanced A2A Auto-Configuration Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-spring-boot-starter/a2a4j-server-spring-boot-starter/STARTER_API.md An example of custom auto-configuration that extends the starter's functionality. It conditionally registers beans like MessageValidator and AgentSecurityManager. ```java import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import io.github.a2ap.agent.core.AgentExecutor; import io.github.a2ap.agent.core.security.AgentSecurityManager; import io.github.a2ap.agent.core.validation.MessageValidator; import io.github.a2ap.server.spring.auto.configuration.A2AServerAutoConfiguration; // Assuming DefaultMessageValidator and JwtAgentSecurityManager are defined elsewhere // Assuming EnhancedAgentExecutor is defined elsewhere @Configuration @AutoConfigureAfter(A2AServerAutoConfiguration.class) @ConditionalOnProperty(name = "myapp.a2a.enhanced", havingValue = "true") public class EnhancedA2AAutoConfiguration { @Bean @ConditionalOnMissingBean public MessageValidator messageValidator() { return new DefaultMessageValidator(); } @Bean @ConditionalOnMissingBean public AgentSecurityManager securityManager() { return new JwtAgentSecurityManager(); } @Bean public AgentExecutor enhancedAgentExecutor( AgentExecutor delegate, MessageValidator validator, AgentSecurityManager securityManager) { return new EnhancedAgentExecutor(delegate, validator, securityManager); } } ``` -------------------------------- ### A2A Server Configuration Metadata Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-spring-boot-starter/a2a4j-server-spring-boot-starter/STARTER_API.md Provides Spring configuration metadata for the A2A Server starter, enabling IDE support like auto-completion and property validation. ```json { "groups": [ { "name": "a2a.server", "type": "io.github.a2ap.server.spring.auto.configuration.A2AServerProperties", "description": "Configuration properties for A2A Server." } ], "properties": [ { "name": "a2a.server.name", "type": "java.lang.String", "description": "The name of the agent." } ] } ``` -------------------------------- ### A2A Client Java Example Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-core/README_CN.md Demonstrates how to use the A2A4J client in Java to send a message. It initializes the client, creates a message with text content, and sends it as a task. ```java import io.github.a2ap.core.client.A2AClient; import io.github.a2ap.core.client.A2AClientImpl; import io.github.a2ap.core.client.HttpCardResolver; import io.github.a2ap.core.model.Message; import io.github.a2ap.core.model.MessageSendParams; import io.github.a2ap.core.model.TextPart; import io.github.a2ap.core.model.Task; import java.util.List; // Assuming agentCard is obtained elsewhere // AgentCard agentCard = ...; A2AClient client = new A2AClientImpl(agentCard, new HttpCardResolver("http://localhost:8089")); // 发送消息 TextPart textPart = new TextPart(); textPart.setText("Hello from Java client!"); Message message = Message.builder() .role("user") .parts(List.of(textPart)) .build(); MessageSendParams params = MessageSendParams.builder() .message(message) .build(); Task result = client.sendTask(params); ``` -------------------------------- ### A2A Server Auto-Configuration Details Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-spring-boot-starter/a2a4j-server-spring-boot-starter/STARTER_API.md API reference for the A2A Server Auto-Configuration, detailing the auto-configured beans and their implementations. ```APIDOC A2AServerAutoConfiguration: description: The main auto-configuration class that sets up all A2A server components. autoConfigures: - QueueManager: Manages task event queues (default: InMemoryQueueManager) - TaskStore: Stores task data and history (default: InMemoryTaskStore) - TaskManager: Manages task lifecycle (default: InMemoryTaskManager) - ObjectMapper: JSON serialization/deserialization - Dispatcher: Routes JSON-RPC requests (default: DefaultDispatcher) - AgentExecutor: Executes agent logic (default: Anonymous no-op, override required) - AgentCard: Agent metadata (built from properties) - A2AServer: Main server implementation (default: DefaultA2AServer) notes: All beans are created with @ConditionalOnMissingBean, allowing easy override. ``` -------------------------------- ### A2AServerProperties Configuration Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-spring-boot-starter/a2a4j-server-spring-boot-starter/STARTER_API.md Defines the configuration properties for the A2A server, prefixed with 'a2a.server'. Includes settings for agent name, description, version, URL, and capabilities like streaming. ```yaml a2a: server: enabled: true # Enable/disable A2A server name: "My Agent" # Agent name description: "Agent description" # Agent description version: "1.0.0" # Agent version url: "https://agent.example.com" # Agent base URL capabilities: streaming: true # Support streaming responses push-notifications: false # Support push notifications state-transition-history: true # Maintain state history ``` -------------------------------- ### Configurable Properties Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-spring-boot-starter/a2a4j-server-spring-boot-starter/README_CN.md Details the configurable properties for the A2A server, including their types, default values, and descriptions. ```APIDOC a2a.server.enabled (boolean, default: true): Enables or disables the A2A server. a2a.server.name (string): The name of the agent. a2a.server.description (string): The description of the agent. a2a.server.version (string): The version of the agent. a2a.server.url (string): The base URL where the agent is accessible. a2a.server.capabilities.streaming (boolean, default: true): Indicates if the agent supports streaming responses. a2a.server.capabilities.push-notifications (boolean, default: false): Indicates if the agent supports push notifications. a2a.server.capabilities.state-transition-history (boolean, default: true): Indicates if the agent maintains state transition history. ``` -------------------------------- ### Unit Testing Agent Executor Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-spring-boot-starter/a2a4j-server-spring-boot-starter/README.md Demonstrates how to unit test an agent executor using Mockito for mocking dependencies and verifying interactions. It covers setting up mocks, injecting dependencies, and asserting the behavior of the execute method. ```java @ExtendWith(MockitoExtension.class) class MyAgentExecutorTest { @Mock private EventQueue eventQueue; @InjectMocks private MyAgentExecutor agentExecutor; @Test void testExecute() { // Given RequestContext context = RequestContext.builder() .taskId("test-task") .message(Message.builder() .role("user") .parts(List.of(TextPart.builder() .text("Hello, agent!") .build())) .build()) .build(); // When StepVerifier.create(agentExecutor.execute(context, eventQueue)) .verifyComplete(); // Then verify(eventQueue, atLeastOnce()).enqueueEvent(any()); verify(eventQueue).close(); } } ``` -------------------------------- ### Custom Agent Executor Implementation Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-samples/server-hello-world/README_CN.md Java code demonstrating how to implement a custom `AgentExecutor` by extending the `AgentExecutor` interface. This allows for custom logic execution and cancellation within the A2A framework. ```java @Component public class MyCustomExecutor implements AgentExecutor { @Override public Mono execute(RequestContext context, EventQueue eventQueue) { // 实现自定义逻辑 return Mono.empty(); } @Override public Mono cancel(String taskId) { // 实现取消逻辑 return Mono.empty(); } } ``` -------------------------------- ### Echo Agent Implementation Source: https://github.com/a2ap/a2a4j/blob/main/a2a4j-spring-boot-starter/a2a4j-server-spring-boot-starter/README.md A simple implementation of an AgentExecutor that echoes the input message back to the user. It demonstrates how to process incoming messages, create artifact updates, and enqueue events using the EventQueue. ```java @Component public class EchoAgentExecutor implements AgentExecutor { @Override public Mono execute(RequestContext context, EventQueue eventQueue) { return Mono.fromRunnable(() -> { String inputText = extractTextFromMessage(context.getMessage()); TaskArtifactUpdateEvent event = TaskArtifactUpdateEvent.builder() .taskId(context.getTaskId()) .artifact(Artifact.builder() .type("text") .content("Echo: " + inputText) .build()) .build(); eventQueue.enqueueEvent(event); eventQueue.close(); }); } @Override public Mono cancel(String taskId) { return Mono.empty(); } private String extractTextFromMessage(Message message) { return message.getParts().stream() .filter(TextPart.class::isInstance) .map(TextPart.class::cast) .map(TextPart::getText) .collect(Collectors.joining(" ")); } } ``` -------------------------------- ### Agent Executor Implementation Source: https://github.com/a2ap/a2a4j/blob/main/README_CN.md Example Java code for implementing the `AgentExecutor` interface to define the logic for handling agent tasks. This includes processing requests and sending task status updates. ```java @Component public class MyAgentExecutor implements AgentExecutor { @Override public Mono execute(RequestContext context, EventQueue eventQueue) { // 你的智能体逻辑 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(); } } ``` -------------------------------- ### Authenticated Extended Card Retrieval Source: https://github.com/a2ap/a2a4j/blob/main/specification/specification.md Retrieves a detailed Agent Card after client authentication. This endpoint is available if AgentCard.supportsAuthenticatedExtendedCard is true. It's an HTTP GET request relative to the AgentCard's URL. ```APIDOC Endpoint URL: {AgentCard.url}/../agent/authenticatedExtendedCard HTTP Method: GET Authentication: Required, using schemes from AgentCard.securitySchemes and AgentCard.security. Request Params: None (HTTP GET). Response Success: AgentCard object (potentially with additional details). Response Failure: Standard HTTP error codes (401, 403, 404, 5xx). Clients should replace their cached public Agent Card with the response from this endpoint when authenticated. ```