Skip to content

Commit 920f97f

Browse files
added extended_agent_card route
1 parent 8902bf7 commit 920f97f

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ def __init__(
4949
def build(
5050
self,
5151
agent_card_url: str = '/.well-known/agent.json',
52+
extended_agent_card_url: str = '/agent/authenticatedExtendedCard',
5253
rpc_url: str = '/',
5354
**kwargs: Any,
5455
) -> FastAPI:
5556
"""Builds and returns the FastAPI application instance.
5657
5758
Args:
5859
agent_card_url: The URL for the agent card endpoint.
59-
rpc_url: The URL for the A2A JSON-RPC endpoint
60+
rpc_url: The URL for the A2A JSON-RPC endpoint.
61+
extended_agent_card_url: The URL for the authenticated extended agent card endpoint.
6062
**kwargs: Additional keyword arguments to pass to the FastAPI constructor.
6163
6264
Returns:
@@ -71,5 +73,10 @@ async def handle_a2a_request(request: Request):
7173
@app.get(agent_card_url)
7274
async def get_agent_card(request: Request):
7375
return await self._handle_get_agent_card(request)
76+
77+
if self.agent_card.supportsAuthenticatedExtendedCard:
78+
@app.get(extended_agent_card_url)
79+
async def get_extended_agent_card(request: Request):
80+
return await self._handle_get_authenticated_extended_agent_card(request)
7481

7582
return app

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,20 @@ def __init__(
5050
def routes(
5151
self,
5252
agent_card_url: str = '/.well-known/agent.json',
53+
extended_agent_card_url: str = '/agent/authenticatedExtendedCard',
5354
rpc_url: str = '/',
5455
) -> list[Route]:
5556
"""Returns the Starlette Routes for handling A2A requests.
5657
5758
Args:
5859
agent_card_url: The URL path for the agent card endpoint.
5960
rpc_url: The URL path for the A2A JSON-RPC endpoint (POST requests).
61+
extended_agent_card_url: The URL for the authenticated extended agent card endpoint.
6062
6163
Returns:
6264
A list of Starlette Route objects.
6365
"""
64-
return [
66+
app_routes = [
6567
Route(
6668
rpc_url,
6769
self._handle_requests,
@@ -76,9 +78,21 @@ def routes(
7678
),
7779
]
7880

81+
if self.agent_card.supportsAuthenticatedExtendedCard:
82+
app_routes.append(
83+
Route(
84+
extended_agent_card_url,
85+
self._handle_get_authenticated_extended_agent_card,
86+
methods=['GET'],
87+
name='authenticated_extended_agent_card',
88+
)
89+
)
90+
return app_routes
91+
7992
def build(
8093
self,
8194
agent_card_url: str = '/.well-known/agent.json',
95+
extended_agent_card_url: str = '/agent/authenticatedExtendedCard',
8296
rpc_url: str = '/',
8397
**kwargs: Any,
8498
) -> Starlette:
@@ -87,16 +101,19 @@ def build(
87101
Args:
88102
agent_card_url: The URL path for the agent card endpoint.
89103
rpc_url: The URL path for the A2A JSON-RPC endpoint (POST requests).
104+
extended_agent_card_url: The URL for the authenticated extended agent card endpoint.
90105
**kwargs: Additional keyword arguments to pass to the Starlette
91106
constructor.
92107
93108
Returns:
94109
A configured Starlette application instance.
95110
"""
96-
routes = self.routes(agent_card_url, rpc_url)
111+
app_routes = self.routes(
112+
agent_card_url, extended_agent_card_url, rpc_url
113+
)
97114
if 'routes' in kwargs:
98-
kwargs['routes'] += routes
115+
kwargs['routes'].extend(app_routes)
99116
else:
100-
kwargs['routes'] = routes
117+
kwargs['routes'] = app_routes
101118

102119
return Starlette(**kwargs)

tests/server/test_integration.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,25 +132,15 @@ def handler():
132132

133133

134134
@pytest.fixture
135-
def starlette_app(agent_card: AgentCard, handler: mock.AsyncMock):
135+
def app(agent_card: AgentCard, handler: mock.AsyncMock):
136136
return A2AStarletteApplication(agent_card, handler)
137137

138138
@pytest.fixture
139-
def starlette_client(app: A2AStarletteApplication, **kwargs):
139+
def client(app: A2AStarletteApplication, **kwargs):
140140
"""Create a test client with the Starlette app."""
141141
return TestClient(app.build(**kwargs))
142142

143143

144-
@pytest.fixture
145-
def fastapi_app(agent_card: AgentCard, handler: mock.AsyncMock):
146-
return A2AFastAPIApplication(agent_card, handler)
147-
148-
@pytest.fixture
149-
def fastapi_client(app: A2AFastAPIApplication, **kwargs):
150-
"""Create a test client with the FastAPI app."""
151-
return TestClient(app.build(**kwargs))
152-
153-
154144
# === BASIC FUNCTIONALITY TESTS ===
155145

156146

@@ -164,7 +154,7 @@ def test_agent_card_endpoint(client: TestClient, agent_card: AgentCard):
164154
assert 'streaming' in data['capabilities']
165155

166156

167-
def test_authenticated_extended_agent_card_endpoint_not_supported_starlette(
157+
def test_authenticated_extended_agent_card_endpoint_not_supported(
168158
agent_card: AgentCard, handler: mock.AsyncMock
169159
):
170160
"""Test extended card endpoint returns 404 if not supported by main card."""
@@ -200,6 +190,7 @@ def test_authenticated_extended_agent_card_endpoint_supported_with_specific_exte
200190
agent_card.supportsAuthenticatedExtendedCard = (
201191
True # Main card must support it
202192
)
193+
print(agent_card)
203194
app_instance = A2AStarletteApplication(
204195
agent_card, handler, extended_agent_card=extended_agent_card_fixture
205196
)

0 commit comments

Comments
 (0)