Skip to content

Commit 1221aa9

Browse files
committed
Formatting
1 parent a2fb4aa commit 1221aa9

File tree

4 files changed

+63
-32
lines changed

4 files changed

+63
-32
lines changed

examples/helloworld/__main__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
from a2a.server.apps import A2AStarletteApplication
66
from a2a.server.request_handlers import DefaultRequestHandler
77
from a2a.server.tasks import InMemoryTaskStore
8-
from a2a.types import AgentCapabilities, AgentCard, AgentSkill
8+
from a2a.types import (
9+
AgentAuthentication,
10+
AgentCapabilities,
11+
AgentCard,
12+
AgentSkill,
13+
)
14+
915

1016
if __name__ == '__main__':
1117
skill = AgentSkill(
@@ -32,7 +38,7 @@
3238
defaultInputModes=['text'],
3339
defaultOutputModes=['text'],
3440
capabilities=AgentCapabilities(streaming=True),
35-
skills=[skill, extended_skill], # Include both skills
41+
skills=[skill, extended_skill], # Include both skills
3642
authentication=AgentAuthentication(schemes=['public']),
3743
# Adding this line to enable extended card support:
3844
supportsAuthenticatedExtendedCard=True,

src/a2a/client/client.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import json
2-
import logging
2+
33
from collections.abc import AsyncGenerator
44
from typing import Any
55
from uuid import uuid4
66

77
import httpx
8+
89
from httpx_sse import SSEError, aconnect_sse
910

1011
from a2a.client.errors import A2AClientHTTPError, A2AClientJSONError
@@ -53,7 +54,10 @@ async def get_agent_card(
5354
)
5455
response.raise_for_status()
5556
public_agent_card_data = response.json()
56-
logger.info("Successfully fetched public agent card data: %s", public_agent_card_data) # Added for verbosity
57+
logger.info(
58+
'Successfully fetched public agent card data: %s',
59+
public_agent_card_data,
60+
) # Added for verbosity
5761
# print(f"DEBUG: Fetched public agent card data:\n{json.dumps(public_agent_card_data, indent=2)}") # Added for direct output
5862
agent_card = AgentCard.model_validate(public_agent_card_data)
5963
except httpx.HTTPStatusError as e:
@@ -77,9 +81,9 @@ async def get_agent_card(
7781
# The extended card URL is relative to the agent's base URL specified *in* the agent card.
7882
if not agent_card.url:
7983
logger.warning(
80-
"Agent card (from %s) indicates support for an extended card "
84+
'Agent card (from %s) indicates support for an extended card '
8185
"but does not specify its own base 'url' field. "
82-
"Cannot fetch extended card. Proceeding with public card.",
86+
'Cannot fetch extended card. Proceeding with public card.',
8387
public_card_url,
8488
)
8589
return agent_card
@@ -102,19 +106,30 @@ async def get_agent_card(
102106
)
103107
extended_response.raise_for_status()
104108
extended_agent_card_data = extended_response.json()
105-
logger.info("Successfully fetched extended agent card data: %s", extended_agent_card_data) # Added for verbosity
106-
print(f"DEBUG: Fetched extended agent card data:\n{json.dumps(extended_agent_card_data, indent=2)}") # Added for direct output
109+
logger.info(
110+
'Successfully fetched extended agent card data: %s',
111+
extended_agent_card_data,
112+
) # Added for verbosity
113+
print(
114+
f'DEBUG: Fetched extended agent card data:\n{json.dumps(extended_agent_card_data, indent=2)}'
115+
) # Added for direct output
107116
# This new card data replaces the old one entirely
108117
agent_card = AgentCard.model_validate(extended_agent_card_data)
109118
logger.info(
110119
'Successfully fetched and using extended agent card from %s',
111120
full_extended_card_url,
112121
)
113-
except (httpx.HTTPStatusError, httpx.RequestError, json.JSONDecodeError, ValidationError) as e:
122+
except (
123+
httpx.HTTPStatusError,
124+
httpx.RequestError,
125+
json.JSONDecodeError,
126+
ValidationError,
127+
) as e:
114128
logger.warning(
115129
'Failed to fetch or parse extended agent card from %s. Error: %s. '
116130
'Proceeding with the initially fetched public agent card.',
117-
full_extended_card_url, e
131+
full_extended_card_url,
132+
e,
118133
)
119134
# Fallback to the already parsed public_agent_card (which is 'agent_card' at this point)
120135

src/a2a/server/apps/starlette_app.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import logging
33
import traceback
4+
45
from collections.abc import AsyncGenerator
56
from typing import Any
67

@@ -37,6 +38,7 @@
3738
)
3839
from a2a.utils.errors import MethodNotImplementedError
3940

41+
4042
logger = logging.getLogger(__name__)
4143

4244

@@ -202,7 +204,7 @@ async def _process_non_streaming_request(
202204
def _create_response(
203205
self,
204206
handler_result: (
205-
AsyncGenerator[SendStreamingMessageResponse, None]
207+
AsyncGenerator[SendStreamingMessageResponse]
206208
| JSONRPCErrorResponse
207209
| JSONRPCResponse
208210
),
@@ -225,8 +227,8 @@ def _create_response(
225227
if isinstance(handler_result, AsyncGenerator):
226228
# Result is a stream of SendStreamingMessageResponse objects
227229
async def event_generator(
228-
stream: AsyncGenerator[SendStreamingMessageResponse, None],
229-
) -> AsyncGenerator[dict[str, str], None]:
230+
stream: AsyncGenerator[SendStreamingMessageResponse],
231+
) -> AsyncGenerator[dict[str, str]]:
230232
async for item in stream:
231233
yield {'data': item.root.model_dump_json(exclude_none=True)}
232234

@@ -247,29 +249,35 @@ async def _handle_get_agent_card(self, request: Request) -> JSONResponse:
247249
"""Handles GET requests for the agent card."""
248250
# Construct the public view of the agent card.
249251
public_card_data = {
250-
"version": self.agent_card.version,
251-
"name": self.agent_card.name,
252-
"providerName": self.agent_card.provider.organization if self.agent_card.provider else None,
253-
"url": self.agent_card.url,
254-
"authentication": self.agent_card.authentication.model_dump(mode='json', exclude_none=True)
255-
if self.agent_card.authentication else None, # authentication is a single object, can be None if made Optional
256-
"skills": [
252+
'version': self.agent_card.version,
253+
'name': self.agent_card.name,
254+
'providerName': self.agent_card.provider.organization
255+
if self.agent_card.provider
256+
else None,
257+
'url': self.agent_card.url,
258+
'authentication': self.agent_card.authentication.model_dump(
259+
mode='json', exclude_none=True
260+
)
261+
if self.agent_card.authentication
262+
else None, # authentication is a single object, can be None if made Optional
263+
'skills': [
257264
f.model_dump(mode='json', exclude_none=True)
258-
for f in self.agent_card.skills if f.id == 'hello_world' # Explicitly filter for public skills
265+
for f in self.agent_card.skills
266+
if f.id == 'hello_world' # Explicitly filter for public skills
259267
]
260268
if self.agent_card.skills
261-
else [], # Default to empty list if no skills
262-
"capabilities": self.agent_card.capabilities.model_dump(
269+
else [], # Default to empty list if no skills
270+
'capabilities': self.agent_card.capabilities.model_dump(
263271
mode='json', exclude_none=True
264272
),
265-
"supportsAuthenticatedExtendedCard": (
273+
'supportsAuthenticatedExtendedCard': (
266274
self.agent_card.supportsAuthenticatedExtendedCard
267275
),
268276
# Include other fields from types.py AgentCard designated as public
269-
"description": self.agent_card.description,
270-
"documentationUrl": self.agent_card.documentationUrl,
271-
"defaultInputModes": self.agent_card.defaultInputModes,
272-
"defaultOutputModes": self.agent_card.defaultOutputModes,
277+
'description': self.agent_card.description,
278+
'documentationUrl': self.agent_card.documentationUrl,
279+
'defaultInputModes': self.agent_card.defaultInputModes,
280+
'defaultOutputModes': self.agent_card.defaultOutputModes,
273281
}
274282
# Filter out None values from the public card data.
275283
public_card_data_cleaned = {
@@ -283,7 +291,7 @@ async def _handle_get_authenticated_extended_agent_card(
283291
"""Handles GET requests for the authenticated extended agent card."""
284292
if not self.agent_card.supportsAuthenticatedExtendedCard:
285293
return JSONResponse(
286-
{"error": "Extended agent card not supported or not enabled."},
294+
{'error': 'Extended agent card not supported or not enabled.'},
287295
status_code=404,
288296
)
289297

@@ -357,7 +365,9 @@ def build(
357365
Returns:
358366
A configured Starlette application instance.
359367
"""
360-
app_routes = self.routes(agent_card_url, extended_agent_card_url, rpc_url)
368+
app_routes = self.routes(
369+
agent_card_url, extended_agent_card_url, rpc_url
370+
)
361371
if 'routes' in kwargs:
362372
kwargs['routes'].extend(app_routes)
363373
else:

src/a2a/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from __future__ import annotations
55

66
from enum import Enum
7-
from typing import Any, Literal, Optional
7+
from typing import Any, Literal
88

99
from pydantic import BaseModel, Field, RootModel
1010

@@ -1408,7 +1408,7 @@ class AgentCard(BaseModel):
14081408
"""
14091409
The version of the agent - format is up to the provider.
14101410
"""
1411-
supportsAuthenticatedExtendedCard: Optional[bool] = Field(default=None)
1411+
supportsAuthenticatedExtendedCard: bool | None = Field(default=None)
14121412
"""
14131413
Optional field indicating there is an extended card available post authentication at the /agent/authenticatedExtendedCard endpoint.
14141414
"""

0 commit comments

Comments
 (0)