Skip to content

Commit 5176ac2

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

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
@@ -476,18 +476,28 @@ class A2AStarletteRouter:
476476
the `build()` method.
477477
"""
478478

479-
def __init__(self, agent_card: AgentCard, http_handler: RequestHandler):
479+
def __init__(
480+
self,
481+
agent_card: AgentCard,
482+
http_handler: RequestHandler,
483+
agent_card_path: str = '/agent.json',
484+
rpc_path: str = '/',
485+
):
480486
"""Initializes the A2AStarletteRouter.
481487
482488
Args:
483489
agent_card: The AgentCard describing the agent's capabilities.
484490
http_handler: The handler instance responsible for processing A2A
485491
requests via http.
492+
agent_card_path: The URL path for the agent card endpoint.
493+
rpc_path: The URL path for the A2A JSON-RPC endpoint (POST requests).
486494
"""
487495
self.agent_card = agent_card
488496
self.handler = JSONRPCHandler(
489497
agent_card=agent_card, request_handler=http_handler
490498
)
499+
self.agent_card_path = agent_card_path
500+
self.rpc_path = rpc_path
491501

492502
def _generate_error_response(
493503
self, request_id: str | int | None, error: JSONRPCError | A2AError
@@ -710,29 +720,21 @@ async def _handle_get_agent_card(self, request: Request) -> JSONResponse:
710720
self.agent_card.model_dump(mode='json', exclude_none=True)
711721
)
712722

713-
def routes(
714-
self,
715-
agent_card_path: str = '/agent.json',
716-
rpc_path: str = '/',
717-
) -> list[Route]:
723+
def routes(self) -> list[Route]:
718724
"""Returns the Starlette Routes for handling A2A requests.
719725
720-
Args:
721-
agent_card_path: The URL path for the agent card endpoint.
722-
rpc_path: The URL path for the A2A JSON-RPC endpoint (POST requests).
723-
724726
Returns:
725727
A list of Starlette Route objects.
726728
"""
727729
return [
728730
Route(
729-
rpc_path,
731+
self.rpc_path,
730732
self._handle_requests,
731733
methods=['POST'],
732734
name='a2a_handler',
733735
),
734736
Route(
735-
agent_card_path,
737+
self.agent_card_path,
736738
self._handle_get_agent_card,
737739
methods=['GET'],
738740
name='agent_card',

0 commit comments

Comments
 (0)