4242from .part_converter import A2A_DATA_PART_METADATA_IS_LONG_RUNNING_KEY
4343from .part_converter import A2A_DATA_PART_METADATA_TYPE_FUNCTION_CALL
4444from .part_converter import A2A_DATA_PART_METADATA_TYPE_KEY
45+ from .part_converter import A2APartToGenAIPartConverter
4546from .part_converter import convert_a2a_part_to_genai_part
4647from .part_converter import convert_genai_part_to_a2a_part
48+ from .part_converter import GenAIPartToA2APartConverter
4749from .utils import _get_adk_metadata_key
4850
4951# Constants
@@ -169,6 +171,7 @@ def convert_a2a_task_to_event(
169171 a2a_task : Task ,
170172 author : Optional [str ] = None ,
171173 invocation_context : Optional [InvocationContext ] = None ,
174+ part_converter : A2APartToGenAIPartConverter = convert_a2a_part_to_genai_part ,
172175) -> Event :
173176 """Converts an A2A task to an ADK event.
174177
@@ -177,6 +180,7 @@ def convert_a2a_task_to_event(
177180 author: The author of the event. Defaults to "a2a agent" if not provided.
178181 invocation_context: The invocation context containing session information.
179182 If provided, the branch will be set from the context.
183+ part_converter: The function to convert A2A part to GenAI part.
180184
181185 Returns:
182186 An ADK Event object representing the converted task.
@@ -203,7 +207,9 @@ def convert_a2a_task_to_event(
203207 # Convert message if available
204208 if message :
205209 try :
206- return convert_a2a_message_to_event (message , author , invocation_context )
210+ return convert_a2a_message_to_event (
211+ message , author , invocation_context , part_converter = part_converter
212+ )
207213 except Exception as e :
208214 logger .error ("Failed to convert A2A task message to event: %s" , e )
209215 raise RuntimeError (f"Failed to convert task message: { e } " ) from e
@@ -229,6 +235,7 @@ def convert_a2a_message_to_event(
229235 a2a_message : Message ,
230236 author : Optional [str ] = None ,
231237 invocation_context : Optional [InvocationContext ] = None ,
238+ part_converter : A2APartToGenAIPartConverter = convert_a2a_part_to_genai_part ,
232239) -> Event :
233240 """Converts an A2A message to an ADK event.
234241
@@ -237,6 +244,7 @@ def convert_a2a_message_to_event(
237244 author: The author of the event. Defaults to "a2a agent" if not provided.
238245 invocation_context: The invocation context containing session information.
239246 If provided, the branch will be set from the context.
247+ part_converter: The function to convert A2A part to GenAI part.
240248
241249 Returns:
242250 An ADK Event object with converted content and long-running tool metadata.
@@ -269,7 +277,7 @@ def convert_a2a_message_to_event(
269277
270278 for a2a_part in a2a_message .parts :
271279 try :
272- part = convert_a2a_part_to_genai_part (a2a_part )
280+ part = part_converter (a2a_part )
273281 if part is None :
274282 logger .warning ("Failed to convert A2A part, skipping: %s" , a2a_part )
275283 continue
@@ -322,13 +330,18 @@ def convert_a2a_message_to_event(
322330
323331@a2a_experimental
324332def convert_event_to_a2a_message (
325- event : Event , invocation_context : InvocationContext , role : Role = Role .agent
333+ event : Event ,
334+ invocation_context : InvocationContext ,
335+ role : Role = Role .agent ,
336+ part_converter : GenAIPartToA2APartConverter = convert_genai_part_to_a2a_part ,
326337) -> Optional [Message ]:
327338 """Converts an ADK event to an A2A message.
328339
329340 Args:
330341 event: The ADK event to convert.
331342 invocation_context: The invocation context.
343+ role: The role of the message.
344+ part_converter: The function to convert GenAI part to A2A part.
332345
333346 Returns:
334347 An A2A Message if the event has content, None otherwise.
@@ -347,7 +360,7 @@ def convert_event_to_a2a_message(
347360 try :
348361 a2a_parts = []
349362 for part in event .content .parts :
350- a2a_part = convert_genai_part_to_a2a_part (part )
363+ a2a_part = part_converter (part )
351364 if a2a_part :
352365 a2a_parts .append (a2a_part )
353366 _process_long_running_tool (a2a_part , event )
@@ -477,6 +490,7 @@ def convert_event_to_a2a_events(
477490 invocation_context : InvocationContext ,
478491 task_id : Optional [str ] = None ,
479492 context_id : Optional [str ] = None ,
493+ part_converter : GenAIPartToA2APartConverter = convert_genai_part_to_a2a_part ,
480494) -> List [A2AEvent ]:
481495 """Converts a GenAI event to a list of A2A events.
482496
@@ -485,6 +499,7 @@ def convert_event_to_a2a_events(
485499 invocation_context: The invocation context.
486500 task_id: Optional task ID to use for generated events.
487501 context_id: Optional Context ID to use for generated events.
502+ part_converter: The function to convert GenAI part to A2A part.
488503
489504 Returns:
490505 A list of A2A events representing the converted ADK event.
@@ -509,7 +524,9 @@ def convert_event_to_a2a_events(
509524 a2a_events .append (error_event )
510525
511526 # Handle regular message content
512- message = convert_event_to_a2a_message (event , invocation_context )
527+ message = convert_event_to_a2a_message (
528+ event , invocation_context , part_converter = part_converter
529+ )
513530 if message :
514531 running_event = _create_status_update_event (
515532 message , invocation_context , event , task_id , context_id
0 commit comments