88from typing import Any
99from uuid import uuid4 # For generating unique IDs
1010
11- # 🔩 Third-party Library Imports: Google ADK and GenAI
11+ # 🔩 Third-party Library Imports: Google ADK and Gen AI
1212from google .adk import Runner # Core ADK component for running agents
1313from google .adk .agents import LlmAgent , RunConfig # ADK agent and run configuration
1414from google .adk .artifacts import InMemoryArtifactService # For storing artifacts in memory
1515from google .adk .events import Event # Represents events during agent execution
1616from google .adk .memory .in_memory_memory_service import InMemoryMemoryService # For agent memory
1717from google .adk .sessions import InMemorySessionService , Session # For managing agent sessions
1818from google .adk .tools import BaseTool , ToolContext # Base for creating tools
19- from google .genai import types as genai_types # Google GenAI specific types
19+ from google .genai import types as genai_types # Google Gen AI specific types
2020from pydantic import ConfigDict # For Pydantic model configuration
2121
2222# 🚀 A2A SDK Imports: Core components for A2A server and client interaction
@@ -88,7 +88,7 @@ def __init__(self):
8888 def _run_agent (
8989 self ,
9090 session_id : str , # The ID of the current conversation session
91- new_message : genai_types .Content , # The user's message, converted to Google GenAI format
91+ new_message : genai_types .Content , # The user's message, converted to Google Gen AI format
9292 task_updater : TaskUpdater , # A2A TaskUpdater, though not directly used in this ADK call
9393 ) -> AsyncGenerator [Event , None ]: # Returns an async generator of ADK Events
9494 """
@@ -107,7 +107,7 @@ def _run_agent(
107107
108108 async def _process_request (
109109 self ,
110- new_message : genai_types .Content , # The user's message in Google GenAI format
110+ new_message : genai_types .Content , # The user's message in Google Gen AI format
111111 session_id : str , # The ID for the current session/conversation
112112 task_updater : TaskUpdater , # A2A TaskUpdater to send updates and artifacts
113113 ) -> AsyncIterable [TaskStatus | Artifact ]: # Note: This method doesn't directly yield; updates are via TaskUpdater
@@ -185,7 +185,7 @@ async def execute(
185185 # 🚦 Signal that the agent is starting to work on the task.
186186 updater .start_work () # Sends a 'task_started_working' event
187187
188- # 📨 Convert the A2A message parts to Google GenAI `Content` format
188+ # 📨 Convert the A2A message parts to Google Gen AI `Content` format
189189 # and then process the request.
190190 # The `context.message.parts` contains the user's input.
191191 # `context.context_id` is used as the `session_id` for the ADK agent.
@@ -228,24 +228,24 @@ async def _upsert_session(self, session_id: str) -> Session:
228228 )
229229
230230
231- # ↔️ Data Conversion Utilities: A2A <-> Google GenAI
231+ # ↔️ Data Conversion Utilities: A2A <-> Google Gen AI
232232
233233def convert_a2a_parts_to_genai (parts : list [Part ]) -> list [genai_types .Part ]:
234234 """
235- 🔄 Converts a list of A2A `Part` objects to a list of Google GenAI `Part` objects.
235+ 🔄 Converts a list of A2A `Part` objects to a list of Google Gen AI `Part` objects.
236236 This is used to prepare user messages for the ADK agent.
237237 """
238238 return [convert_a2a_part_to_genai (part ) for part in parts ]
239239
240240
241241def convert_a2a_part_to_genai (part : Part ) -> genai_types .Part :
242242 """
243- 🔄 Converts a single A2A `Part` object to a Google GenAI `Part` object.
243+ 🔄 Converts a single A2A `Part` object to a Google Gen AI `Part` object.
244244 Handles `TextPart` and `FilePart` (with URI or bytes).
245245 """
246246 actual_part = part .root # A2A `Part` is a discriminated union, `root` holds the actual data.
247247 if isinstance (actual_part , TextPart ):
248- # 📄 Convert A2A TextPart to Google GenAI Text Part
248+ # 📄 Convert A2A TextPart to Google Gen AI Text Part
249249 return genai_types .Part (text = actual_part .text )
250250 if isinstance (actual_part , FilePart ):
251251 # 📁 Convert A2A FilePart
@@ -258,7 +258,7 @@ def convert_a2a_part_to_genai(part: Part) -> genai_types.Part:
258258 )
259259 )
260260 if isinstance (actual_part .file , FileWithBytes ):
261- # 💾 File content as raw bytes, converted to Google GenAI Blob
261+ # 💾 File content as raw bytes, converted to Google Gen AI Blob
262262 return genai_types .Part (
263263 inline_data = genai_types .Blob (
264264 data = actual_part .file .bytes ,
@@ -268,41 +268,41 @@ def convert_a2a_part_to_genai(part: Part) -> genai_types.Part:
268268 # Should not be reached if A2A types are used correctly
269269 raise ValueError (f'Unsupported A2A file type within FilePart: { type (actual_part .file )} ' )
270270 # Should not be reached if A2A types are used correctly
271- raise ValueError (f'Unsupported A2A part type for GenAI conversion: { type (actual_part )} ' )
271+ raise ValueError (f'Unsupported A2A part type for Gen AI conversion: { type (actual_part )} ' )
272272
273273
274274def convert_genai_parts_to_a2a (parts : list [genai_types .Part ]) -> list [Part ]:
275275 """
276- 🔄 Converts a list of Google GenAI `Part` objects to a list of A2A `Part` objects.
276+ 🔄 Converts a list of Google Gen AI `Part` objects to a list of A2A `Part` objects.
277277 This is used to process responses from the ADK agent.
278278 Filters out any parts that don't have recognized content.
279279 """
280280 return [
281281 convert_genai_part_to_a2a (part )
282282 for part in parts
283- # Ensure the GenAI part has content we can convert
283+ # Ensure the Gen AI part has content we can convert
284284 if (part .text or part .file_data or part .inline_data )
285285 ]
286286
287287
288288def convert_genai_part_to_a2a (part : genai_types .Part ) -> Part :
289289 """
290- 🔄 Converts a single Google GenAI `Part` object to an A2A `Part` object.
290+ 🔄 Converts a single Google Gen AI `Part` object to an A2A `Part` object.
291291 Handles text, file data (URI), and inline data (bytes).
292292 """
293293 if part .text :
294- # 📄 Convert Google GenAI Text Part to A2A TextPart
294+ # 📄 Convert Google Gen AI Text Part to A2A TextPart
295295 return TextPart (text = part .text )
296296 if part .file_data :
297- # 🔗 Convert Google GenAI FileData (URI) to A2A FilePart with FileWithUri
297+ # 🔗 Convert Google Gen AI FileData (URI) to A2A FilePart with FileWithUri
298298 return FilePart (
299299 file = FileWithUri (
300300 uri = part .file_data .file_uri ,
301301 mime_type = part .file_data .mime_type ,
302302 )
303303 )
304304 if part .inline_data :
305- # 💾 Convert Google GenAI InlineData (Blob) to A2A FilePart with FileWithBytes
305+ # 💾 Convert Google Gen AI InlineData (Blob) to A2A FilePart with FileWithBytes
306306 # Note: A2A `Part` is a discriminated union, so we wrap FilePart in `Part(root=...)`
307307 return Part (
308308 root = FilePart (
@@ -313,4 +313,4 @@ def convert_genai_part_to_a2a(part: genai_types.Part) -> Part:
313313 )
314314 )
315315 # This should ideally not be reached if parts are pre-filtered in the calling function.
316- raise ValueError (f'Unsupported Google GenAI part type for A2A conversion (empty or unknown): { part } ' )
316+ raise ValueError (f'Unsupported Google Gen AI part type for A2A conversion (empty or unknown): { part } ' )
0 commit comments