11import asyncio
22import logging
3-
4- from collections .abc import AsyncGenerator , AsyncIterable
5- from typing import Any
3+ from collections .abc import AsyncGenerator
4+ from typing import Any , AsyncIterable
65from uuid import uuid4
76
87import httpx
9-
108from google .adk import Runner
119from google .adk .agents import LlmAgent , RunConfig
1210from google .adk .artifacts import InMemoryArtifactService
4442from a2a .utils import get_text_parts
4543from a2a .utils .errors import ServerError
4644
47-
4845logger = logging .getLogger (__name__ )
4946logger .setLevel (logging .DEBUG )
5047
@@ -69,7 +66,7 @@ def __init__(self, calendar_agent_url):
6966 name = 'birthday_planner_agent' ,
7067 description = 'An agent that helps manage birthday parties.' ,
7168 after_tool_callback = self ._handle_auth_required_task ,
72- instruction = """
69+ instruction = f """
7370 You are an agent that helps plan birthday parties.
7471
7572 Your job as a party planner is to act as a sounding board and idea generator for
@@ -168,7 +165,7 @@ async def _process_request(
168165 task_updater .add_artifact (response )
169166 task_updater .complete ()
170167 break
171- if calls := event .get_function_calls ():
168+ elif calls := event .get_function_calls ():
172169 for call in calls :
173170 # Provide an update on what we're doing.
174171 if call .name == 'message_calendar_agent' :
@@ -317,21 +314,23 @@ def convert_a2a_part_to_genai(part: Part) -> types.Part:
317314 part = part .root
318315 if isinstance (part , TextPart ):
319316 return types .Part (text = part .text )
320- if isinstance (part , FilePart ):
317+ elif isinstance (part , FilePart ):
321318 if isinstance (part .file , FileWithUri ):
322319 return types .Part (
323320 file_data = types .FileData (
324321 file_uri = part .file .uri , mime_type = part .file .mime_type
325322 )
326323 )
327- if isinstance (part .file , FileWithBytes ):
324+ elif isinstance (part .file , FileWithBytes ):
328325 return types .Part (
329326 inline_data = types .Blob (
330327 data = part .file .bytes , mime_type = part .file .mime_type
331328 )
332329 )
333- raise ValueError (f'Unsupported file type: { type (part .file )} ' )
334- raise ValueError (f'Unsupported part type: { type (part )} ' )
330+ else :
331+ raise ValueError (f'Unsupported file type: { type (part .file )} ' )
332+ else :
333+ raise ValueError (f'Unsupported part type: { type (part )} ' )
335334
336335
337336def convert_genai_parts_to_a2a (parts : list [types .Part ]) -> list [Part ]:
@@ -347,14 +346,14 @@ def convert_genai_part_to_a2a(part: types.Part) -> Part:
347346 """Convert a single Google GenAI Part type into an A2A Part type."""
348347 if part .text :
349348 return TextPart (text = part .text )
350- if part .file_data :
349+ elif part .file_data :
351350 return FilePart (
352351 file = FileWithUri (
353352 uri = part .file_data .file_uri ,
354353 mime_type = part .file_data .mime_type ,
355354 )
356355 )
357- if part .inline_data :
356+ elif part .inline_data :
358357 return Part (
359358 root = FilePart (
360359 file = FileWithBytes (
@@ -363,4 +362,5 @@ def convert_genai_part_to_a2a(part: types.Part) -> Part:
363362 )
364363 )
365364 )
366- raise ValueError (f'Unsupported part type: { part } ' )
365+ else :
366+ raise ValueError (f'Unsupported part type: { part } ' )
0 commit comments