feat!: Support for serving agent card at deprecated path (#352) · a2aproject/a2a-python@2444034 · GitHub
Skip to content

Commit 2444034

Browse files
authored
feat!: Support for serving agent card at deprecated path (#352)
Adds support for continuing to serve agent card at `/.well-known/agent.json` when the default agent card location changes to `/.well-known/agent-card.json` Release-As: 0.3.0
1 parent f22e479 commit 2444034

7 files changed

Lines changed: 109 additions & 18 deletions

File tree

‎src/a2a/server/apps/jsonrpc/fastapi_app.py‎

Lines changed: 7 additions & 0 deletions

‎src/a2a/server/apps/jsonrpc/jsonrpc_app.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
AGENT_CARD_WELL_KNOWN_PATH,
5353
DEFAULT_RPC_URL,
5454
EXTENDED_AGENT_CARD_PATH,
55+
PREV_AGENT_CARD_WELL_KNOWN_PATH,
5556
)
5657
from a2a.utils.errors import MethodNotImplementedError
5758

@@ -436,6 +437,15 @@ async def _handle_get_agent_card(self, request: Request) -> JSONResponse:
436437
)
437438
)
438439

440+
async def handle_deprecated_agent_card_path(
441+
self, request: Request
442+
) -> JSONResponse:
443+
"""Handles GET requests for the deprecated agent card endpoint."""
444+
logger.warning(
445+
f"Deprecated agent card endpoint '{PREV_AGENT_CARD_WELL_KNOWN_PATH}' accessed. Please use '{AGENT_CARD_WELL_KNOWN_PATH}' instead. This endpoint will be removed in a future version."
446+
)
447+
return await self._handle_get_agent_card(request)
448+
439449
async def _handle_get_authenticated_extended_agent_card(
440450
self, request: Request
441451
) -> JSONResponse:

‎src/a2a/server/apps/jsonrpc/starlette_app.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
AGENT_CARD_WELL_KNOWN_PATH,
1616
DEFAULT_RPC_URL,
1717
EXTENDED_AGENT_CARD_PATH,
18+
PREV_AGENT_CARD_WELL_KNOWN_PATH,
1819
)
1920

2021

@@ -86,6 +87,17 @@ def routes(
8687
),
8788
]
8889

90+
# add deprecated path only if the agent_card_url uses default well-known path
91+
if agent_card_url == AGENT_CARD_WELL_KNOWN_PATH:
92+
app_routes.append(
93+
Route(
94+
PREV_AGENT_CARD_WELL_KNOWN_PATH,
95+
self.handle_deprecated_agent_card_path,
96+
methods=['GET'],
97+
name='agent_card_path_deprecated',
98+
)
99+
)
100+
89101
if self.agent_card.supports_authenticated_extended_card:
90102
app_routes.append(
91103
Route(

‎src/a2a/utils/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
AGENT_CARD_WELL_KNOWN_PATH,
1010
DEFAULT_RPC_URL,
1111
EXTENDED_AGENT_CARD_PATH,
12+
PREV_AGENT_CARD_WELL_KNOWN_PATH,
1213
)
1314
from a2a.utils.helpers import (
1415
append_artifact_to_task,
@@ -34,6 +35,7 @@
3435
'AGENT_CARD_WELL_KNOWN_PATH',
3536
'DEFAULT_RPC_URL',
3637
'EXTENDED_AGENT_CARD_PATH',
38+
'PREV_AGENT_CARD_WELL_KNOWN_PATH',
3739
'append_artifact_to_task',
3840
'are_modalities_compatible',
3941
'build_text_artifact',

‎src/a2a/utils/constants.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Constants for well-known URIs used throughout the A2A Python SDK."""
22

3-
AGENT_CARD_WELL_KNOWN_PATH = '/.well-known/agent.json'
3+
AGENT_CARD_WELL_KNOWN_PATH = '/.well-known/agent-card.json'
4+
PREV_AGENT_CARD_WELL_KNOWN_PATH = '/.well-known/agent.json'
45
EXTENDED_AGENT_CARD_PATH = '/agent/authenticatedExtendedCard'
56
DEFAULT_RPC_URL = '/'

‎tests/client/test_client.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
TaskPushNotificationConfig,
4949
TaskQueryParams,
5050
)
51+
from a2a.utils import AGENT_CARD_WELL_KNOWN_PATH
5152

5253

5354
AGENT_CARD = AgentCard(
@@ -128,7 +129,7 @@ async def async_iterable_from_list(
128129

129130
class TestA2ACardResolver:
130131
BASE_URL = 'http://example.com'
131-
AGENT_CARD_PATH = '/.well-known/agent.json'
132+
AGENT_CARD_PATH = AGENT_CARD_WELL_KNOWN_PATH
132133
FULL_AGENT_CARD_URL = f'{BASE_URL}{AGENT_CARD_PATH}'
133134
EXTENDED_AGENT_CARD_PATH = (
134135
'/agent/authenticatedExtendedCard' # Default path
@@ -154,7 +155,10 @@ async def test_init_parameters_stored_correctly(
154155
httpx_client=mock_httpx_client,
155156
base_url=base_url,
156157
)
157-
assert resolver_default_path.agent_card_path == '.well-known/agent.json'
158+
assert (
159+
'/' + resolver_default_path.agent_card_path
160+
== AGENT_CARD_WELL_KNOWN_PATH
161+
)
158162

159163
@pytest.mark.asyncio
160164
async def test_init_strips_slashes(self, mock_httpx_client: AsyncMock):

‎tests/server/test_integration.py‎

Lines changed: 70 additions & 15 deletions

0 commit comments

Comments
 (0)