Skip to content

feat: Add constants for Well-Known URIs #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/a2a/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
SetTaskPushNotificationConfigRequest,
SetTaskPushNotificationConfigResponse,
)
from a2a.utils.constants import (
AGENT_CARD_WELL_KNOWN_PATH,
)
from a2a.utils.telemetry import SpanKind, trace_class


Expand All @@ -40,8 +43,8 @@ def __init__(
self,
httpx_client: httpx.AsyncClient,
base_url: str,
agent_card_path: str = '/.well-known/agent.json',
):
agent_card_path: str = AGENT_CARD_WELL_KNOWN_PATH,
) -> None:
"""Initializes the A2ACardResolver.

Args:
Expand Down Expand Up @@ -184,7 +187,7 @@ async def _apply_interceptors(
async def get_client_from_agent_card_url(
httpx_client: httpx.AsyncClient,
base_url: str,
agent_card_path: str = '/.well-known/agent.json',
agent_card_path: str = AGENT_CARD_WELL_KNOWN_PATH,
http_kwargs: dict[str, Any] | None = None,
) -> 'A2AClient':
"""Fetches the public AgentCard and initializes an A2A client.
Expand Down
19 changes: 12 additions & 7 deletions src/a2a/server/apps/jsonrpc/fastapi_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@

from fastapi import FastAPI, Request, Response

from a2a.server.apps.jsonrpc.jsonrpc_app import (
CallContextBuilder,
JSONRPCApplication,
)
from a2a.server.request_handlers.jsonrpc_handler import RequestHandler
from a2a.types import AgentCard
from a2a.utils.constants import (
AGENT_CARD_WELL_KNOWN_PATH,
DEFAULT_RPC_URL,
EXTENDED_AGENT_CARD_PATH,
)


logger = logging.getLogger(__name__)


class A2AFastAPIApplication(JSONRPCApplication):

Check notice on line 23 in src/a2a/server/apps/jsonrpc/fastapi_app.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

Copy/pasted code

see src/a2a/server/apps/jsonrpc/starlette_app.py (8-24)
"""A FastAPI application implementing the A2A protocol server endpoints.

Handles incoming JSON-RPC requests, routes them to the appropriate
Expand All @@ -23,38 +28,38 @@
(SSE).
"""

def __init__(
self,
agent_card: AgentCard,
http_handler: RequestHandler,
extended_agent_card: AgentCard | None = None,
context_builder: CallContextBuilder | None = None,
):
) -> None:
"""Initializes the A2AStarletteApplication.

Args:
agent_card: The AgentCard describing the agent's capabilities.
http_handler: The handler instance responsible for processing A2A
requests via http.
extended_agent_card: An optional, distinct AgentCard to be served
at the authenticated extended card endpoint.
context_builder: The CallContextBuilder used to construct the
ServerCallContext passed to the http_handler. If None, no
ServerCallContext is passed.
"""
super().__init__(
agent_card=agent_card,
http_handler=http_handler,
extended_agent_card=extended_agent_card,
context_builder=context_builder,
)

def add_routes_to_app(

Check notice on line 57 in src/a2a/server/apps/jsonrpc/fastapi_app.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

Copy/pasted code

see src/a2a/server/apps/jsonrpc/starlette_app.py (32-58)
self,
app: FastAPI,
agent_card_url: str = '/.well-known/agent.json',
rpc_url: str = '/',
extended_agent_card_url: str = '/agent/authenticatedExtendedCard',
agent_card_url: str = AGENT_CARD_WELL_KNOWN_PATH,
rpc_url: str = DEFAULT_RPC_URL,
extended_agent_card_url: str = EXTENDED_AGENT_CARD_PATH,
) -> None:
"""Adds the routes to the FastAPI application.

Expand Down Expand Up @@ -83,9 +88,9 @@

def build(
self,
agent_card_url: str = '/.well-known/agent.json',
rpc_url: str = '/',
extended_agent_card_url: str = '/agent/authenticatedExtendedCard',
agent_card_url: str = AGENT_CARD_WELL_KNOWN_PATH,
rpc_url: str = DEFAULT_RPC_URL,
extended_agent_card_url: str = EXTENDED_AGENT_CARD_PATH,
**kwargs: Any,
) -> FastAPI:
"""Builds and returns the FastAPI application instance.
Expand Down
42 changes: 27 additions & 15 deletions src/a2a/server/apps/jsonrpc/jsonrpc_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
TaskResubscriptionRequest,
UnsupportedOperationError,
)
from a2a.utils.constants import (
AGENT_CARD_WELL_KNOWN_PATH,
DEFAULT_RPC_URL,
)
from a2a.utils.errors import MethodNotImplementedError


Expand Down Expand Up @@ -109,7 +113,7 @@ def __init__(
http_handler: RequestHandler,
extended_agent_card: AgentCard | None = None,
context_builder: CallContextBuilder | None = None,
):
) -> None:
"""Initializes the A2AStarletteApplication.
Args:
Expand Down Expand Up @@ -299,24 +303,32 @@ async def _process_non_streaming_request(
request_obj, context
)
case SetTaskPushNotificationConfigRequest():
handler_result = await self.handler.set_push_notification_config(
request_obj,
context,
handler_result = (
await self.handler.set_push_notification_config(
request_obj,
context,
)
)
case GetTaskPushNotificationConfigRequest():
handler_result = await self.handler.get_push_notification_config(
request_obj,
context,
handler_result = (
await self.handler.get_push_notification_config(
request_obj,
context,
)
)
case ListTaskPushNotificationConfigRequest():
handler_result = await self.handler.list_push_notification_config(
request_obj,
context,
handler_result = (
await self.handler.list_push_notification_config(
request_obj,
context,
)
)
case DeleteTaskPushNotificationConfigRequest():
handler_result = await self.handler.delete_push_notification_config(
request_obj,
context,
handler_result = (
await self.handler.delete_push_notification_config(
request_obj,
context,
)
)
case _:
logger.error(
Expand Down Expand Up @@ -424,8 +436,8 @@ async def _handle_get_authenticated_extended_agent_card(
@abstractmethod
def build(
self,
agent_card_url: str = '/.well-known/agent.json',
rpc_url: str = '/',
agent_card_url: str = AGENT_CARD_WELL_KNOWN_PATH,
rpc_url: str = DEFAULT_RPC_URL,
**kwargs: Any,
) -> FastAPI | Starlette:
"""Builds and returns the JSONRPC application instance.
Expand Down
25 changes: 15 additions & 10 deletions src/a2a/server/apps/jsonrpc/starlette_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@
from starlette.applications import Starlette
from starlette.routing import Route

from a2a.server.apps.jsonrpc.jsonrpc_app import (
CallContextBuilder,
JSONRPCApplication,
)
from a2a.server.request_handlers.jsonrpc_handler import RequestHandler
from a2a.types import AgentCard
from a2a.utils.constants import (
AGENT_CARD_WELL_KNOWN_PATH,
DEFAULT_RPC_URL,
EXTENDED_AGENT_CARD_PATH,
)


logger = logging.getLogger(__name__)


class A2AStarletteApplication(JSONRPCApplication):

Check notice on line 24 in src/a2a/server/apps/jsonrpc/starlette_app.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

Copy/pasted code

see src/a2a/server/apps/jsonrpc/fastapi_app.py (7-23)
"""A Starlette application implementing the A2A protocol server endpoints.

Handles incoming JSON-RPC requests, routes them to the appropriate
Expand All @@ -24,37 +29,37 @@
(SSE).
"""

def __init__(
self,
agent_card: AgentCard,
http_handler: RequestHandler,
extended_agent_card: AgentCard | None = None,
context_builder: CallContextBuilder | None = None,
):
) -> None:
"""Initializes the A2AStarletteApplication.

Args:
agent_card: The AgentCard describing the agent's capabilities.
http_handler: The handler instance responsible for processing A2A
requests via http.
extended_agent_card: An optional, distinct AgentCard to be served
at the authenticated extended card endpoint.
context_builder: The CallContextBuilder used to construct the
ServerCallContext passed to the http_handler. If None, no
ServerCallContext is passed.
"""
super().__init__(
agent_card=agent_card,
http_handler=http_handler,
extended_agent_card=extended_agent_card,
context_builder=context_builder,
)

def routes(

Check notice on line 58 in src/a2a/server/apps/jsonrpc/starlette_app.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

Copy/pasted code

see src/a2a/server/apps/jsonrpc/fastapi_app.py (31-57)
self,
agent_card_url: str = '/.well-known/agent.json',
rpc_url: str = '/',
extended_agent_card_url: str = '/agent/authenticatedExtendedCard',
agent_card_url: str = AGENT_CARD_WELL_KNOWN_PATH,
rpc_url: str = DEFAULT_RPC_URL,
extended_agent_card_url: str = EXTENDED_AGENT_CARD_PATH,
) -> list[Route]:
"""Returns the Starlette Routes for handling A2A requests.

Expand Down Expand Up @@ -95,9 +100,9 @@
def add_routes_to_app(
self,
app: Starlette,
agent_card_url: str = '/.well-known/agent.json',
rpc_url: str = '/',
extended_agent_card_url: str = '/agent/authenticatedExtendedCard',
agent_card_url: str = AGENT_CARD_WELL_KNOWN_PATH,
rpc_url: str = DEFAULT_RPC_URL,
extended_agent_card_url: str = EXTENDED_AGENT_CARD_PATH,
) -> None:
"""Adds the routes to the Starlette application.

Expand All @@ -116,9 +121,9 @@

def build(
self,
agent_card_url: str = '/.well-known/agent.json',
rpc_url: str = '/',
extended_agent_card_url: str = '/agent/authenticatedExtendedCard',
agent_card_url: str = AGENT_CARD_WELL_KNOWN_PATH,
rpc_url: str = DEFAULT_RPC_URL,
extended_agent_card_url: str = EXTENDED_AGENT_CARD_PATH,
**kwargs: Any,
) -> Starlette:
"""Builds and returns the Starlette application instance.
Expand Down
8 changes: 8 additions & 0 deletions src/a2a/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
new_data_artifact,
new_text_artifact,
)
from a2a.utils.constants import (
AGENT_CARD_WELL_KNOWN_PATH,
DEFAULT_RPC_URL,
EXTENDED_AGENT_CARD_PATH,
)
from a2a.utils.helpers import (
append_artifact_to_task,
are_modalities_compatible,
Expand All @@ -24,6 +29,9 @@


__all__ = [
'AGENT_CARD_WELL_KNOWN_PATH',
'DEFAULT_RPC_URL',
'EXTENDED_AGENT_CARD_PATH',
'append_artifact_to_task',
'are_modalities_compatible',
'build_text_artifact',
Expand Down
5 changes: 5 additions & 0 deletions src/a2a/utils/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Constants for well-known URIs used throughout the A2A Python SDK."""

AGENT_CARD_WELL_KNOWN_PATH = '/.well-known/agent.json'
EXTENDED_AGENT_CARD_PATH = '/agent/authenticatedExtendedCard'
DEFAULT_RPC_URL = '/'
Loading