2020)
2121from a2a .server .request_handlers .request_handler import (
2222 RequestHandler ,
23- validate_request_params ,
2423)
2524from a2a .server .tasks import (
2625 PushNotificationConfigStore ,
5958 validate_page_size ,
6059)
6160from a2a .utils .telemetry import SpanKind , trace_class
61+ from a2a .utils .proto_utils import validate_proto_required_fields
6262
6363
6464logger = logging .getLogger (__name__ )
@@ -121,13 +121,13 @@ def __init__( # noqa: PLR0913
121121 # asyncio tasks and to surface unexpected exceptions.
122122 self ._background_tasks = set ()
123123
124- @validate_request_params
125124 async def on_get_task (
126125 self ,
127126 params : GetTaskRequest ,
128127 context : ServerCallContext ,
129128 ) -> Task | None :
130129 """Default handler for 'tasks/get'."""
130+ validate_proto_required_fields (params )
131131 validate_history_length (params )
132132
133133 task_id = params .id
@@ -137,13 +137,13 @@ async def on_get_task(
137137
138138 return apply_history_length (task , params )
139139
140- @validate_request_params
141140 async def on_list_tasks (
142141 self ,
143142 params : ListTasksRequest ,
144143 context : ServerCallContext ,
145144 ) -> ListTasksResponse :
146145 """Default handler for 'tasks/list'."""
146+ validate_proto_required_fields (params )
147147 validate_history_length (params )
148148 if params .HasField ('page_size' ):
149149 validate_page_size (params .page_size )
@@ -159,7 +159,6 @@ async def on_list_tasks(
159159
160160 return page
161161
162- @validate_request_params
163162 async def on_cancel_task (
164163 self ,
165164 params : CancelTaskRequest ,
@@ -169,6 +168,7 @@ async def on_cancel_task(
169168
170169 Attempts to cancel the task managed by the `AgentExecutor`.
171170 """
171+ validate_proto_required_fields (params )
172172 task_id = params .id
173173 task : Task | None = await self .task_store .get (task_id , context )
174174 if not task :
@@ -323,7 +323,6 @@ async def _send_push_notification_if_needed(
323323 ):
324324 await self ._push_sender .send_notification (task_id , event )
325325
326- @validate_request_params
327326 async def on_message_send (
328327 self ,
329328 params : SendMessageRequest ,
@@ -334,6 +333,7 @@ async def on_message_send(
334333 Starts the agent execution for the message and waits for the final
335334 result (Task or Message).
336335 """
336+ validate_proto_required_fields (params )
337337 validate_history_length (params .configuration )
338338
339339 (
@@ -393,7 +393,6 @@ async def push_notification_callback(event: Event) -> None:
393393
394394 return result
395395
396- @validate_request_params
397396 async def on_message_send_stream (
398397 self ,
399398 params : SendMessageRequest ,
@@ -404,6 +403,7 @@ async def on_message_send_stream(
404403 Starts the agent execution and yields events as they are produced
405404 by the agent.
406405 """
406+ validate_proto_required_fields (params )
407407 (
408408 _task_manager ,
409409 task_id ,
@@ -482,7 +482,6 @@ async def _cleanup_producer(
482482 async with self ._running_agents_lock :
483483 self ._running_agents .pop (task_id , None )
484484
485- @validate_request_params
486485 async def on_create_task_push_notification_config (
487486 self ,
488487 params : TaskPushNotificationConfig ,
@@ -492,6 +491,7 @@ async def on_create_task_push_notification_config(
492491
493492 Requires a `PushNotifier` to be configured.
494493 """
494+ validate_proto_required_fields (params )
495495 if not self ._push_config_store :
496496 raise UnsupportedOperationError
497497
@@ -508,7 +508,6 @@ async def on_create_task_push_notification_config(
508508
509509 return params
510510
511- @validate_request_params
512511 async def on_get_task_push_notification_config (
513512 self ,
514513 params : GetTaskPushNotificationConfigRequest ,
@@ -518,6 +517,7 @@ async def on_get_task_push_notification_config(
518517
519518 Requires a `PushConfigStore` to be configured.
520519 """
520+ validate_proto_required_fields (params )
521521 if not self ._push_config_store :
522522 raise UnsupportedOperationError
523523
@@ -540,7 +540,6 @@ async def on_get_task_push_notification_config(
540540
541541 raise InternalError (message = 'Push notification config not found' )
542542
543- @validate_request_params
544543 async def on_subscribe_to_task (
545544 self ,
546545 params : SubscribeToTaskRequest ,
@@ -551,6 +550,7 @@ async def on_subscribe_to_task(
551550 Allows a client to re-attach to a running streaming task's event stream.
552551 Requires the task and its queue to still be active.
553552 """
553+ validate_proto_required_fields (params )
554554 task_id = params .id
555555 task : Task | None = await self .task_store .get (task_id , context )
556556 if not task :
@@ -583,7 +583,6 @@ async def on_subscribe_to_task(
583583 async for event in result_aggregator .consume_and_emit (consumer ):
584584 yield event
585585
586- @validate_request_params
587586 async def on_list_task_push_notification_configs (
588587 self ,
589588 params : ListTaskPushNotificationConfigsRequest ,
@@ -593,6 +592,7 @@ async def on_list_task_push_notification_configs(
593592
594593 Requires a `PushConfigStore` to be configured.
595594 """
595+ validate_proto_required_fields (params )
596596 if not self ._push_config_store :
597597 raise UnsupportedOperationError
598598
@@ -609,7 +609,6 @@ async def on_list_task_push_notification_configs(
609609 configs = push_notification_config_list
610610 )
611611
612- @validate_request_params
613612 async def on_delete_task_push_notification_config (
614613 self ,
615614 params : DeleteTaskPushNotificationConfigRequest ,
@@ -619,6 +618,7 @@ async def on_delete_task_push_notification_config(
619618
620619 Requires a `PushConfigStore` to be configured.
621620 """
621+ validate_proto_required_fields (params )
622622 if not self ._push_config_store :
623623 raise UnsupportedOperationError
624624
0 commit comments