Skip to content

Commit dabd80e

Browse files
feat: introduce TransportProtocol validation for AgentCard and AgentInterface
1 parent aa159f3 commit dabd80e

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

src/a2a/types.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,30 @@ class AgentExtension(A2ABaseModel):
9393
"""
9494

9595

96+
class TransportProtocol(str, Enum):
97+
"""
98+
Supported A2A transport protocols.
99+
"""
100+
101+
jsonrpc = 'JSONRPC'
102+
grpc = 'GRPC'
103+
http_json = 'HTTP+JSON'
104+
105+
96106
class AgentInterface(A2ABaseModel):
97107
"""
98108
Declares a combination of a target URL and a transport protocol for interacting with the agent.
99109
This allows agents to expose the same functionality over multiple transport mechanisms.
100110
"""
101111

102-
transport: str = Field(..., examples=['JSONRPC', 'GRPC', 'HTTP+JSON'])
112+
transport: TransportProtocol = Field(
113+
...,
114+
examples=[
115+
TransportProtocol.jsonrpc,
116+
TransportProtocol.grpc,
117+
TransportProtocol.http_json,
118+
]
119+
)
103120
"""
104121
The transport protocol supported at this URL.
105122
"""
@@ -1020,17 +1037,6 @@ class TextPart(A2ABaseModel):
10201037
The string content of the text part.
10211038
"""
10221039

1023-
1024-
class TransportProtocol(str, Enum):
1025-
"""
1026-
Supported A2A transport protocols.
1027-
"""
1028-
1029-
jsonrpc = 'JSONRPC'
1030-
grpc = 'GRPC'
1031-
http_json = 'HTTP+JSON'
1032-
1033-
10341040
class UnsupportedOperationError(A2ABaseModel):
10351041
"""
10361042
An A2A-specific error indicating that the requested operation is not supported by the agent.
@@ -1774,8 +1780,13 @@ class AgentCard(A2ABaseModel):
17741780
"""
17751781
A human-readable name for the agent.
17761782
"""
1777-
preferred_transport: str | None = Field(
1778-
default='JSONRPC', examples=['JSONRPC', 'GRPC', 'HTTP+JSON']
1783+
preferred_transport: TransportProtocol | None = Field(
1784+
default=TransportProtocol.jsonrpc,
1785+
examples=[
1786+
TransportProtocol.jsonrpc,
1787+
TransportProtocol.grpc,
1788+
TransportProtocol.http_json
1789+
]
17791790
)
17801791
"""
17811792
The transport protocol for the preferred endpoint (the main 'url' field).

0 commit comments

Comments
 (0)