@@ -34,15 +34,23 @@ class A2AStarletteApplication:
3434 (SSE).
3535 """
3636
37- def __init__ (self , agent_card : AgentCard , http_handler : RequestHandler ):
37+ def __init__ (
38+ self ,
39+ agent_card : AgentCard ,
40+ http_handler : RequestHandler ,
41+ extended_agent_card : AgentCard | None = None ,
42+ ):
3843 """Initializes the A2AStarletteApplication.
3944
4045 Args:
4146 agent_card: The AgentCard describing the agent's capabilities.
4247 http_handler: The handler instance responsible for processing A2A
4348 requests via http.
49+ extended_agent_card: An optional, distinct AgentCard to be served
50+ at the authenticated extended card endpoint.
4451 """
4552 self .agent_card = agent_card
53+ self .extended_agent_card = extended_agent_card
4654 self .handler = JSONRPCHandler (
4755 agent_card = agent_card , request_handler = http_handler
4856 )
@@ -264,44 +272,11 @@ async def _handle_get_agent_card(self, request: Request) -> JSONResponse:
264272 Returns:
265273 A JSONResponse containing the agent card data.
266274 """
267-
268- # Construct the public view of the agent card.
269- public_card_data = {
270- 'version' : self .agent_card .version ,
271- 'name' : self .agent_card .name ,
272- 'providerName' : self .agent_card .provider .organization
273- if self .agent_card .provider
274- else None ,
275- 'url' : self .agent_card .url ,
276- 'authentication' : self .agent_card .authentication .model_dump (
277- mode = 'json' , exclude_none = True
278- )
279- if self .agent_card .authentication
280- else None , # authentication is a single object, can be None if made Optional
281- 'skills' : [
282- f .model_dump (mode = 'json' , exclude_none = True )
283- for f in self .agent_card .skills
284- if f .id == 'hello_world' # Explicitly filter for public skills
285- ]
286- if self .agent_card .skills
287- else [], # Default to empty list if no skills
288- 'capabilities' : self .agent_card .capabilities .model_dump (
289- mode = 'json' , exclude_none = True
290- ),
291- 'supportsAuthenticatedExtendedCard' : (
292- self .agent_card .supportsAuthenticatedExtendedCard
293- ),
294- # Include other fields from types.py AgentCard designated as public
295- 'description' : self .agent_card .description ,
296- 'documentationUrl' : self .agent_card .documentationUrl ,
297- 'defaultInputModes' : self .agent_card .defaultInputModes ,
298- 'defaultOutputModes' : self .agent_card .defaultOutputModes ,
299- }
300- # Filter out None values from the public card data.
301- public_card_data_cleaned = {
302- k : v for k , v in public_card_data .items () if v is not None
303- }
304- return JSONResponse (public_card_data_cleaned )
275+ # The public agent card is a direct serialization of the agent_card
276+ # provided at initialization.
277+ return JSONResponse (
278+ self .agent_card .model_dump (mode = 'json' , exclude_none = True )
279+ )
305280
306281 async def _handle_get_authenticated_extended_agent_card (
307282 self , request : Request
@@ -313,11 +288,15 @@ async def _handle_get_authenticated_extended_agent_card(
313288 status_code = 404 ,
314289 )
315290
316- # Authentication and authorization are NOT YET IMPLEMENTED for this endpoint.
317- # As per current requirements, if 'supportsAuthenticatedExtendedCard' is true,
318- # this endpoint returns the complete agent card.
319- # In the future, proper authentication checks will be added here, and the
320- # returned card may be filtered based on the client's authorization scopes.
291+ # If an explicit extended_agent_card is provided, serve that.
292+ if self .extended_agent_card :
293+ return JSONResponse (
294+ self .extended_agent_card .model_dump (
295+ mode = 'json' , exclude_none = True
296+ )
297+ )
298+ # Otherwise, if supportsAuthenticatedExtendedCard is true but no specific
299+ # extended card is set, serve the main agent_card.
321300 return JSONResponse (
322301 self .agent_card .model_dump (mode = 'json' , exclude_none = True )
323302 )
0 commit comments