@@ -37,7 +37,12 @@ public class AgentCardWrapper {
3737
3838 private static final String JSONRPC_TRANSPORT = TransportProtocol .JSONRPC .asString ();
3939
40- private AgentCard agentCard ;
40+ private static final String LEGACY_PROTOCOL_VERSION = "0.3" ;
41+
42+ private volatile AgentCard agentCard ;
43+
44+ public record AgentEndpoint (String url , String protocolBinding , String protocolVersion , String tenant ) {
45+ }
4146
4247 public AgentCardWrapper (AgentCard agentCard ) {
4348 this .agentCard = agentCard ;
@@ -52,7 +57,7 @@ public String description() {
5257 }
5358
5459 public String url () {
55- return preferredInterface ().url ();
60+ return endpoint ().url ();
5661 }
5762
5863 public AgentProvider provider () {
@@ -111,16 +116,28 @@ public List<AgentInterface> additionalInterfaces() {
111116 }
112117 return this .agentCard .additionalInterfaces ()
113118 .stream ()
114- .map (agentInterface -> new AgentInterface (agentInterface .transport (), agentInterface .url ()))
119+ .map (agentInterface -> legacyInterface (agentInterface .transport (), agentInterface .url ()))
115120 .toList ();
116121 }
117122
118123 public String preferredTransport () {
119- return preferredInterface ().protocolBinding ();
124+ return endpoint ().protocolBinding ();
120125 }
121126
122127 public String protocolVersion () {
123- return preferredInterface ().protocolVersion ();
128+ return endpoint ().protocolVersion ();
129+ }
130+
131+ public String tenant () {
132+ return endpoint ().tenant ();
133+ }
134+
135+ /**
136+ * Select the endpoint once so callers can build and send a request from one
137+ * immutable agent-card snapshot.
138+ */
139+ public AgentEndpoint endpoint () {
140+ return preferredEndpoint (this .agentCard );
124141 }
125142
126143 public AgentCard getAgentCard () {
@@ -131,27 +148,36 @@ public void setAgentCard(AgentCard agentCard) {
131148 this .agentCard = agentCard ;
132149 }
133150
134- private AgentInterface preferredInterface () {
135- List <AgentInterface > supportedInterfaces = this .agentCard .supportedInterfaces ();
151+ protected final AgentEndpoint preferredEndpoint (AgentCard agentCard ) {
152+ AgentInterface agentInterface = preferredInterface (agentCard );
153+ String protocolVersion = agentInterface .protocolVersion ();
154+ if (protocolVersion == null || protocolVersion .isBlank ()) {
155+ throw new IllegalStateException ("JSONRPC interface does not declare a protocol version" );
156+ }
157+ return new AgentEndpoint (agentInterface .url (), agentInterface .protocolBinding (), protocolVersion ,
158+ agentInterface .tenant ());
159+ }
160+
161+ private AgentInterface preferredInterface (AgentCard agentCard ) {
162+ List <AgentInterface > supportedInterfaces = agentCard .supportedInterfaces ();
136163 if (supportedInterfaces != null ) {
137164 for (AgentInterface agentInterface : supportedInterfaces ) {
138165 if (agentInterface != null && isJsonRpc (agentInterface .protocolBinding ())) {
139166 return agentInterface ;
140167 }
141168 }
142169 }
143- if (this .agentCard .url () != null ) {
144- String transport = this .agentCard .preferredTransport () == null ? JSONRPC_TRANSPORT
145- : this .agentCard .preferredTransport ();
170+ if (agentCard .url () != null ) {
171+ String transport = agentCard .preferredTransport () == null ? JSONRPC_TRANSPORT : agentCard .preferredTransport ();
146172 if (isJsonRpc (transport )) {
147- return new AgentInterface (transport , this . agentCard .url ());
173+ return legacyInterface (transport , agentCard .url ());
148174 }
149175 }
150- List <Legacy_0_3_AgentInterface > additionalInterfaces = this . agentCard .additionalInterfaces ();
176+ List <Legacy_0_3_AgentInterface > additionalInterfaces = agentCard .additionalInterfaces ();
151177 if (additionalInterfaces != null ) {
152178 for (Legacy_0_3_AgentInterface agentInterface : additionalInterfaces ) {
153179 if (agentInterface != null && isJsonRpc (agentInterface .transport ())) {
154- return new AgentInterface (agentInterface .transport (), agentInterface .url ());
180+ return legacyInterface (agentInterface .transport (), agentInterface .url ());
155181 }
156182 }
157183 }
@@ -161,4 +187,8 @@ private AgentInterface preferredInterface() {
161187 private boolean isJsonRpc (String transport ) {
162188 return transport != null && JSONRPC_TRANSPORT .equalsIgnoreCase (transport );
163189 }
190+
191+ private AgentInterface legacyInterface (String transport , String url ) {
192+ return new AgentInterface (transport , url , null , LEGACY_PROTOCOL_VERSION );
193+ }
164194}
0 commit comments