|
6 | 6 | from enum import Enum |
7 | 7 | from typing import Any, Literal |
8 | 8 |
|
9 | | -from pydantic import Field, RootModel |
| 9 | +from pydantic import AnyUrl, Field, RootModel |
10 | 10 |
|
11 | 11 | from a2a._base import A2ABaseModel |
12 | 12 |
|
@@ -75,16 +75,23 @@ class AgentExtension(A2ABaseModel): |
75 | 75 | class AgentInterface(A2ABaseModel): |
76 | 76 | """ |
77 | 77 | Declares a combination of a target URL and a transport protocol for interacting with the agent. |
| 78 | + This allows agents to expose the same functionality over multiple transport mechanisms. |
78 | 79 | """ |
79 | 80 |
|
80 | | - transport: str |
| 81 | + transport: str = Field(..., examples=['JSONRPC', 'GRPC', 'HTTP+JSON']) |
81 | 82 | """ |
82 | | - The transport protocol supported at this URL. This is a string to allow for future |
83 | | - extension. Core supported transports include 'JSONRPC', 'GRPC', and 'HTTP+JSON'. |
| 83 | + The transport protocol supported at this URL. |
84 | 84 | """ |
85 | | - url: str |
| 85 | + url: AnyUrl = Field( |
| 86 | + ..., |
| 87 | + examples=[ |
| 88 | + 'https://api.example.com/a2a/v1', |
| 89 | + 'https://grpc.example.com/a2a', |
| 90 | + 'https://rest.example.com/v1', |
| 91 | + ], |
| 92 | + ) |
86 | 93 | """ |
87 | | - The URL where this interface is available. |
| 94 | + The URL where this interface is available. Must be a valid absolute HTTPS URL in production. |
88 | 95 | """ |
89 | 96 |
|
90 | 97 |
|
@@ -928,6 +935,16 @@ class TextPart(A2ABaseModel): |
928 | 935 | """ |
929 | 936 |
|
930 | 937 |
|
| 938 | +class TransportProtocol(str, Enum): |
| 939 | + """ |
| 940 | + Supported A2A transport protocols. |
| 941 | + """ |
| 942 | + |
| 943 | + jsonrpc = 'JSONRPC' |
| 944 | + grpc = 'GRPC' |
| 945 | + http_json = 'HTTP+JSON' |
| 946 | + |
| 947 | + |
931 | 948 | class UnsupportedOperationError(A2ABaseModel): |
932 | 949 | """ |
933 | 950 | An A2A-specific error indicating that the requested operation is not supported by the agent. |
@@ -1615,7 +1632,16 @@ class AgentCard(A2ABaseModel): |
1615 | 1632 | additional_interfaces: list[AgentInterface] | None = None |
1616 | 1633 | """ |
1617 | 1634 | A list of additional supported interfaces (transport and URL combinations). |
1618 | | - A client can use any of these to communicate with the agent. |
| 1635 | + This allows agents to expose multiple transports, potentially at different URLs. |
| 1636 | +
|
| 1637 | + Best practices: |
| 1638 | + - SHOULD include all supported transports for completeness |
| 1639 | + - SHOULD include an entry matching the main 'url' and 'preferredTransport' |
| 1640 | + - MAY reuse URLs if multiple transports are available at the same endpoint |
| 1641 | + - MUST accurately declare the transport available at each URL |
| 1642 | +
|
| 1643 | + Clients can select any interface from this list based on their transport capabilities |
| 1644 | + and preferences. This enables transport negotiation and fallback scenarios. |
1619 | 1645 | """ |
1620 | 1646 | capabilities: AgentCapabilities |
1621 | 1647 | """ |
@@ -1650,9 +1676,16 @@ class AgentCard(A2ABaseModel): |
1650 | 1676 | """ |
1651 | 1677 | A human-readable name for the agent. |
1652 | 1678 | """ |
1653 | | - preferred_transport: str | None = None |
| 1679 | + preferred_transport: str | None = Field( |
| 1680 | + default='JSONRPC', examples=['JSONRPC', 'GRPC', 'HTTP+JSON'] |
| 1681 | + ) |
1654 | 1682 | """ |
1655 | | - The transport protocol for the preferred endpoint. Defaults to 'JSONRPC' if not specified. |
| 1683 | + The transport protocol for the preferred endpoint (the main 'url' field). |
| 1684 | + If not specified, defaults to 'JSONRPC'. |
| 1685 | +
|
| 1686 | + IMPORTANT: The transport specified here MUST be available at the main 'url'. |
| 1687 | + This creates a binding between the main URL and its supported transport protocol. |
| 1688 | + Clients should prefer this transport and URL combination when both are supported. |
1656 | 1689 | """ |
1657 | 1690 | protocol_version: str | None = '0.2.6' |
1658 | 1691 | """ |
@@ -1681,9 +1714,10 @@ class AgentCard(A2ABaseModel): |
1681 | 1714 | If true, the agent can provide an extended agent card with additional details |
1682 | 1715 | to authenticated users. Defaults to false. |
1683 | 1716 | """ |
1684 | | - url: str |
| 1717 | + url: AnyUrl = Field(..., examples=['https://api.example.com/a2a/v1']) |
1685 | 1718 | """ |
1686 | 1719 | The preferred endpoint URL for interacting with the agent. |
| 1720 | + This URL MUST support the transport specified by 'preferredTransport'. |
1687 | 1721 | """ |
1688 | 1722 | version: str = Field(..., examples=['1.0.0']) |
1689 | 1723 | """ |
|
0 commit comments