-
Notifications
You must be signed in to change notification settings - Fork 147
fix: preserve tenant and protocolVersion from AgentInterface in ClientBuilder #773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ehsavoie
merged 2 commits into
a2aproject:main
from
Lirons01:issue-772-tenant-not-preserved-in-client-builder
Apr 1, 2026
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| package io.a2a.client; | ||
|
|
||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
|
|
@@ -24,26 +23,71 @@ public class ClientBuilderTest { | |
|
|
||
| private AgentCard card = AgentCard.builder() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this whole agent cards building could be simplified in a helper method ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea, this looks cleaner now with the helper method IMO |
||
| .name("Hello World Agent") | ||
| .description("Just a hello world agent") | ||
| .version("1.0.0") | ||
| .documentationUrl("http://example.com/docs") | ||
| .capabilities(AgentCapabilities.builder() | ||
| .streaming(true) | ||
| .pushNotifications(true) | ||
| .build()) | ||
| .description("Just a hello world agent") | ||
| .version("1.0.0") | ||
| .documentationUrl("http://example.com/docs") | ||
| .capabilities(AgentCapabilities.builder() | ||
| .streaming(true) | ||
| .pushNotifications(true) | ||
| .build()) | ||
| .defaultInputModes(Collections.singletonList("text")) | ||
| .defaultOutputModes(Collections.singletonList("text")) | ||
| .skills(Collections.singletonList(AgentSkill.builder() | ||
| .id("hello_world") | ||
| .name("Returns hello world") | ||
| .description("just returns hello world") | ||
| .tags(Collections.singletonList("hello world")) | ||
| .examples(List.of("hi", "hello world")) | ||
| .build())) | ||
| .id("hello_world") | ||
| .name("Returns hello world") | ||
| .description("just returns hello world") | ||
| .tags(Collections.singletonList("hello world")) | ||
| .examples(List.of("hi", "hello world")) | ||
| .build())) | ||
| .supportedInterfaces(List.of( | ||
| new AgentInterface(TransportProtocol.JSONRPC.asString(), "http://localhost:9999"))) | ||
| .build(); | ||
|
|
||
| private AgentCard cardWithTenant = AgentCard.builder() | ||
| .name("Hello World Agent") | ||
| .description("Just a hello world agent") | ||
| .version("1.0.0") | ||
| .documentationUrl("http://example.com/docs") | ||
| .capabilities(AgentCapabilities.builder() | ||
| .streaming(true) | ||
| .pushNotifications(true) | ||
| .build()) | ||
| .defaultInputModes(Collections.singletonList("text")) | ||
| .defaultOutputModes(Collections.singletonList("text")) | ||
| .skills(Collections.singletonList(AgentSkill.builder() | ||
| .id("hello_world") | ||
| .name("Returns hello world") | ||
| .description("just returns hello world") | ||
| .tags(Collections.singletonList("hello world")) | ||
| .examples(List.of("hi", "hello world")) | ||
| .build())) | ||
| .supportedInterfaces(List.of( | ||
| new AgentInterface(TransportProtocol.JSONRPC.asString(), "http://localhost:9999", "/default-tenant"))) | ||
| .build(); | ||
|
|
||
| private AgentCard cardWithMultipleInterfaces = AgentCard.builder() | ||
| .name("Multi-Interface Agent") | ||
| .description("Agent with multiple interfaces") | ||
| .version("1.0.0") | ||
| .documentationUrl("http://example.com/docs") | ||
| .capabilities(AgentCapabilities.builder() | ||
| .streaming(true) | ||
| .pushNotifications(true) | ||
| .build()) | ||
| .defaultInputModes(Collections.singletonList("text")) | ||
| .defaultOutputModes(Collections.singletonList("text")) | ||
| .skills(Collections.singletonList(AgentSkill.builder() | ||
| .id("hello_world") | ||
| .name("Returns hello world") | ||
| .description("just returns hello world") | ||
| .tags(Collections.singletonList("hello world")) | ||
| .examples(List.of("hi", "hello world")) | ||
| .build())) | ||
| .supportedInterfaces(List.of( | ||
| new AgentInterface(TransportProtocol.GRPC.asString(), "http://localhost:9998", "/grpc-tenant", "1.0"), | ||
| new AgentInterface(TransportProtocol.JSONRPC.asString(), "http://localhost:9999", "/jsonrpc-tenant", "1.0"))) | ||
| .build(); | ||
|
|
||
| @Test | ||
| public void shouldNotFindCompatibleTransport() throws A2AClientException { | ||
| A2AClientException exception = Assertions.assertThrows(A2AClientException.class, | ||
|
|
@@ -91,4 +135,75 @@ public void shouldCreateClient_differentConfigurations() throws A2AClientExcepti | |
|
|
||
| Assertions.assertNotNull(client); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldPreserveTenantFromAgentInterface() throws A2AClientException { | ||
| ClientBuilder builder = Client | ||
| .builder(cardWithTenant) | ||
| .withTransport(JSONRPCTransport.class, new JSONRPCTransportConfigBuilder()); | ||
|
|
||
| AgentInterface selectedInterface = builder.findBestClientTransport(); | ||
|
|
||
| Assertions.assertEquals("/default-tenant", selectedInterface.tenant()); | ||
| Assertions.assertEquals("http://localhost:9999", selectedInterface.url()); | ||
| Assertions.assertEquals(TransportProtocol.JSONRPC.asString(), selectedInterface.protocolBinding()); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldPreserveProtocolVersionFromAgentInterface() throws A2AClientException { | ||
| ClientBuilder builder = Client | ||
| .builder(cardWithMultipleInterfaces) | ||
| .withTransport(JSONRPCTransport.class, new JSONRPCTransportConfigBuilder()); | ||
|
|
||
| AgentInterface selectedInterface = builder.findBestClientTransport(); | ||
|
|
||
| Assertions.assertEquals("/jsonrpc-tenant", selectedInterface.tenant()); | ||
| Assertions.assertEquals("1.0", selectedInterface.protocolVersion()); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldSelectCorrectInterfaceWithServerPreference() throws A2AClientException { | ||
| // Server preference (default): iterates server interfaces in order, picks first that client supports | ||
| // cardWithMultipleInterfaces has [GRPC, JSONRPC] - GRPC is first | ||
| // Client supports both GRPC and JSONRPC, so GRPC should be selected (server's first choice) | ||
| ClientBuilder builder = Client | ||
| .builder(cardWithMultipleInterfaces) | ||
| .withTransport(GrpcTransport.class, new GrpcTransportConfigBuilder().channelFactory(s -> null)) | ||
| .withTransport(JSONRPCTransport.class, new JSONRPCTransportConfigBuilder()); | ||
|
|
||
| AgentInterface selectedInterface = builder.findBestClientTransport(); | ||
|
|
||
| Assertions.assertEquals(TransportProtocol.GRPC.asString(), selectedInterface.protocolBinding()); | ||
| Assertions.assertEquals("http://localhost:9998", selectedInterface.url()); | ||
| Assertions.assertEquals("/grpc-tenant", selectedInterface.tenant()); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldSelectCorrectInterfaceWithClientPreference() throws A2AClientException { | ||
| // Client preference: iterates client transports in registration order, picks first that server supports | ||
| // Client registers [JSONRPC, GRPC] - JSONRPC is first | ||
| // Server supports both, so JSONRPC should be selected (client's first choice) | ||
| ClientBuilder builder = Client | ||
| .builder(cardWithMultipleInterfaces) | ||
| .clientConfig(new ClientConfig.Builder().setUseClientPreference(true).build()) | ||
| .withTransport(JSONRPCTransport.class, new JSONRPCTransportConfigBuilder()) | ||
| .withTransport(GrpcTransport.class, new GrpcTransportConfigBuilder().channelFactory(s -> null)); | ||
|
|
||
| AgentInterface selectedInterface = builder.findBestClientTransport(); | ||
|
|
||
| Assertions.assertEquals(TransportProtocol.JSONRPC.asString(), selectedInterface.protocolBinding()); | ||
| Assertions.assertEquals("http://localhost:9999", selectedInterface.url()); | ||
| Assertions.assertEquals("/jsonrpc-tenant", selectedInterface.tenant()); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldPreserveEmptyTenant() throws A2AClientException { | ||
| ClientBuilder builder = Client | ||
| .builder(card) | ||
| .withTransport(JSONRPCTransport.class, new JSONRPCTransportConfigBuilder()); | ||
|
|
||
| AgentInterface selectedInterface = builder.findBestClientTransport(); | ||
|
|
||
| Assertions.assertEquals("", selectedInterface.tenant()); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.