Implementation:A2aproject A2a java AgentCard Builder
| Knowledge Sources | |
|---|---|
| Domains | Spec, Service_Discovery |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Concrete builder for constructing immutable `AgentCard` records that serve as A2A agent capability manifests, provided by the A2A Java SDK spec module.
Description
The `AgentCard.Builder` is a fluent builder for the `AgentCard` Java record. It constructs an immutable, thread-safe agent capability manifest that advertises the agent's name, description, version, capabilities (streaming, push notifications), supported transport interfaces, skills, and security configuration.
The builder enforces required-field validation in the `build()` method via `Assert.checkNotNullParam()`. All collection fields are defensively copied using `CollectionCopies.immutableList()` and `CollectionCopies.immutableNullableMap()` in the record's compact constructor, ensuring the resulting `AgentCard` cannot be mutated after creation.
The `AgentCard` is typically exposed as a CDI bean qualified with `@PublicAgentCard` in a Quarkus application. The framework serves it at the `.well-known/agent-card.json` endpoint for client discovery.
Usage
- Building a server agent: Use the builder to construct the agent's capability manifest, produced as a `@PublicAgentCard` CDI bean.
- Multi-transport agents: List multiple `AgentInterface` entries in `supportedInterfaces`, ordered by preference.
- Cloud deployment: Combine with `@ConfigProperty` to make transport selection configurable via MicroProfile Config.
Code Reference
Source Location
- Repository: a2a-java
- File: `spec/src/main/java/org/a2aproject/sdk/spec/AgentCard.java`
- Lines: L44-439 (record + Builder class)
Signature
public record AgentCard(
String name,
String description,
@Nullable AgentProvider provider,
String version,
@Nullable String documentationUrl,
AgentCapabilities capabilities,
List<String> defaultInputModes,
List<String> defaultOutputModes,
List<AgentSkill> skills,
@Nullable Map<String, SecurityScheme> securitySchemes,
@Nullable List<SecurityRequirement> securityRequirements,
@Nullable String iconUrl,
List<AgentInterface> supportedInterfaces,
@Nullable List<AgentCardSignature> signatures,
@Nullable String url,
@Nullable String preferredTransport,
@Nullable List<Legacy_0_3_AgentInterface> additionalInterfaces
) {
public static Builder builder() { ... }
public static Builder builder(AgentCard card) { ... }
public static class Builder {
public Builder name(String name);
public Builder description(String description);
public Builder provider(AgentProvider provider);
public Builder version(String version);
public Builder documentationUrl(String documentationUrl);
public Builder capabilities(AgentCapabilities capabilities);
public Builder defaultInputModes(List<String> defaultInputModes);
public Builder defaultOutputModes(List<String> defaultOutputModes);
public Builder skills(List<AgentSkill> skills);
public Builder securitySchemes(Map<String, SecurityScheme> securitySchemes);
public Builder securityRequirements(List<SecurityRequirement> securityRequirements);
public Builder iconUrl(String iconUrl);
public Builder supportedInterfaces(List<AgentInterface> supportedInterfaces);
public Builder signatures(List<AgentCardSignature> signatures);
public Builder preferredTransport(String preferredTransport);
public Builder url(String url);
public Builder additionalInterfaces(List<Legacy_0_3_AgentInterface> additionalInterfaces);
public AgentCard build();
}
}
Import
import org.a2aproject.sdk.spec.AgentCard;
import org.a2aproject.sdk.spec.AgentInterface;
import org.a2aproject.sdk.spec.AgentCapabilities;
import org.a2aproject.sdk.spec.AgentSkill;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| name | String | Yes | Human-readable agent name |
| description | String | Yes | Agent purpose description |
| version | String | Yes | Agent implementation version |
| capabilities | AgentCapabilities | Yes | Streaming, push notification, state transition flags |
| defaultInputModes | List<String> | Yes | Accepted input formats (e.g., "text") |
| defaultOutputModes | List<String> | Yes | Produced output formats (e.g., "text") |
| skills | List<AgentSkill> | Yes | Agent skill definitions |
| supportedInterfaces | List<AgentInterface> | Yes | Ordered transport endpoints (first = preferred) |
| provider | AgentProvider | No | Organization providing the agent |
| documentationUrl | String | No | URL to human-readable docs |
| securitySchemes | Map<String, SecurityScheme> | No | Authentication method definitions |
| securityRequirements | List<SecurityRequirement> | No | Security requirements for access |
| iconUrl | String | No | Agent icon URL |
| preferredTransport | String | No | Preferred transport (defaults to "JSONRPC") |
Outputs
| Name | Type | Description |
|---|---|---|
| build() returns | AgentCard | Immutable record, thread-safe, served at .well-known/agent-card.json |
| Validation | IllegalArgumentException | Thrown by build() if required fields are null |
Usage Examples
Basic Hello World Agent Card
import org.a2aproject.sdk.spec.AgentCard;
import org.a2aproject.sdk.spec.AgentCapabilities;
import org.a2aproject.sdk.spec.AgentInterface;
import org.a2aproject.sdk.spec.AgentSkill;
import org.a2aproject.sdk.spec.TransportProtocol;
import java.util.List;
AgentCard card = AgentCard.builder()
.name("Hello World Agent")
.description("Just a hello world agent")
.version("1.0.0")
.supportedInterfaces(List.of(
new AgentInterface("JSONRPC", "http://localhost:9999")))
.capabilities(AgentCapabilities.builder()
.streaming(true)
.pushNotifications(true)
.build())
.defaultInputModes(List.of("text"))
.defaultOutputModes(List.of("text"))
.skills(List.of(AgentSkill.builder()
.id("hello_world")
.name("Returns hello world")
.description("just returns hello world")
.build()))
.build();
Multi-Transport Agent Card
// First interface is the agent's preferred transport
AgentCard card = AgentCard.builder()
.name("Multi-Transport Agent")
.description("Supports JSON-RPC and gRPC")
.version("2.0.0")
.supportedInterfaces(List.of(
new AgentInterface("GRPC", "localhost:9000"),
new AgentInterface("JSONRPC", "http://localhost:9999")))
.capabilities(AgentCapabilities.builder()
.streaming(true)
.build())
.defaultInputModes(List.of("text"))
.defaultOutputModes(List.of("text"))
.skills(List.of())
.build();
CDI Producer for Quarkus
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;
import org.a2aproject.sdk.server.PublicAgentCard;
@ApplicationScoped
public class AgentCardProducer {
@Produces
@PublicAgentCard
public AgentCard agentCard() {
return AgentCard.builder()
.name("My Agent")
.description("Description here")
.version("1.0.0")
.supportedInterfaces(List.of(
new AgentInterface("JSONRPC", "http://localhost:9999")))
.capabilities(AgentCapabilities.builder().build())
.defaultInputModes(List.of("text"))
.defaultOutputModes(List.of("text"))
.skills(List.of())
.build();
}
}