Skip to content

Commit 9c80607

Browse files
committed
feat: Add Javadoc
1 parent 870b82c commit 9c80607

File tree

1 file changed

+248
-14
lines changed

1 file changed

+248
-14
lines changed

spec/src/main/java/io/a2a/spec/AgentCard.java

Lines changed: 248 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,70 @@
99
import io.a2a.util.Assert;
1010

1111
/**
12-
* The AgentCard is a self-describing manifest for an agent. It provides essential
13-
* metadata including the agent's identity, capabilities, skills, supported
14-
* communication methods, and security requirements.
12+
* The AgentCard is a self-describing manifest for an agent in the A2A Protocol.
13+
* <p>
14+
* An AgentCard provides essential metadata about an agent, including its identity, capabilities,
15+
* supported skills, communication methods, and security requirements. It serves as the primary
16+
* discovery mechanism for clients to understand what an agent can do and how to interact with it.
17+
* <p>
18+
* The AgentCard corresponds to the {@code AgentCard} type in the A2A Protocol specification,
19+
* defining the contract between clients and agents for capability advertisement.
20+
* <p>
21+
* This class is immutable and uses the Builder pattern for construction to handle the mix of
22+
* required and optional fields defined by the specification.
23+
*
24+
* @param name the human-readable name of the agent (required)
25+
* @param description a brief description of the agent's purpose and functionality (required)
26+
* @param url the base URL where the agent can be accessed (required)
27+
* @param provider information about the organization or entity providing the agent (optional)
28+
* @param version the version of the agent implementation (required)
29+
* @param documentationUrl URL to human-readable documentation for the agent (optional)
30+
* @param capabilities the capabilities supported by this agent (required)
31+
* @param defaultInputModes list of supported input modes, e.g., "text", "audio" (required)
32+
* @param defaultOutputModes list of supported output modes, e.g., "text", "audio" (required)
33+
* @param skills list of skills that this agent can perform (required)
34+
* @param supportsAuthenticatedExtendedCard whether the agent supports authenticated extended card retrieval (optional, defaults to false)
35+
* @param securitySchemes map of security scheme names to their definitions (optional)
36+
* @param security list of security requirements for accessing the agent (optional)
37+
* @param iconUrl URL to an icon representing the agent (optional)
38+
* @param additionalInterfaces list of additional transport interfaces beyond the primary url/transport (optional)
39+
* @param preferredTransport the preferred transport protocol, e.g., "jsonrpc", "grpc" (defaults to "jsonrpc")
40+
* @param protocolVersion the version of the A2A Protocol this agent implements (defaults to {@link #DEFAULT_PROTOCOL_VERSION})
41+
* @param signatures digital signatures verifying the authenticity of the agent card (optional)
42+
* @see <a href="https://a2a-protocol.org/latest/">A2A Protocol Specification</a>
1543
*/
1644
@JsonInclude(JsonInclude.Include.NON_ABSENT)
1745
@JsonIgnoreProperties(ignoreUnknown = true)
18-
public record AgentCard(String name, String description, String url, AgentProvider provider,
19-
String version, String documentationUrl, AgentCapabilities capabilities,
20-
List<String> defaultInputModes, List<String> defaultOutputModes, List<AgentSkill> skills,
21-
boolean supportsAuthenticatedExtendedCard, Map<String, SecurityScheme> securitySchemes,
22-
List<Map<String, List<String>>> security, String iconUrl, List<AgentInterface> additionalInterfaces,
23-
String preferredTransport, String protocolVersion, List<AgentCardSignature> signatures) {
24-
25-
private static final String DEFAULT_PROTOCOL_VERSION = "0.3.0";
46+
public record AgentCard(
47+
String name,
48+
String description,
49+
String url,
50+
AgentProvider provider,
51+
String version,
52+
String documentationUrl,
53+
AgentCapabilities capabilities,
54+
List<String> defaultInputModes,
55+
List<String> defaultOutputModes,
56+
List<AgentSkill> skills,
57+
boolean supportsAuthenticatedExtendedCard,
58+
Map<String, SecurityScheme> securitySchemes,
59+
List<Map<String, List<String>>> security,
60+
String iconUrl,
61+
List<AgentInterface> additionalInterfaces,
62+
String preferredTransport,
63+
String protocolVersion,
64+
List<AgentCardSignature> signatures) {
65+
66+
/** The default A2A Protocol version used when not explicitly specified. */
67+
public static final String DEFAULT_PROTOCOL_VERSION = "0.3.0";
68+
2669
private static final TransportProtocol DEFAULT_TRANSPORT = TransportProtocol.JSONRPC;
2770

71+
/**
72+
* Compact constructor that validates required fields and sets defaults.
73+
*
74+
* @throws IllegalArgumentException if any required field is null
75+
*/
2876
public AgentCard {
2977
Assert.checkNotNullParam("capabilities", capabilities);
3078
Assert.checkNotNullParam("defaultInputModes", defaultInputModes);
@@ -42,6 +90,35 @@ public record AgentCard(String name, String description, String url, AgentProvid
4290
}
4391
}
4492

93+
/**
94+
* Builder for constructing immutable {@link AgentCard} instances.
95+
* <p>
96+
* The Builder pattern is used to enforce immutability of AgentCard objects while providing
97+
* a fluent API for setting required and optional fields. This approach ensures that once
98+
* an AgentCard is created, its state cannot be modified, which is important for thread-safety
99+
* and protocol correctness.
100+
* <p>
101+
* Example usage:
102+
* <pre>{@code
103+
* AgentCard card = new AgentCard.Builder()
104+
* .name("Weather Agent")
105+
* .description("Provides weather information")
106+
* .url("http://localhost:9999")
107+
* .version("1.0.0")
108+
* .capabilities(new AgentCapabilities.Builder()
109+
* .streaming(true)
110+
* .build())
111+
* .defaultInputModes(List.of("text"))
112+
* .defaultOutputModes(List.of("text"))
113+
* .skills(List.of(
114+
* new AgentSkill.Builder()
115+
* .id("weather_query")
116+
* .name("Weather Queries")
117+
* .build()
118+
* ))
119+
* .build();
120+
* }</pre>
121+
*/
45122
public static class Builder {
46123
private String name;
47124
private String description;
@@ -63,16 +140,19 @@ public static class Builder {
63140
private List<AgentCardSignature> signatures;
64141

65142
/**
66-
* Creates a new Builder.
143+
* Creates a new Builder with all fields unset.
67144
*/
68145
public Builder() {
69146

70147
}
71148

72149
/**
73-
* Creates a new Builder as a copy of an existing AgentCard.
150+
* Creates a new Builder initialized with values from an existing AgentCard.
151+
* <p>
152+
* This constructor creates defensive copies of mutable collections to ensure
153+
* that modifications to the builder do not affect the original AgentCard.
74154
*
75-
* @param card the AgentCard to copy
155+
* @param card the AgentCard to copy values from
76156
*/
77157
public Builder(AgentCard card) {
78158
this.name = card.name;
@@ -95,96 +175,250 @@ public Builder(AgentCard card) {
95175
this.signatures = card.signatures != null ? new ArrayList<>(card.signatures) : null;
96176
}
97177

178+
/**
179+
* Sets the human-readable name of the agent.
180+
*
181+
* @param name the agent name (required)
182+
* @return this builder for method chaining
183+
*/
98184
public Builder name(String name) {
99185
this.name = name;
100186
return this;
101187
}
102188

189+
/**
190+
* Sets a brief description of the agent's purpose and functionality.
191+
*
192+
* @param description the agent description (required)
193+
* @return this builder for method chaining
194+
*/
103195
public Builder description(String description) {
104196
this.description = description;
105197
return this;
106198
}
107199

200+
/**
201+
* Sets the base URL where the agent can be accessed.
202+
*
203+
* @param url the agent URL (required)
204+
* @return this builder for method chaining
205+
*/
108206
public Builder url(String url) {
109207
this.url = url;
110208
return this;
111209
}
112210

211+
/**
212+
* Sets information about the organization or entity providing the agent.
213+
*
214+
* @param provider the agent provider (optional)
215+
* @return this builder for method chaining
216+
*/
113217
public Builder provider(AgentProvider provider) {
114218
this.provider = provider;
115219
return this;
116220
}
117221

222+
/**
223+
* Sets the version of the agent implementation.
224+
*
225+
* @param version the agent version (required)
226+
* @return this builder for method chaining
227+
*/
118228
public Builder version(String version) {
119229
this.version = version;
120230
return this;
121231
}
122232

233+
/**
234+
* Sets the URL to human-readable documentation for the agent.
235+
*
236+
* @param documentationUrl the documentation URL (optional)
237+
* @return this builder for method chaining
238+
*/
123239
public Builder documentationUrl(String documentationUrl) {
124240
this.documentationUrl = documentationUrl;
125241
return this;
126242
}
127243

244+
/**
245+
* Sets the capabilities supported by this agent.
246+
* <p>
247+
* Capabilities define optional features such as streaming responses,
248+
* push notifications, and state transition history.
249+
*
250+
* @param capabilities the agent capabilities (required)
251+
* @return this builder for method chaining
252+
* @see AgentCapabilities
253+
*/
128254
public Builder capabilities(AgentCapabilities capabilities) {
129255
this.capabilities = capabilities;
130256
return this;
131257
}
132258

259+
/**
260+
* Sets the list of supported input modes.
261+
* <p>
262+
* Input modes define the formats the agent can accept, such as "text", "audio", or "image".
263+
*
264+
* @param defaultInputModes the list of input modes (required, must not be empty)
265+
* @return this builder for method chaining
266+
*/
133267
public Builder defaultInputModes(List<String> defaultInputModes) {
134268
this.defaultInputModes = defaultInputModes;
135269
return this;
136270
}
137271

272+
/**
273+
* Sets the list of supported output modes.
274+
* <p>
275+
* Output modes define the formats the agent can produce, such as "text", "audio", or "image".
276+
*
277+
* @param defaultOutputModes the list of output modes (required, must not be empty)
278+
* @return this builder for method chaining
279+
*/
138280
public Builder defaultOutputModes(List<String> defaultOutputModes) {
139281
this.defaultOutputModes = defaultOutputModes;
140282
return this;
141283
}
142284

285+
/**
286+
* Sets the list of skills that this agent can perform.
287+
* <p>
288+
* Skills represent distinct capabilities or operations the agent can execute,
289+
* such as "weather_query" or "language_translation".
290+
*
291+
* @param skills the list of agent skills (required, must not be empty)
292+
* @return this builder for method chaining
293+
* @see AgentSkill
294+
*/
143295
public Builder skills(List<AgentSkill> skills) {
144296
this.skills = skills;
145297
return this;
146298
}
147299

300+
/**
301+
* Sets whether the agent supports authenticated extended card retrieval.
302+
* <p>
303+
* When true, the agent can provide additional information through the
304+
* {@code GetAuthenticatedExtendedCard} method, which may include private
305+
* or user-specific details not in the public card.
306+
*
307+
* @param supportsAuthenticatedExtendedCard true if supported, false otherwise
308+
* @return this builder for method chaining
309+
*/
148310
public Builder supportsAuthenticatedExtendedCard(boolean supportsAuthenticatedExtendedCard) {
149311
this.supportsAuthenticatedExtendedCard = supportsAuthenticatedExtendedCard;
150312
return this;
151313
}
152314

315+
/**
316+
* Sets the map of security scheme definitions.
317+
* <p>
318+
* Security schemes define authentication and authorization methods supported
319+
* by the agent, such as OAuth2, API keys, or HTTP authentication.
320+
*
321+
* @param securitySchemes map of scheme names to definitions (optional)
322+
* @return this builder for method chaining
323+
* @see SecurityScheme
324+
*/
153325
public Builder securitySchemes(Map<String, SecurityScheme> securitySchemes) {
154326
this.securitySchemes = securitySchemes;
155327
return this;
156328
}
157329

330+
/**
331+
* Sets the list of security requirements for accessing the agent.
332+
* <p>
333+
* Each entry in the list represents an alternative security requirement,
334+
* where each map contains scheme names and their required scopes.
335+
*
336+
* @param security the list of security requirements (optional)
337+
* @return this builder for method chaining
338+
*/
158339
public Builder security(List<Map<String, List<String>>> security) {
159340
this.security = security;
160341
return this;
161342
}
162343

344+
/**
345+
* Sets the URL to an icon representing the agent.
346+
*
347+
* @param iconUrl the icon URL (optional)
348+
* @return this builder for method chaining
349+
*/
163350
public Builder iconUrl(String iconUrl) {
164351
this.iconUrl = iconUrl;
165352
return this;
166353
}
167354

355+
/**
356+
* Sets the list of additional transport interfaces.
357+
* <p>
358+
* Additional interfaces allow the agent to be accessed through multiple
359+
* transport protocols beyond the primary url/preferredTransport combination.
360+
*
361+
* @param additionalInterfaces the list of additional interfaces (optional)
362+
* @return this builder for method chaining
363+
* @see AgentInterface
364+
*/
168365
public Builder additionalInterfaces(List<AgentInterface> additionalInterfaces) {
169366
this.additionalInterfaces = additionalInterfaces;
170367
return this;
171368
}
172369

370+
/**
371+
* Sets the preferred transport protocol.
372+
* <p>
373+
* Valid values include "jsonrpc", "grpc", and "rest". If not set, defaults to "jsonrpc".
374+
*
375+
* @param preferredTransport the preferred transport protocol name
376+
* @return this builder for method chaining
377+
* @see TransportProtocol
378+
*/
173379
public Builder preferredTransport(String preferredTransport) {
174380
this.preferredTransport = preferredTransport;
175381
return this;
176382
}
177383

384+
/**
385+
* Sets the version of the A2A Protocol this agent implements.
386+
* <p>
387+
* If not set, defaults to {@link AgentCard#DEFAULT_PROTOCOL_VERSION}.
388+
*
389+
* @param protocolVersion the protocol version string
390+
* @return this builder for method chaining
391+
*/
178392
public Builder protocolVersion(String protocolVersion) {
179393
this.protocolVersion = protocolVersion;
180394
return this;
181395
}
182396

397+
/**
398+
* Sets the digital signatures verifying the authenticity of the agent card.
399+
* <p>
400+
* Signatures provide cryptographic proof that the agent card was issued by
401+
* a trusted authority and has not been tampered with.
402+
*
403+
* @param signatures the list of signatures (optional)
404+
* @return this builder for method chaining
405+
* @see AgentCardSignature
406+
*/
183407
public Builder signatures(List<AgentCardSignature> signatures) {
184408
this.signatures = signatures;
185409
return this;
186410
}
187411

412+
/**
413+
* Builds an immutable {@link AgentCard} from the current builder state.
414+
* <p>
415+
* This method applies default values for optional fields and creates an entry
416+
* in additionalInterfaces matching the primary url and preferredTransport if
417+
* additionalInterfaces was not explicitly set.
418+
*
419+
* @return a new AgentCard instance
420+
* @throws IllegalArgumentException if any required field is null
421+
*/
188422
public AgentCard build() {
189423
if (preferredTransport == null) {
190424
preferredTransport = DEFAULT_TRANSPORT.asString();

0 commit comments

Comments
 (0)