Skip to content

Commit 9b0b522

Browse files
committed
remove agent_card property
1 parent 3169d76 commit 9b0b522

13 files changed

Lines changed: 53 additions & 56 deletions

src/a2a/server/request_handlers/default_request_handler.py

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,6 @@ def __init__( # noqa: PLR0913
144144
# asyncio tasks and to surface unexpected exceptions.
145145
self._background_tasks = set()
146146

147-
@property
148-
def agent_card(self) -> AgentCard:
149-
"""The agent card to be served by default."""
150-
return self._agent_card
151-
152147
@validate_request_params
153148
async def on_get_task(
154149
self,
@@ -424,7 +419,7 @@ async def push_notification_callback(event: Event) -> None:
424419

425420
@validate_request_params
426421
@validate(
427-
lambda self: self.agent_card.capabilities.streaming,
422+
lambda self: self._agent_card.capabilities.streaming,
428423
'Streaming is not supported by the agent',
429424
)
430425
async def on_message_send_stream(
@@ -517,10 +512,7 @@ async def _cleanup_producer(
517512

518513
@validate_request_params
519514
@validate(
520-
lambda self: (
521-
self.agent_card.capabilities.push_notifications
522-
and self._push_config_store
523-
),
515+
lambda self: self._agent_card.capabilities.push_notifications,
524516
error_message='Push notifications are not supported by the agent',
525517
error_type=PushNotificationNotSupportedError,
526518
)
@@ -533,12 +525,15 @@ async def on_create_task_push_notification_config(
533525
534526
Requires a `PushNotifier` to be configured.
535527
"""
528+
if not self._push_config_store:
529+
raise PushNotificationNotSupportedError
530+
536531
task_id = params.task_id
537532
task: Task | None = await self.task_store.get(task_id, context)
538533
if not task:
539534
raise TaskNotFoundError
540535

541-
await self._push_config_store.set_info( # type: ignore[union-attr]
536+
await self._push_config_store.set_info(
542537
task_id,
543538
params,
544539
context,
@@ -548,10 +543,7 @@ async def on_create_task_push_notification_config(
548543

549544
@validate_request_params
550545
@validate(
551-
lambda self: (
552-
self.agent_card.capabilities.push_notifications
553-
and self._push_config_store
554-
),
546+
lambda self: self._agent_card.capabilities.push_notifications,
555547
error_message='Push notifications are not supported by the agent',
556548
error_type=PushNotificationNotSupportedError,
557549
)
@@ -564,14 +556,17 @@ async def on_get_task_push_notification_config(
564556
565557
Requires a `PushConfigStore` to be configured.
566558
"""
559+
if not self._push_config_store:
560+
raise PushNotificationNotSupportedError
561+
567562
task_id = params.task_id
568563
config_id = params.id
569564
task: Task | None = await self.task_store.get(task_id, context)
570565
if not task:
571566
raise TaskNotFoundError
572567

573568
push_notification_configs: list[TaskPushNotificationConfig] = (
574-
await self._push_config_store.get_info(task_id, context) or [] # type: ignore[union-attr]
569+
await self._push_config_store.get_info(task_id, context) or []
575570
)
576571

577572
for config in push_notification_configs:
@@ -582,7 +577,7 @@ async def on_get_task_push_notification_config(
582577

583578
@validate_request_params
584579
@validate(
585-
lambda self: self.agent_card.capabilities.streaming,
580+
lambda self: self._agent_card.capabilities.streaming,
586581
'Streaming is not supported by the agent',
587582
)
588583
async def on_subscribe_to_task(
@@ -629,10 +624,7 @@ async def on_subscribe_to_task(
629624

630625
@validate_request_params
631626
@validate(
632-
lambda self: (
633-
self.agent_card.capabilities.push_notifications
634-
and self._push_config_store
635-
),
627+
lambda self: self._agent_card.capabilities.push_notifications,
636628
error_message='Push notifications are not supported by the agent',
637629
error_type=PushNotificationNotSupportedError,
638630
)
@@ -645,12 +637,15 @@ async def on_list_task_push_notification_configs(
645637
646638
Requires a `PushConfigStore` to be configured.
647639
"""
640+
if not self._push_config_store:
641+
raise PushNotificationNotSupportedError
642+
648643
task_id = params.task_id
649644
task: Task | None = await self.task_store.get(task_id, context)
650645
if not task:
651646
raise TaskNotFoundError
652647

653-
push_notification_config_list = await self._push_config_store.get_info( # type: ignore[union-attr]
648+
push_notification_config_list = await self._push_config_store.get_info(
654649
task_id, context
655650
)
656651

@@ -660,10 +655,7 @@ async def on_list_task_push_notification_configs(
660655

661656
@validate_request_params
662657
@validate(
663-
lambda self: (
664-
self.agent_card.capabilities.push_notifications
665-
and self._push_config_store
666-
),
658+
lambda self: self._agent_card.capabilities.push_notifications,
667659
error_message='Push notifications are not supported by the agent',
668660
error_type=PushNotificationNotSupportedError,
669661
)
@@ -676,17 +668,24 @@ async def on_delete_task_push_notification_config(
676668
677669
Requires a `PushConfigStore` to be configured.
678670
"""
671+
if not self._push_config_store:
672+
raise PushNotificationNotSupportedError
673+
679674
task_id = params.task_id
680675
config_id = params.id
681676
task: Task | None = await self.task_store.get(task_id, context)
682677
if not task:
683678
raise TaskNotFoundError
684679

685-
await self._push_config_store.delete_info(task_id, context, config_id) # type: ignore[union-attr]
680+
await self._push_config_store.delete_info(task_id, context, config_id)
686681

687682
@validate_request_params
688683
@validate(
689-
lambda self: self.agent_card.capabilities.extended_agent_card,
684+
lambda self: self._agent_card.capabilities.extended_agent_card,
685+
error_message='The agent does not support authenticated extended cards',
686+
)
687+
@validate(
688+
lambda self: self.extended_agent_card,
690689
error_message='The agent does not have an extended agent card configured',
691690
error_type=ExtendedAgentCardNotConfiguredError,
692691
)
@@ -699,12 +698,11 @@ async def on_get_extended_agent_card(
699698
700699
Requires `capabilities.extended_agent_card` to be true.
701700
"""
702-
card = self.extended_agent_card or self.agent_card
701+
extended_card = self.extended_agent_card
703702

704703
if self.extended_card_modifier:
705-
return await maybe_await(self.extended_card_modifier(card, context))
706-
707-
if self.card_modifier:
708-
return await maybe_await(self.card_modifier(card))
704+
return await maybe_await(
705+
self.extended_card_modifier(extended_card, context)
706+
)
709707

710-
return card
708+
return extended_card

src/a2a/server/request_handlers/request_handler.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ class RequestHandler(ABC):
3636
provide to handle incoming A2A requests from any transport (gRPC, REST, JSON-RPC).
3737
"""
3838

39-
@property
40-
@abstractmethod
41-
def agent_card(self) -> AgentCard:
42-
"""The core agent card to serve logic against."""
43-
4439
@abstractmethod
4540
async def on_get_task(
4641
self,

src/a2a/server/routes/jsonrpc_dispatcher.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,15 @@ def __init__(
220220

221221
if self.enable_v0_3_compat:
222222
self._v03_adapter = JSONRPC03Adapter(
223-
agent_card=request_handler.agent_card,
223+
agent_card=getattr(request_handler, '_agent_card', None),
224224
http_handler=request_handler,
225225
extended_agent_card=getattr(
226-
request_handler, 'extended_agent_card', None
226+
request_handler, '_extended_agent_card', None
227227
),
228228
context_builder=self._context_builder,
229-
card_modifier=getattr(request_handler, 'card_modifier', None),
229+
card_modifier=getattr(request_handler, '_card_modifier', None),
230230
extended_card_modifier=getattr(
231-
request_handler, 'extended_card_modifier', None
231+
request_handler, '_extended_card_modifier', None
232232
),
233233
)
234234

src/a2a/server/routes/rest_routes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ def create_rest_routes(
7070
routes: list[BaseRoute] = []
7171
if enable_v0_3_compat:
7272
v03_adapter = REST03Adapter(
73-
agent_card=request_handler.agent_card,
73+
agent_card=getattr(request_handler, '_agent_card', None),
7474
http_handler=request_handler,
7575
extended_agent_card=getattr(
76-
request_handler, 'extended_agent_card', None
76+
request_handler, '_extended_agent_card', None
7777
),
7878
context_builder=context_builder,
79-
card_modifier=getattr(request_handler, 'card_modifier', None),
79+
card_modifier=getattr(request_handler, '_card_modifier', None),
8080
extended_card_modifier=getattr(
81-
request_handler, 'extended_card_modifier', None
81+
request_handler, '_extended_card_modifier', None
8282
),
8383
)
8484
v03_routes = v03_adapter.routes()

tests/compat/v0_3/test_jsonrpc_app_compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_app(mock_handler):
5151
mock_agent_card.capabilities.streaming = False
5252
mock_agent_card.capabilities.push_notifications = True
5353
mock_agent_card.capabilities.extended_agent_card = True
54-
mock_handler.agent_card = mock_agent_card
54+
mock_handler._agent_card = mock_agent_card
5555
jsonrpc_routes = create_jsonrpc_routes(
5656
request_handler=mock_handler,
5757
enable_v0_3_compat=True,

tests/compat/v0_3/test_rest_routes_compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async def app(
5353
request_handler: RequestHandler,
5454
) -> Starlette:
5555
"""Builds the Starlette application for testing."""
56-
request_handler.agent_card = agent_card
56+
request_handler._agent_card = agent_card
5757
rest_routes = create_rest_routes(
5858
request_handler=request_handler, enable_v0_3_compat=True
5959
)

tests/e2e/push_notifications/agent_app.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,13 @@ def create_agent_app(
142142
"""Creates a new HTTP+REST Starlette application for the test agent."""
143143
push_config_store = InMemoryPushNotificationConfigStore()
144144
card = test_agent_card(url)
145+
extended_card = test_agent_card(url)
146+
extended_card.name = 'Test Agent Extended'
145147
handler = DefaultRequestHandler(
146148
agent_executor=TestAgentExecutor(),
147149
task_store=InMemoryTaskStore(),
148150
agent_card=card,
151+
extended_agent_card=extended_card,
149152
push_config_store=push_config_store,
150153
push_sender=BasePushNotificationSender(
151154
httpx_client=notification_client,

tests/integration/test_client_server_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def mock_request_handler(agent_card) -> AsyncMock:
150150
handler = AsyncMock(spec=RequestHandler)
151151

152152
# Configure on_message_send for non-streaming calls
153-
handler.agent_card = agent_card
153+
handler._agent_card = agent_card
154154
handler.on_message_send.return_value = TASK_FROM_BLOCKING
155155

156156
# Configure on_message_send_stream for streaming calls

tests/server/request_handlers/test_default_request_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2894,7 +2894,7 @@ async def test_on_get_extended_agent_card_unsupported(agent_card):
28942894
params = GetExtendedAgentCardRequest()
28952895
context = create_server_call_context()
28962896

2897-
with pytest.raises(ExtendedAgentCardNotConfiguredError):
2897+
with pytest.raises(UnsupportedOperationError):
28982898
await request_handler.on_get_extended_agent_card(params, context)
28992899

29002900

tests/server/request_handlers/test_grpc_handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def sample_agent_card() -> types.AgentCard:
5353
def grpc_handler(
5454
mock_request_handler: AsyncMock, sample_agent_card: types.AgentCard
5555
) -> GrpcHandler:
56-
mock_request_handler.agent_card = sample_agent_card
56+
mock_request_handler._agent_card = sample_agent_card
5757
return GrpcHandler(request_handler=mock_request_handler)
5858

5959

@@ -219,7 +219,7 @@ async def side_effect_func(*_args, **_kwargs):
219219
mock_request_handler.on_get_extended_agent_card.side_effect = (
220220
side_effect_func
221221
)
222-
mock_request_handler.agent_card = sample_agent_card
222+
mock_request_handler._agent_card = sample_agent_card
223223
grpc_handler_modified = GrpcHandler(request_handler=mock_request_handler)
224224
request_proto = a2a_pb2.GetExtendedAgentCardRequest()
225225
response = await grpc_handler_modified.GetExtendedAgentCard(
@@ -249,7 +249,7 @@ async def async_modifier(*args, **kwargs):
249249
return modifier(sample_agent_card)
250250

251251
mock_request_handler.on_get_extended_agent_card.side_effect = async_modifier
252-
mock_request_handler.agent_card = sample_agent_card
252+
mock_request_handler._agent_card = sample_agent_card
253253
grpc_handler_modified = GrpcHandler(request_handler=mock_request_handler)
254254
request_proto = a2a_pb2.GetExtendedAgentCardRequest()
255255
response = await grpc_handler_modified.GetExtendedAgentCard(

0 commit comments

Comments
 (0)