Skip to content

Commit ce07202

Browse files
style: apply auto-formatting
1 parent 6692700 commit ce07202

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

examples/google_adk/french_translation_agent/adk_agent_executor.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
import logging
44

55
from collections.abc import AsyncGenerator, AsyncIterable
6+
from typing import Any
7+
from uuid import uuid4
68

7-
from adk_agent import create_french_translation_agent
89
from google.adk import Runner
10+
from google.adk.agents import LlmAgent, RunConfig
911
from google.adk.artifacts import InMemoryArtifactService
1012
from google.adk.events import Event
1113
from google.adk.memory.in_memory_memory_service import InMemoryMemoryService
1214
from google.adk.sessions import InMemorySessionService
1315
from google.genai import types as genai_types
16+
from pydantic import ConfigDict
1417

18+
from a2a.client import A2AClient
1519
from a2a.server.agent_execution import AgentExecutor, RequestContext
1620
from a2a.server.events.event_queue import EventQueue
1721
from a2a.server.tasks import TaskUpdater
@@ -20,14 +24,26 @@
2024
FilePart,
2125
FileWithBytes,
2226
FileWithUri,
27+
GetTaskRequest,
28+
GetTaskSuccessResponse,
29+
Message,
30+
MessageSendParams,
2331
Part,
32+
Role,
33+
SendMessageRequest,
34+
SendMessageSuccessResponse,
35+
Task,
36+
TaskQueryParams,
2437
TaskState,
2538
TaskStatus,
2639
TextPart,
2740
UnsupportedOperationError,
2841
)
42+
from a2a.utils import get_text_parts
2943
from a2a.utils.errors import ServerError
3044

45+
from adk_agent import create_french_translation_agent
46+
3147

3248
logger = logging.getLogger(__name__)
3349
logger.setLevel(logging.DEBUG)
@@ -51,12 +67,12 @@ def _run_agent(
5167
self,
5268
session_id: str,
5369
new_message: genai_types.Content,
54-
task_updater: TaskUpdater, # This parameter is not used in this method.
70+
task_updater: TaskUpdater, # This parameter is not used in this method.
5571
) -> AsyncGenerator[Event, None]:
5672
"""Runs the ADK agent with the given message."""
5773
return self.runner.run_async(
5874
session_id=session_id,
59-
user_id='self', # The user ID for the ADK session.
75+
user_id='self', # The user ID for the ADK session.
6076
new_message=new_message,
6177
)
6278

@@ -72,9 +88,7 @@ async def _process_request(
7288
)
7389
session_id = session.id
7490
async for event in self._run_agent(
75-
session_id,
76-
new_message,
77-
task_updater, # Pass task_updater to _run_agent
91+
session_id, new_message, task_updater # Pass task_updater to _run_agent
7892
):
7993
logger.debug('Received ADK event: %s', event)
8094
if event.is_final_response():
@@ -84,7 +98,7 @@ async def _process_request(
8498
task_updater.add_artifact(response)
8599
task_updater.complete()
86100
break
87-
if not event.get_function_calls():
101+
elif not event.get_function_calls():
88102
# If it's not a final response and no function calls, it's an interim update.
89103
logger.debug('Yielding update response')
90104
task_updater.update_status(
@@ -95,10 +109,8 @@ async def _process_request(
95109
)
96110
else:
97111
# This agent does not use tools, so function calls are unexpected.
98-
logger.debug(
99-
'Skipping event with function call: %s',
100-
event.get_function_calls(),
101-
)
112+
logger.debug('Skipping event with function call: %s', event.get_function_calls())
113+
102114

103115
async def execute(
104116
self,
@@ -131,12 +143,12 @@ async def _upsert_session(self, session_id: str):
131143

132144

133145
def convert_a2a_parts_to_genai(parts: list[Part]) -> list[genai_types.Part]:
134-
"""Converts a list of A2A Part objects to a list of Google GenAI Part objects."""
146+
"""Converts a list of A2A Part objects to a list of Google Gen AI Part objects."""
135147
return [convert_a2a_part_to_genai(part) for part in parts]
136148

137149

138150
def convert_a2a_part_to_genai(part: Part) -> genai_types.Part:
139-
"""Converts a single A2A Part object to a Google GenAI Part object."""
151+
"""Converts a single A2A Part object to a Google Gen AI Part object."""
140152
part = part.root
141153
if isinstance(part, TextPart):
142154
return genai_types.Part(text=part.text)
@@ -158,7 +170,7 @@ def convert_a2a_part_to_genai(part: Part) -> genai_types.Part:
158170

159171

160172
def convert_genai_parts_to_a2a(parts: list[genai_types.Part]) -> list[Part]:
161-
"""Converts a list of Google GenAI Part objects to a list of A2A Part objects."""
173+
"""Converts a list of Google Gen AI Part objects to a list of A2A Part objects."""
162174
return [
163175
convert_genai_part_to_a2a(part)
164176
for part in parts
@@ -167,7 +179,7 @@ def convert_genai_parts_to_a2a(parts: list[genai_types.Part]) -> list[Part]:
167179

168180

169181
def convert_genai_part_to_a2a(part: genai_types.Part) -> Part:
170-
"""Converts a single Google GenAI Part object to an A2A Part object."""
182+
"""Converts a single Google Gen AI Part object to an A2A Part object."""
171183
if part.text:
172184
return TextPart(text=part.text)
173185
if part.file_data:

0 commit comments

Comments
 (0)