44import traceback
55
66from abc import ABC , abstractmethod
7- from collections .abc import AsyncGenerator , Callable
7+ from collections .abc import AsyncGenerator , Awaitable , Callable
88from typing import TYPE_CHECKING , Any
99
1010from pydantic import ValidationError
@@ -178,9 +178,10 @@ def __init__( # noqa: PLR0913
178178 http_handler : RequestHandler ,
179179 extended_agent_card : AgentCard | None = None ,
180180 context_builder : CallContextBuilder | None = None ,
181- card_modifier : Callable [[AgentCard ], AgentCard ] | None = None ,
181+ card_modifier : Callable [[AgentCard ], Awaitable [AgentCard ]]
182+ | None = None ,
182183 extended_card_modifier : Callable [
183- [AgentCard , ServerCallContext ], AgentCard
184+ [AgentCard , ServerCallContext ], Awaitable [ AgentCard ]
184185 ]
185186 | None = None ,
186187 max_content_length : int | None = 10 * 1024 * 1024 , # 10MB
@@ -196,9 +197,9 @@ def __init__( # noqa: PLR0913
196197 context_builder: The CallContextBuilder used to construct the
197198 ServerCallContext passed to the http_handler. If None, no
198199 ServerCallContext is passed.
199- card_modifier: An optional callback to dynamically modify the public
200+ card_modifier: An optional async callback to dynamically modify the public
200201 agent card before it is served.
201- extended_card_modifier: An optional callback to dynamically modify
202+ extended_card_modifier: An optional async callback to dynamically modify
202203 the extended agent card before it is served. It receives the
203204 call context.
204205 max_content_length: The maximum allowed content length for incoming
@@ -576,7 +577,7 @@ async def _handle_get_agent_card(self, request: Request) -> JSONResponse:
576577
577578 card_to_serve = self .agent_card
578579 if self .card_modifier :
579- card_to_serve = self .card_modifier (card_to_serve )
580+ card_to_serve = await self .card_modifier (card_to_serve )
580581
581582 return JSONResponse (
582583 card_to_serve .model_dump (
@@ -605,7 +606,9 @@ async def _handle_get_authenticated_extended_agent_card(
605606 context = self ._context_builder .build (request )
606607 # If no base extended card is provided, pass the public card to the modifier
607608 base_card = card_to_serve if card_to_serve else self .agent_card
608- card_to_serve = self .extended_card_modifier (base_card , context )
609+ card_to_serve = await self .extended_card_modifier (
610+ base_card , context
611+ )
609612
610613 if card_to_serve :
611614 return JSONResponse (
0 commit comments