Skip to content

Commit 14d2db5

Browse files
committed
Merge branch 'main' into make-fastapi-package-optional
2 parents 975e865 + 1c8e12e commit 14d2db5

File tree

6 files changed

+73
-35
lines changed

6 files changed

+73
-35
lines changed

src/a2a/client/client.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
SetTaskPushNotificationConfigRequest,
2828
SetTaskPushNotificationConfigResponse,
2929
)
30+
from a2a.utils.constants import (
31+
AGENT_CARD_WELL_KNOWN_PATH,
32+
)
3033
from a2a.utils.telemetry import SpanKind, trace_class
3134

3235

@@ -40,8 +43,8 @@ def __init__(
4043
self,
4144
httpx_client: httpx.AsyncClient,
4245
base_url: str,
43-
agent_card_path: str = '/.well-known/agent.json',
44-
):
46+
agent_card_path: str = AGENT_CARD_WELL_KNOWN_PATH,
47+
) -> None:
4548
"""Initializes the A2ACardResolver.
4649
4750
Args:
@@ -184,7 +187,7 @@ async def _apply_interceptors(
184187
async def get_client_from_agent_card_url(
185188
httpx_client: httpx.AsyncClient,
186189
base_url: str,
187-
agent_card_path: str = '/.well-known/agent.json',
190+
agent_card_path: str = AGENT_CARD_WELL_KNOWN_PATH,
188191
http_kwargs: dict[str, Any] | None = None,
189192
) -> 'A2AClient':
190193
"""Fetches the public AgentCard and initializes an A2A client.

src/a2a/server/apps/jsonrpc/fastapi_app.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
)
2626
from a2a.server.request_handlers.jsonrpc_handler import RequestHandler
2727
from a2a.types import AgentCard
28+
from a2a.utils.constants import (
29+
AGENT_CARD_WELL_KNOWN_PATH,
30+
DEFAULT_RPC_URL,
31+
EXTENDED_AGENT_CARD_PATH,
32+
)
2833

2934

3035
logger = logging.getLogger(__name__)
@@ -44,7 +49,7 @@ def __init__(
4449
http_handler: RequestHandler,
4550
extended_agent_card: AgentCard | None = None,
4651
context_builder: CallContextBuilder | None = None,
47-
):
52+
) -> None:
4853
"""Initializes the A2AFastAPIApplication.
4954
5055
Args:
@@ -73,9 +78,9 @@ def __init__(
7378
def add_routes_to_app(
7479
self,
7580
app: FastAPI,
76-
agent_card_url: str = '/.well-known/agent.json',
77-
rpc_url: str = '/',
78-
extended_agent_card_url: str = '/agent/authenticatedExtendedCard',
81+
agent_card_url: str = AGENT_CARD_WELL_KNOWN_PATH,
82+
rpc_url: str = DEFAULT_RPC_URL,
83+
extended_agent_card_url: str = EXTENDED_AGENT_CARD_PATH,
7984
) -> None:
8085
"""Adds the routes to the FastAPI application.
8186
@@ -104,9 +109,9 @@ async def get_extended_agent_card(request: Request) -> Response:
104109

105110
def build(
106111
self,
107-
agent_card_url: str = '/.well-known/agent.json',
108-
rpc_url: str = '/',
109-
extended_agent_card_url: str = '/agent/authenticatedExtendedCard',
112+
agent_card_url: str = AGENT_CARD_WELL_KNOWN_PATH,
113+
rpc_url: str = DEFAULT_RPC_URL,
114+
extended_agent_card_url: str = EXTENDED_AGENT_CARD_PATH,
110115
**kwargs: Any,
111116
) -> FastAPI:
112117
"""Builds and returns the FastAPI application instance.

src/a2a/server/apps/jsonrpc/jsonrpc_app.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
TaskResubscriptionRequest,
3737
UnsupportedOperationError,
3838
)
39+
from a2a.utils.constants import (
40+
AGENT_CARD_WELL_KNOWN_PATH,
41+
DEFAULT_RPC_URL,
42+
)
3943
from a2a.utils.errors import MethodNotImplementedError
4044

4145

@@ -133,7 +137,7 @@ def __init__(
133137
http_handler: RequestHandler,
134138
extended_agent_card: AgentCard | None = None,
135139
context_builder: CallContextBuilder | None = None,
136-
):
140+
) -> None:
137141
"""Initializes the JSONRPCApplication.
138142
139143
Args:
@@ -329,24 +333,32 @@ async def _process_non_streaming_request(
329333
request_obj, context
330334
)
331335
case SetTaskPushNotificationConfigRequest():
332-
handler_result = await self.handler.set_push_notification_config(
333-
request_obj,
334-
context,
336+
handler_result = (
337+
await self.handler.set_push_notification_config(
338+
request_obj,
339+
context,
340+
)
335341
)
336342
case GetTaskPushNotificationConfigRequest():
337-
handler_result = await self.handler.get_push_notification_config(
338-
request_obj,
339-
context,
343+
handler_result = (
344+
await self.handler.get_push_notification_config(
345+
request_obj,
346+
context,
347+
)
340348
)
341349
case ListTaskPushNotificationConfigRequest():
342-
handler_result = await self.handler.list_push_notification_config(
343-
request_obj,
344-
context,
350+
handler_result = (
351+
await self.handler.list_push_notification_config(
352+
request_obj,
353+
context,
354+
)
345355
)
346356
case DeleteTaskPushNotificationConfigRequest():
347-
handler_result = await self.handler.delete_push_notification_config(
348-
request_obj,
349-
context,
357+
handler_result = (
358+
await self.handler.delete_push_notification_config(
359+
request_obj,
360+
context,
361+
)
350362
)
351363
case _:
352364
logger.error(
@@ -454,8 +466,8 @@ async def _handle_get_authenticated_extended_agent_card(
454466
@abstractmethod
455467
def build(
456468
self,
457-
agent_card_url: str = '/.well-known/agent.json',
458-
rpc_url: str = '/',
469+
agent_card_url: str = AGENT_CARD_WELL_KNOWN_PATH,
470+
rpc_url: str = DEFAULT_RPC_URL,
459471
**kwargs: Any,
460472
) -> FastAPI | Starlette:
461473
"""Builds and returns the JSONRPC application instance.

src/a2a/server/apps/jsonrpc/starlette_app.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
)
2828
from a2a.server.request_handlers.jsonrpc_handler import RequestHandler
2929
from a2a.types import AgentCard
30+
from a2a.utils.constants import (
31+
AGENT_CARD_WELL_KNOWN_PATH,
32+
DEFAULT_RPC_URL,
33+
EXTENDED_AGENT_CARD_PATH,
34+
)
3035

3136

3237
logger = logging.getLogger(__name__)
@@ -46,7 +51,7 @@ def __init__(
4651
http_handler: RequestHandler,
4752
extended_agent_card: AgentCard | None = None,
4853
context_builder: CallContextBuilder | None = None,
49-
):
54+
) -> None:
5055
"""Initializes the A2AStarletteApplication.
5156
5257
Args:
@@ -74,9 +79,9 @@ def __init__(
7479

7580
def routes(
7681
self,
77-
agent_card_url: str = '/.well-known/agent.json',
78-
rpc_url: str = '/',
79-
extended_agent_card_url: str = '/agent/authenticatedExtendedCard',
82+
agent_card_url: str = AGENT_CARD_WELL_KNOWN_PATH,
83+
rpc_url: str = DEFAULT_RPC_URL,
84+
extended_agent_card_url: str = EXTENDED_AGENT_CARD_PATH,
8085
) -> list[Route]:
8186
"""Returns the Starlette Routes for handling A2A requests.
8287
@@ -117,9 +122,9 @@ def routes(
117122
def add_routes_to_app(
118123
self,
119124
app: Starlette,
120-
agent_card_url: str = '/.well-known/agent.json',
121-
rpc_url: str = '/',
122-
extended_agent_card_url: str = '/agent/authenticatedExtendedCard',
125+
agent_card_url: str = AGENT_CARD_WELL_KNOWN_PATH,
126+
rpc_url: str = DEFAULT_RPC_URL,
127+
extended_agent_card_url: str = EXTENDED_AGENT_CARD_PATH,
123128
) -> None:
124129
"""Adds the routes to the Starlette application.
125130
@@ -138,9 +143,9 @@ def add_routes_to_app(
138143

139144
def build(
140145
self,
141-
agent_card_url: str = '/.well-known/agent.json',
142-
rpc_url: str = '/',
143-
extended_agent_card_url: str = '/agent/authenticatedExtendedCard',
146+
agent_card_url: str = AGENT_CARD_WELL_KNOWN_PATH,
147+
rpc_url: str = DEFAULT_RPC_URL,
148+
extended_agent_card_url: str = EXTENDED_AGENT_CARD_PATH,
144149
**kwargs: Any,
145150
) -> Starlette:
146151
"""Builds and returns the Starlette application instance.

src/a2a/utils/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
new_data_artifact,
66
new_text_artifact,
77
)
8+
from a2a.utils.constants import (
9+
AGENT_CARD_WELL_KNOWN_PATH,
10+
DEFAULT_RPC_URL,
11+
EXTENDED_AGENT_CARD_PATH,
12+
)
813
from a2a.utils.helpers import (
914
append_artifact_to_task,
1015
are_modalities_compatible,
@@ -24,6 +29,9 @@
2429

2530

2631
__all__ = [
32+
'AGENT_CARD_WELL_KNOWN_PATH',
33+
'DEFAULT_RPC_URL',
34+
'EXTENDED_AGENT_CARD_PATH',
2735
'append_artifact_to_task',
2836
'are_modalities_compatible',
2937
'build_text_artifact',

src/a2a/utils/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""Constants for well-known URIs used throughout the A2A Python SDK."""
2+
3+
AGENT_CARD_WELL_KNOWN_PATH = '/.well-known/agent.json'
4+
EXTENDED_AGENT_CARD_PATH = '/agent/authenticatedExtendedCard'
5+
DEFAULT_RPC_URL = '/'

0 commit comments

Comments
 (0)