11import json
22import logging
33import traceback
4+
45from collections .abc import AsyncGenerator
56from typing import Any
67
3738)
3839from a2a .utils .errors import MethodNotImplementedError
3940
41+
4042logger = 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 :
0 commit comments