11from collections .abc import Callable
22from typing import Any
33
4- from fastapi import APIRouter , FastAPI
5- from google .adk import Runner
6- from google .adk .a2a .executor .a2a_agent_executor import A2aAgentExecutor , A2aAgentExecutorConfig
7- from google .adk .agents import LlmAgent
8- from google .adk .artifacts import InMemoryArtifactService
9- from google .adk .memory import InMemoryMemoryService
10- from google .adk .sessions import InMemorySessionService
11- from starlette .applications import Starlette
12-
134from a2a .server .apps .jsonrpc .jsonrpc_app import CallContextBuilder , JSONRPCApplication
145from a2a .server .context import ServerCallContext
15- from a2a .server .request_handlers import DefaultRequestHandler
166from a2a .server .request_handlers .request_handler import RequestHandler
17- from a2a .server .tasks import InMemoryTaskStore
187from a2a .types import AgentCard
198from a2a .utils .constants import AGENT_CARD_WELL_KNOWN_PATH , DEFAULT_RPC_URL , EXTENDED_AGENT_CARD_PATH
20-
21-
22- def get_agent_request_handler (agent : LlmAgent ):
23- runner = Runner (
24- app_name = agent .name ,
25- agent = agent ,
26- artifact_service = InMemoryArtifactService (),
27- session_service = InMemorySessionService (),
28- memory_service = InMemoryMemoryService (),
29- )
30- config = A2aAgentExecutorConfig ()
31- executor = A2aAgentExecutor (runner = runner , config = config )
32- return DefaultRequestHandler (agent_executor = executor , task_store = InMemoryTaskStore ())
9+ from fastapi import APIRouter , FastAPI
10+ from starlette .applications import Starlette
3311
3412
3513class A2AFastApiApp (JSONRPCApplication ):
3614 def __init__ (
37- self ,
38- fastapi_app : FastAPI ,
39- agent_card : AgentCard ,
40- http_handler : RequestHandler ,
41- extended_agent_card : AgentCard | None = None ,
42- context_builder : CallContextBuilder | None = None ,
43- card_modifier : Callable [[AgentCard ], AgentCard ] | None = None ,
44- extended_card_modifier : Callable [[AgentCard , ServerCallContext ], AgentCard ] | None = None ,
15+ self ,
16+ fastapi_app : FastAPI ,
17+ agent_card : AgentCard ,
18+ http_handler : RequestHandler ,
19+ extended_agent_card : AgentCard | None = None ,
20+ context_builder : CallContextBuilder | None = None ,
21+ card_modifier : Callable [[AgentCard ], AgentCard ] | None = None ,
22+ extended_card_modifier : Callable [[AgentCard , ServerCallContext ], AgentCard ] | None = None ,
4523 ):
4624 super ().__init__ (
4725 agent_card = agent_card ,
@@ -54,11 +32,11 @@ def __init__(
5432 self .fastapi_app = fastapi_app
5533
5634 def build (
57- self ,
58- agent_card_url : str = AGENT_CARD_WELL_KNOWN_PATH ,
59- rpc_url : str = DEFAULT_RPC_URL ,
60- extended_agent_card_url : str = EXTENDED_AGENT_CARD_PATH ,
61- ** kwargs : Any ,
35+ self ,
36+ agent_card_url : str = AGENT_CARD_WELL_KNOWN_PATH ,
37+ rpc_url : str = DEFAULT_RPC_URL ,
38+ extended_agent_card_url : str = EXTENDED_AGENT_CARD_PATH ,
39+ ** kwargs : Any ,
6240 ) -> Starlette :
6341 name_prefix = rpc_url .replace ("/" , "" )
6442 router = APIRouter ()
0 commit comments