Skip to content

Commit 7297aaa

Browse files
committed
feat: Add an optional tenant parameter to the getExtendedAgentCard operation
this fixes #608 Signed-off-by: Jeff Mesnil <jmesnil@ibm.com>
1 parent 4aa7107 commit 7297aaa

9 files changed

Lines changed: 72 additions & 20 deletions

File tree

‎client/base/src/main/java/io/a2a/client/AbstractClient.java‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,17 +390,41 @@ public abstract void subscribeToTask(@NonNull TaskIdParams request,
390390
* @throws A2AClientException if retrieving the extended agent card fails for any reason
391391
*/
392392
public AgentCard getExtendedAgentCard() throws A2AClientException {
393-
return getExtendedAgentCard(null);
393+
return getExtendedAgentCard(null, null);
394394
}
395395

396396
/**
397397
* Retrieve the extended AgentCard.
398398
*
399+
* @param tenant Optional tenant
400+
* @return the extended AgentCard
401+
* @throws A2AClientException if retrieving the extended agent card fails for any reason
402+
*/
403+
public AgentCard getExtendedAgentCard(@Nullable String tenant) throws A2AClientException {
404+
return getExtendedAgentCard(tenant, null);
405+
}
406+
407+
/**
408+
* Retrieve the extended AgentCard.
409+
*
410+
* @param context optional client call context for the request (may be {@code null})
411+
* @return the extended AgentCard
412+
* @throws A2AClientException if retrieving the extended agent card fails for any reason
413+
*/
414+
public AgentCard getExtendedAgentCard(@Nullable ClientCallContext context) throws A2AClientException {
415+
return getExtendedAgentCard(null, context);
416+
}
417+
418+
/**
419+
* Retrieve the extended AgentCard.
420+
*
421+
* @param tenant Optional tenant
399422
* @param context optional client call context for the request (may be {@code null})
400423
* @return the extended AgentCard
401424
* @throws A2AClientException if retrieving the extended agent card fails for any reason
402425
*/
403-
public abstract AgentCard getExtendedAgentCard(@Nullable ClientCallContext context) throws A2AClientException;
426+
public abstract AgentCard getExtendedAgentCard(@Nullable String tenant,
427+
@Nullable ClientCallContext context) throws A2AClientException;
404428

405429
/**
406430
* Close the transport and release any associated resources.

‎client/base/src/main/java/io/a2a/client/Client.java‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import io.a2a.spec.AgentCard;
1818
import io.a2a.spec.DeleteTaskPushNotificationConfigParams;
1919
import io.a2a.spec.EventKind;
20+
import io.a2a.spec.GetExtendedAgentCardParams;
2021
import io.a2a.spec.GetTaskPushNotificationConfigParams;
2122
import io.a2a.spec.ListTaskPushNotificationConfigParams;
2223
import io.a2a.spec.ListTaskPushNotificationConfigResult;
@@ -601,19 +602,21 @@ public void subscribeToTask(@NonNull TaskIdParams request,
601602
* <p>
602603
* Example:
603604
* <pre>{@code
604-
* AgentCard updatedCard = client.getExtendedAgentCard(null);
605+
* AgentCard updatedCard = client.getExtendedAgentCard();
605606
* System.out.println("Agent version: " + updatedCard.version());
606607
* System.out.println("Skills: " + updatedCard.skills().size());
607608
* }</pre>
608609
*
610+
* @param tenant Optional tenant
609611
* @param context custom call context for request interceptors (optional)
610612
* @return the agent's extended agent card
611613
* @throws A2AClientException if the extended agent card cannot be retrieved
612614
* @see AgentCard
613615
*/
614616
@Override
615-
public AgentCard getExtendedAgentCard(@Nullable ClientCallContext context) throws A2AClientException {
616-
agentCard = clientTransport.getExtendedAgentCard(context);
617+
public AgentCard getExtendedAgentCard(@Nullable String tenant, @Nullable ClientCallContext context) throws A2AClientException {
618+
GetExtendedAgentCardParams params = new GetExtendedAgentCardParams(tenant);
619+
agentCard = clientTransport.getExtendedAgentCard(params, context);
617620
return agentCard;
618621
}
619622

‎client/transport/grpc/src/main/java/io/a2a/client/transport/grpc/GrpcTransport.java‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import io.a2a.spec.AgentCard;
3636
import io.a2a.spec.DeleteTaskPushNotificationConfigParams;
3737
import io.a2a.spec.EventKind;
38+
import io.a2a.spec.GetExtendedAgentCardParams;
3839
import io.a2a.spec.GetTaskPushNotificationConfigParams;
3940
import io.a2a.spec.ListTaskPushNotificationConfigParams;
4041
import io.a2a.spec.ListTaskPushNotificationConfigResult;
@@ -356,9 +357,12 @@ private MessageSendParams createRequestWithTenant(MessageSendParams request) {
356357
}
357358

358359
@Override
359-
public AgentCard getExtendedAgentCard(@Nullable ClientCallContext context) throws A2AClientException {
360-
GetExtendedAgentCardRequest request = GetExtendedAgentCardRequest.newBuilder()
361-
.build();
360+
public AgentCard getExtendedAgentCard(GetExtendedAgentCardParams params, @Nullable ClientCallContext context) throws A2AClientException {
361+
GetExtendedAgentCardRequest.Builder builder = GetExtendedAgentCardRequest.newBuilder();
362+
if (params.tenant() != null) {
363+
builder.setTenant(params.tenant());
364+
}
365+
GetExtendedAgentCardRequest request = builder.build();
362366
PayloadAndHeaders payloadAndHeaders = applyInterceptors(GET_EXTENDED_AGENT_CARD_METHOD, request, agentCard, context);
363367

364368
try {

‎client/transport/jsonrpc/src/main/java/io/a2a/client/transport/jsonrpc/JSONRPCTransport.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import io.a2a.spec.AgentInterface;
5252
import io.a2a.spec.DeleteTaskPushNotificationConfigParams;
5353
import io.a2a.spec.EventKind;
54+
import io.a2a.spec.GetExtendedAgentCardParams;
5455
import io.a2a.spec.GetTaskPushNotificationConfigParams;
5556
import io.a2a.spec.ListTaskPushNotificationConfigParams;
5657
import io.a2a.spec.ListTaskPushNotificationConfigResult;
@@ -284,13 +285,13 @@ public void subscribeToTask(TaskIdParams request, Consumer<StreamingEventKind> e
284285
}
285286

286287
@Override
287-
public AgentCard getExtendedAgentCard(@Nullable ClientCallContext context) throws A2AClientException {
288+
public AgentCard getExtendedAgentCard(GetExtendedAgentCardParams params, @Nullable ClientCallContext context) throws A2AClientException {
288289
try {
289290
PayloadAndHeaders payloadAndHeaders = applyInterceptors(GET_EXTENDED_AGENT_CARD_METHOD,
290-
ProtoUtils.ToProto.extendedAgentCard(), agentCard, context);
291+
ProtoUtils.ToProto.extendedAgentCard(params), agentCard, context);
291292

292293
try {
293-
String httpResponseBody = sendPostRequest(Utils.buildBaseUrl(agentInterface, ""), payloadAndHeaders, GET_EXTENDED_AGENT_CARD_METHOD);
294+
String httpResponseBody = sendPostRequest(Utils.buildBaseUrl(agentInterface, params.tenant()), payloadAndHeaders, GET_EXTENDED_AGENT_CARD_METHOD);
294295
GetExtendedAgentCardResponse response = unmarshalResponse(httpResponseBody, GET_EXTENDED_AGENT_CARD_METHOD);
295296
return response.getResult();
296297
} catch (IOException | InterruptedException | JsonProcessingException e) {

‎client/transport/jsonrpc/src/test/java/io/a2a/client/transport/jsonrpc/JSONRPCTransportTest.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import io.a2a.spec.FilePart;
5151
import io.a2a.spec.FileWithBytes;
5252
import io.a2a.spec.FileWithUri;
53+
import io.a2a.spec.GetExtendedAgentCardParams;
5354
import io.a2a.spec.GetTaskPushNotificationConfigParams;
5455
import io.a2a.spec.Message;
5556
import io.a2a.spec.MessageSendConfiguration;
@@ -361,7 +362,8 @@ public void testA2AClientGetExtendedAgentCard() throws Exception {
361362
);
362363

363364
JSONRPCTransport client = new JSONRPCTransport("http://localhost:4001");
364-
AgentCard agentCard = client.getExtendedAgentCard(null);
365+
GetExtendedAgentCardParams params = new GetExtendedAgentCardParams(null);
366+
AgentCard agentCard = client.getExtendedAgentCard(params, null);
365367
assertEquals("GeoSpatial Route Planner Agent Extended", agentCard.name());
366368
assertEquals("Extended description", agentCard.description());
367369
assertEquals("https://georoute-agent.example.com/a2a/v1", Utils.getFavoriteInterface(agentCard).url());

‎client/transport/rest/src/main/java/io/a2a/client/transport/rest/RestTransport.java‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import io.a2a.spec.AgentInterface;
4646
import io.a2a.spec.DeleteTaskPushNotificationConfigParams;
4747
import io.a2a.spec.EventKind;
48+
import io.a2a.spec.GetExtendedAgentCardParams;
4849
import io.a2a.spec.GetTaskPushNotificationConfigParams;
4950
import io.a2a.spec.ListTaskPushNotificationConfigParams;
5051
import io.a2a.spec.ListTaskPushNotificationConfigResult;
@@ -414,15 +415,13 @@ public void subscribeToTask(TaskIdParams request, Consumer<StreamingEventKind> e
414415
}
415416

416417
@Override
417-
public AgentCard getExtendedAgentCard(@Nullable ClientCallContext context) throws A2AClientException {
418+
public AgentCard getExtendedAgentCard(GetExtendedAgentCardParams params, @Nullable ClientCallContext context) throws A2AClientException {
418419
try {
419420
PayloadAndHeaders payloadAndHeaders = applyInterceptors(GET_EXTENDED_AGENT_CARD_METHOD, null, agentCard, context);
420-
String url = Utils.buildBaseUrl(agentInterface, "") + "/extendedAgentCard";
421+
String url = Utils.buildBaseUrl(agentInterface, params.tenant()) + "/extendedAgentCard";
421422
A2AHttpClient.GetBuilder getBuilder = httpClient.createGet().url(url);
422-
if (payloadAndHeaders.getHeaders() != null) {
423-
for (Map.Entry<String, String> entry : payloadAndHeaders.getHeaders().entrySet()) {
423+
for (Map.Entry<String, String> entry : payloadAndHeaders.getHeaders().entrySet()) {
424424
getBuilder.addHeader(entry.getKey(), entry.getValue());
425-
}
426425
}
427426
A2AHttpResponse response = getBuilder.get();
428427
if (!response.success()) {

‎client/transport/spi/src/main/java/io/a2a/client/transport/spi/ClientTransport.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.a2a.spec.AgentCard;
99
import io.a2a.spec.DeleteTaskPushNotificationConfigParams;
1010
import io.a2a.spec.EventKind;
11+
import io.a2a.spec.GetExtendedAgentCardParams;
1112
import io.a2a.spec.GetTaskPushNotificationConfigParams;
1213
import io.a2a.spec.ListTaskPushNotificationConfigParams;
1314
import io.a2a.spec.ListTaskPushNotificationConfigResult;
@@ -139,11 +140,12 @@ void subscribeToTask(TaskIdParams request, Consumer<StreamingEventKind> eventCon
139140
/**
140141
* Retrieve the extended AgentCard.
141142
*
143+
* @param params the parameters to get the extended agent card.
142144
* @param context optional client call context for the request (may be {@code null})
143145
* @return the extended agent card
144146
* @throws A2AClientException if retrieving the agent card fails for any reason
145147
*/
146-
AgentCard getExtendedAgentCard(@Nullable ClientCallContext context) throws A2AClientException;
148+
AgentCard getExtendedAgentCard(GetExtendedAgentCardParams params, @Nullable ClientCallContext context) throws A2AClientException;
147149

148150
/**
149151
* Close the transport and release any associated resources.

‎spec-grpc/src/main/java/io/a2a/grpc/utils/ProtoUtils.java‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import io.a2a.spec.AgentCard;
2828
import io.a2a.spec.DeleteTaskPushNotificationConfigParams;
2929
import io.a2a.spec.EventKind;
30+
import io.a2a.spec.GetExtendedAgentCardParams;
3031
import io.a2a.spec.GetTaskPushNotificationConfigParams;
3132
import io.a2a.spec.InvalidParamsError;
3233
import io.a2a.spec.ListTaskPushNotificationConfigParams;
@@ -55,8 +56,12 @@ public static io.a2a.grpc.AgentCard agentCard(AgentCard agentCard) {
5556
return AgentCardMapper.INSTANCE.toProto(agentCard);
5657
}
5758

58-
public static io.a2a.grpc.GetExtendedAgentCardRequest extendedAgentCard() {
59-
return GetExtendedAgentCardRequest.newBuilder().build();
59+
public static io.a2a.grpc.GetExtendedAgentCardRequest extendedAgentCard(GetExtendedAgentCardParams params) {
60+
GetExtendedAgentCardRequest.Builder builder = GetExtendedAgentCardRequest.newBuilder();
61+
if (params.tenant() != null) {
62+
builder.setTenant(params.tenant());
63+
}
64+
return builder.build();
6065
}
6166

6267
public static io.a2a.grpc.GetTaskRequest getTaskRequest(TaskQueryParams params) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.a2a.spec;
2+
3+
import org.jspecify.annotations.Nullable;
4+
5+
/**
6+
* Parameters to get the extended agent card.
7+
*
8+
* @param tenant optional tenant, provided as a path parameter.
9+
* @see <a href="https://a2a-protocol.org/latest/">A2A Protocol Specification</a>
10+
*/
11+
public record GetExtendedAgentCardParams(@Nullable String tenant) {
12+
}

0 commit comments

Comments
 (0)