Skip to content

Commit e9d8e8f

Browse files
committed
fix: move agent_card_path and rpc_path to init from routes
Signed-off-by: Shingo OKAWA <[email protected]>
1 parent 538cc42 commit e9d8e8f

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/a2a/server/apps/starlette_app.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -433,18 +433,28 @@ class A2AStarletteRouter:
433433
the `build()` method.
434434
"""
435435

436-
def __init__(self, agent_card: AgentCard, http_handler: RequestHandler):
436+
def __init__(
437+
self,
438+
agent_card: AgentCard,
439+
http_handler: RequestHandler,
440+
agent_card_path: str = '/agent.json',
441+
rpc_path: str = '/',
442+
):
437443
"""Initializes the A2AStarletteRouter.
438444
439445
Args:
440446
agent_card: The AgentCard describing the agent's capabilities.
441447
http_handler: The handler instance responsible for processing A2A
442448
requests via http.
449+
agent_card_path: The URL path for the agent card endpoint.
450+
rpc_path: The URL path for the A2A JSON-RPC endpoint (POST requests).
443451
"""
444452
self.agent_card = agent_card
445453
self.handler = JSONRPCHandler(
446454
agent_card=agent_card, request_handler=http_handler
447455
)
456+
self.agent_card_path = agent_card_path
457+
self.rpc_path = rpc_path
448458

449459
def _generate_error_response(
450460
self, request_id: str | int | None, error: JSONRPCError | A2AError
@@ -667,29 +677,21 @@ async def _handle_get_agent_card(self, request: Request) -> JSONResponse:
667677
self.agent_card.model_dump(mode='json', exclude_none=True)
668678
)
669679

670-
def routes(
671-
self,
672-
agent_card_path: str = '/agent.json',
673-
rpc_path: str = '/',
674-
) -> list[Route]:
680+
def routes(self) -> list[Route]:
675681
"""Returns the Starlette Routes for handling A2A requests.
676682
677-
Args:
678-
agent_card_path: The URL path for the agent card endpoint.
679-
rpc_path: The URL path for the A2A JSON-RPC endpoint (POST requests).
680-
681683
Returns:
682684
A list of Starlette Route objects.
683685
"""
684686
return [
685687
Route(
686-
rpc_path,
688+
self.rpc_path,
687689
self._handle_requests,
688690
methods=['POST'],
689691
name='a2a_handler',
690692
),
691693
Route(
692-
agent_card_path,
694+
self.agent_card_path,
693695
self._handle_get_agent_card,
694696
methods=['GET'],
695697
name='agent_card',

0 commit comments

Comments
 (0)