Skip to content

Commit 6692700

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

File tree

22 files changed

+696
-501
lines changed

22 files changed

+696
-501
lines changed

.github/actions/spelling/allow.txt

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,58 @@ AClient
33
AError
44
ARequest
55
ARun
6+
ASGI
67
AServer
78
AServers
89
AStarlette
910
EUR
1011
GBP
12+
GPT
1113
INR
1214
JPY
1315
JSONRPCt
16+
LLMs
1417
Llm
1518
aconnect
1619
adk
1720
agentic
1821
autouse
22+
avanc
23+
avancées
1924
cla
2025
cls
2126
coc
2227
codegen
2328
coro
29+
dans
2430
datamodel
31+
derni
32+
dernières
33+
docstrings
2534
dunders
2635
genai
2736
gle
37+
gpt
2838
inmemory
2939
kwarg
40+
l'actualit
41+
l'actualité
3042
langgraph
3143
lifecycles
3244
linting
45+
llm
46+
m'appelle
47+
mcp
48+
mundo
49+
npx
3350
oauthoidc
3451
opensource
3552
pyversions
53+
résultats
3654
socio
3755
sse
56+
sultats
3857
tagwords
58+
thiques
3959
vulnz
40-
ASGI
41-
avancées
42-
dans
43-
dernières
44-
docstrings
45-
GPT
46-
gpt
47-
l'actualité
48-
llm
49-
LLMs
50-
m'appelle
51-
mcp
52-
mundo
53-
npx
54-
résultats
5560
éthiques

.vscode/settings.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
2-
"python.testing.pytestArgs": ["tests"],
2+
"python.testing.pytestArgs": [
3+
"tests"
4+
],
35
"python.testing.unittestEnabled": false,
46
"python.testing.pytestEnabled": true,
57
"editor.formatOnSave": true,
@@ -11,4 +13,4 @@
1113
}
1214
},
1315
"ruff.importStrategy": "fromEnvironment"
14-
}
16+
}

examples/google_adk/french_translation_agent/__main__.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
import asyncio
2-
import functools
31
import logging
42
import os
5-
import sys
63

74
import click
85
import uvicorn
96

7+
from adk_agent_executor import ADKFrenchTranslationAgentExecutor
108
from dotenv import load_dotenv
119

1210
from a2a.server.apps import A2AStarletteApplication
1311
from a2a.server.request_handlers import DefaultRequestHandler
1412
from a2a.server.tasks import InMemoryTaskStore
1513
from a2a.types import AgentCapabilities, AgentCard, AgentSkill
1614

17-
from adk_agent_executor import ADKFrenchTranslationAgentExecutor
18-
1915

2016
load_dotenv()
2117

@@ -30,7 +26,9 @@
3026
def main(host: str, port: int):
3127
# Ensure GOOGLE_API_KEY is set for the Gemini model used by this agent.
3228
if not os.getenv('GOOGLE_API_KEY'):
33-
logger.error('GOOGLE_API_KEY environment variable not set. This agent may not function correctly.')
29+
logger.error(
30+
'GOOGLE_API_KEY environment variable not set. This agent may not function correctly.'
31+
)
3432

3533
# Define the capabilities and skills of this French Translation Agent.
3634
skill = AgentSkill(
@@ -53,15 +51,19 @@ def main(host: str, port: int):
5351
defaultInputModes=['text'],
5452
defaultOutputModes=['text'],
5553
capabilities=AgentCapabilities(streaming=True),
56-
skills=[skill]
54+
skills=[skill],
5755
)
5856
request_handler = DefaultRequestHandler(
5957
agent_executor=agent_executor, task_store=InMemoryTaskStore()
6058
)
6159
app = A2AStarletteApplication(agent_card, request_handler)
6260

63-
logger.info(f"Starting French Translation Agent server on http://{host}:{port}")
64-
logger.info(f"This agent is identified by 'french_translator' for delegation.")
61+
logger.info(
62+
f'Starting French Translation Agent server on http://{host}:{port}'
63+
)
64+
logger.info(
65+
"This agent is identified by 'french_translator' for delegation."
66+
)
6567
uvicorn.run(app.build(), host=host, port=port)
6668

6769

examples/google_adk/french_translation_agent/adk_agent.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import os
2+
23
from google.adk.agents import LlmAgent
34

5+
46
async def create_french_translation_agent() -> LlmAgent:
57
"""Constructs the ADK French Translation agent."""
68
# Ensure GOOGLE_API_KEY is set for Gemini model usage.
7-
if not os.getenv("GOOGLE_API_KEY"):
8-
print("Warning: GOOGLE_API_KEY environment variable not set. This agent may not function correctly.")
9+
if not os.getenv('GOOGLE_API_KEY'):
10+
print(
11+
'Warning: GOOGLE_API_KEY environment variable not set. This agent may not function correctly.'
12+
)
913

1014
return LlmAgent(
1115
model='gemini-1.5-flash',

examples/google_adk/french_translation_agent/adk_agent_executor.py

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

55
from collections.abc import AsyncGenerator, AsyncIterable
6-
from typing import Any
7-
from uuid import uuid4
86

7+
from adk_agent import create_french_translation_agent
98
from google.adk import Runner
10-
from google.adk.agents import LlmAgent, RunConfig
119
from google.adk.artifacts import InMemoryArtifactService
1210
from google.adk.events import Event
1311
from google.adk.memory.in_memory_memory_service import InMemoryMemoryService
1412
from google.adk.sessions import InMemorySessionService
1513
from google.genai import types as genai_types
16-
from pydantic import ConfigDict
1714

18-
from a2a.client import A2AClient
1915
from a2a.server.agent_execution import AgentExecutor, RequestContext
2016
from a2a.server.events.event_queue import EventQueue
2117
from a2a.server.tasks import TaskUpdater
@@ -24,26 +20,14 @@
2420
FilePart,
2521
FileWithBytes,
2622
FileWithUri,
27-
GetTaskRequest,
28-
GetTaskSuccessResponse,
29-
Message,
30-
MessageSendParams,
3123
Part,
32-
Role,
33-
SendMessageRequest,
34-
SendMessageSuccessResponse,
35-
Task,
36-
TaskQueryParams,
3724
TaskState,
3825
TaskStatus,
3926
TextPart,
4027
UnsupportedOperationError,
4128
)
42-
from a2a.utils import get_text_parts
4329
from a2a.utils.errors import ServerError
4430

45-
from adk_agent import create_french_translation_agent
46-
4731

4832
logger = logging.getLogger(__name__)
4933
logger.setLevel(logging.DEBUG)
@@ -67,12 +51,12 @@ def _run_agent(
6751
self,
6852
session_id: str,
6953
new_message: genai_types.Content,
70-
task_updater: TaskUpdater, # This parameter is not used in this method.
54+
task_updater: TaskUpdater, # This parameter is not used in this method.
7155
) -> AsyncGenerator[Event, None]:
7256
"""Runs the ADK agent with the given message."""
7357
return self.runner.run_async(
7458
session_id=session_id,
75-
user_id='self', # The user ID for the ADK session.
59+
user_id='self', # The user ID for the ADK session.
7660
new_message=new_message,
7761
)
7862

@@ -88,7 +72,9 @@ async def _process_request(
8872
)
8973
session_id = session.id
9074
async for event in self._run_agent(
91-
session_id, new_message, task_updater # Pass task_updater to _run_agent
75+
session_id,
76+
new_message,
77+
task_updater, # Pass task_updater to _run_agent
9278
):
9379
logger.debug('Received ADK event: %s', event)
9480
if event.is_final_response():
@@ -98,7 +84,7 @@ async def _process_request(
9884
task_updater.add_artifact(response)
9985
task_updater.complete()
10086
break
101-
elif not event.get_function_calls():
87+
if not event.get_function_calls():
10288
# If it's not a final response and no function calls, it's an interim update.
10389
logger.debug('Yielding update response')
10490
task_updater.update_status(
@@ -109,8 +95,10 @@ async def _process_request(
10995
)
11096
else:
11197
# This agent does not use tools, so function calls are unexpected.
112-
logger.debug('Skipping event with function call: %s', event.get_function_calls())
113-
98+
logger.debug(
99+
'Skipping event with function call: %s',
100+
event.get_function_calls(),
101+
)
114102

115103
async def execute(
116104
self,

examples/google_adk/mcp_brave_search_agent/__main__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
import asyncio
2-
import functools
31
import logging
42
import os
53
import sys
64

75
import click
86
import uvicorn
97

8+
from adk_agent_executor import ADKBraveSearchAgentExecutor
109
from dotenv import load_dotenv
1110

1211
from a2a.server.apps import A2AStarletteApplication
1312
from a2a.server.request_handlers import DefaultRequestHandler
1413
from a2a.server.tasks import InMemoryTaskStore
1514
from a2a.types import AgentCapabilities, AgentCard, AgentSkill
1615

17-
from adk_agent_executor import ADKBraveSearchAgentExecutor
18-
1916

2017
load_dotenv()
2118

@@ -28,7 +25,9 @@
2825
def main(host: str, port: int):
2926
# Ensure BRAVE_API_KEY is set for the Brave Search MCP server.
3027
if not os.getenv('BRAVE_API_KEY'):
31-
print('BRAVE_API_KEY environment variable not set. This agent requires it to function.')
28+
print(
29+
'BRAVE_API_KEY environment variable not set. This agent requires it to function.'
30+
)
3231
sys.exit(1)
3332

3433
# Define the capabilities and skills of this Brave Search Agent.

examples/google_adk/mcp_brave_search_agent/adk_agent.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import os
2+
23
from google.adk.agents import LlmAgent
3-
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset, StdioServerParameters
4+
from google.adk.tools.mcp_tool.mcp_toolset import (
5+
MCPToolset,
6+
StdioServerParameters,
7+
)
8+
49

510
async def create_mcp_brave_search_agent() -> LlmAgent:
611
"""Constructs the ADK MCP Brave Search agent."""
7-
brave_api_key = os.getenv("BRAVE_API_KEY")
12+
brave_api_key = os.getenv('BRAVE_API_KEY')
813
if not brave_api_key:
9-
raise ValueError("BRAVE_API_KEY environment variable not set. This agent requires it.")
14+
raise ValueError(
15+
'BRAVE_API_KEY environment variable not set. This agent requires it.'
16+
)
1017

1118
return LlmAgent(
1219
model='gemini-2.0-flash',
@@ -24,12 +31,10 @@ async def create_mcp_brave_search_agent() -> LlmAgent:
2431
connection_params=StdioServerParameters(
2532
command='npx',
2633
args=[
27-
"-y",
28-
"@modelcontextprotocol/server-brave-search",
34+
'-y',
35+
'@modelcontextprotocol/server-brave-search',
2936
],
30-
env={
31-
"BRAVE_API_KEY": brave_api_key
32-
}
37+
env={'BRAVE_API_KEY': brave_api_key},
3338
),
3439
)
3540
],

0 commit comments

Comments
 (0)