From dabd80e8551da76f0b4d219ea55ed12feb940495 Mon Sep 17 00:00:00 2001 From: martimfasantos Date: Fri, 31 Oct 2025 11:53:10 +0000 Subject: [PATCH 1/3] feat: introduce TransportProtocol validation for AgentCard and AgentInterface --- src/a2a/types.py | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/a2a/types.py b/src/a2a/types.py index 918a06b5..efd0ec4c 100644 --- a/src/a2a/types.py +++ b/src/a2a/types.py @@ -93,13 +93,30 @@ class AgentExtension(A2ABaseModel): """ +class TransportProtocol(str, Enum): + """ + Supported A2A transport protocols. + """ + + jsonrpc = 'JSONRPC' + grpc = 'GRPC' + http_json = 'HTTP+JSON' + + class AgentInterface(A2ABaseModel): """ Declares a combination of a target URL and a transport protocol for interacting with the agent. This allows agents to expose the same functionality over multiple transport mechanisms. """ - transport: str = Field(..., examples=['JSONRPC', 'GRPC', 'HTTP+JSON']) + transport: TransportProtocol = Field( + ..., + examples=[ + TransportProtocol.jsonrpc, + TransportProtocol.grpc, + TransportProtocol.http_json, + ] + ) """ The transport protocol supported at this URL. """ @@ -1020,17 +1037,6 @@ class TextPart(A2ABaseModel): The string content of the text part. """ - -class TransportProtocol(str, Enum): - """ - Supported A2A transport protocols. - """ - - jsonrpc = 'JSONRPC' - grpc = 'GRPC' - http_json = 'HTTP+JSON' - - class UnsupportedOperationError(A2ABaseModel): """ An A2A-specific error indicating that the requested operation is not supported by the agent. @@ -1774,8 +1780,13 @@ class AgentCard(A2ABaseModel): """ A human-readable name for the agent. """ - preferred_transport: str | None = Field( - default='JSONRPC', examples=['JSONRPC', 'GRPC', 'HTTP+JSON'] + preferred_transport: TransportProtocol | None = Field( + default=TransportProtocol.jsonrpc, + examples=[ + TransportProtocol.jsonrpc, + TransportProtocol.grpc, + TransportProtocol.http_json + ] ) """ The transport protocol for the preferred endpoint (the main 'url' field). From 09db309cc2303797ead13eabb31642693b167fe2 Mon Sep 17 00:00:00 2001 From: martimfasantos Date: Fri, 31 Oct 2025 12:07:19 +0000 Subject: [PATCH 2/3] formatting --- src/a2a/types.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/a2a/types.py b/src/a2a/types.py index efd0ec4c..e9ab5508 100644 --- a/src/a2a/types.py +++ b/src/a2a/types.py @@ -110,12 +110,12 @@ class AgentInterface(A2ABaseModel): """ transport: TransportProtocol = Field( - ..., + ..., examples=[ - TransportProtocol.jsonrpc, - TransportProtocol.grpc, + TransportProtocol.jsonrpc, + TransportProtocol.grpc, TransportProtocol.http_json, - ] + ], ) """ The transport protocol supported at this URL. @@ -1037,6 +1037,7 @@ class TextPart(A2ABaseModel): The string content of the text part. """ + class UnsupportedOperationError(A2ABaseModel): """ An A2A-specific error indicating that the requested operation is not supported by the agent. @@ -1781,12 +1782,12 @@ class AgentCard(A2ABaseModel): A human-readable name for the agent. """ preferred_transport: TransportProtocol | None = Field( - default=TransportProtocol.jsonrpc, + default=TransportProtocol.jsonrpc, examples=[ - TransportProtocol.jsonrpc, - TransportProtocol.grpc, - TransportProtocol.http_json - ] + TransportProtocol.jsonrpc, + TransportProtocol.grpc, + TransportProtocol.http_json, + ], ) """ The transport protocol for the preferred endpoint (the main 'url' field). From c7182b1b6a9df80e34623d69ae6452293366eb3c Mon Sep 17 00:00:00 2001 From: martimfasantos Date: Fri, 31 Oct 2025 15:43:54 +0000 Subject: [PATCH 3/3] fix: update TransportProtocol enum values to uppercase for Python consistency --- src/a2a/types.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/a2a/types.py b/src/a2a/types.py index e9ab5508..f154cada 100644 --- a/src/a2a/types.py +++ b/src/a2a/types.py @@ -98,9 +98,9 @@ class TransportProtocol(str, Enum): Supported A2A transport protocols. """ - jsonrpc = 'JSONRPC' - grpc = 'GRPC' - http_json = 'HTTP+JSON' + JSONRPC = 'JSONRPC' + GRPC = 'GRPC' + HTTP_JSON = 'HTTP+JSON' class AgentInterface(A2ABaseModel): @@ -112,9 +112,9 @@ class AgentInterface(A2ABaseModel): transport: TransportProtocol = Field( ..., examples=[ - TransportProtocol.jsonrpc, - TransportProtocol.grpc, - TransportProtocol.http_json, + TransportProtocol.JSONRPC, + TransportProtocol.GRPC, + TransportProtocol.HTTP_JSON, ], ) """ @@ -1782,11 +1782,11 @@ class AgentCard(A2ABaseModel): A human-readable name for the agent. """ preferred_transport: TransportProtocol | None = Field( - default=TransportProtocol.jsonrpc, + default=TransportProtocol.JSONRPC, examples=[ - TransportProtocol.jsonrpc, - TransportProtocol.grpc, - TransportProtocol.http_json, + TransportProtocol.JSONRPC, + TransportProtocol.GRPC, + TransportProtocol.HTTP_JSON, ], ) """