Skip to content

Commit dc2b2a8

Browse files
Update cloud run scripts
1 parent 2f94f3b commit dc2b2a8

5 files changed

Lines changed: 35 additions & 44 deletions

File tree

samples/agent/adk/gemini_enterprise/cloud_run/agent.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,13 @@
2525
Part,
2626
TextPart,
2727
)
28-
<<<<<<< HEAD
29-
from a2ui.a2a import (
30-
get_a2ui_agent_extension,
31-
parse_response_to_parts,
32-
)
33-
from a2ui.basic_catalog.provider import BasicCatalog
34-
from a2ui.core.parser.parser import parse_response
35-
from a2ui.core.schema.common_modifiers import remove_strict_validation
36-
from a2ui.core.schema.constants import A2UI_CLOSE_TAG, A2UI_OPEN_TAG, VERSION_0_8
37-
from a2ui.core.schema.manager import A2uiSchemaManager
38-
=======
3928
from a2ui.a2a.extension import get_a2ui_agent_extension
4029
from a2ui.a2a.parts import parse_response_to_parts
4130
from a2ui.basic_catalog.provider import BasicCatalog
4231
from a2ui.parser.parser import parse_response
4332
from a2ui.schema.common_modifiers import remove_strict_validation
4433
from a2ui.schema.constants import A2UI_CLOSE_TAG, A2UI_OPEN_TAG, VERSION_0_8
4534
from a2ui.schema.manager import A2uiSchemaManager
46-
47-
>>>>>>> main
4835
import dotenv
4936
from google.adk.agents import run_config
5037
from google.adk.agents.llm_agent import LlmAgent
@@ -71,7 +58,9 @@ def __init__(self, base_url: str):
7158
self.base_url = base_url
7259
self._agent_name = "contact_agent"
7360
self._user_id = "remote_agent"
74-
self._text_runner: Optional[Runner] = self._build_runner(self._build_llm_agent())
61+
self._text_runner: Optional[Runner] = self._build_runner(
62+
self._build_llm_agent()
63+
)
7564

7665
self._schema_managers: Dict[str, A2uiSchemaManager] = {}
7766
self._ui_runners: Dict[str, Runner] = {}
@@ -137,7 +126,8 @@ def _build_agent_card(self) -> AgentCard:
137126
return AgentCard(
138127
name="Contact Lookup Agent",
139128
description=(
140-
"This agent helps find contact info for people in your organization."
129+
"This agent helps find contact info for people in your"
130+
" organization."
141131
),
142132
url=self.base_url,
143133
version="1.0.0",
@@ -225,7 +215,9 @@ async def fetch_response(
225215
current_query_text = query
226216

227217
# Ensure catalog schema was loaded
228-
if ui_version and (not selected_catalog or not selected_catalog.catalog_schema):
218+
if ui_version and (
219+
not selected_catalog or not selected_catalog.catalog_schema
220+
):
229221
logger.error(
230222
"--- ContactAgent.fetch_response: A2UI_SCHEMA is not loaded. "
231223
"Cannot perform UI validation. ---"
@@ -261,8 +253,14 @@ async def fetch_response(
261253
new_message=current_message,
262254
):
263255
if event.is_final_response():
264-
if event.content and event.content.parts and event.content.parts[0].text:
265-
full_content_list.extend([p.text for p in event.content.parts if p.text])
256+
if (
257+
event.content
258+
and event.content.parts
259+
and event.content.parts[0].text
260+
):
261+
full_content_list.extend(
262+
[p.text for p in event.content.parts if p.text]
263+
)
266264

267265
final_response_content = "".join(full_content_list)
268266

@@ -282,7 +280,8 @@ async def fetch_response(
282280
logger.info("Retries exhausted on no-response")
283281
# Retries exhausted on no-response
284282
final_response_content = (
285-
"I'm sorry, I encountered an error and couldn't process your request."
283+
"I'm sorry, I encountered an error and couldn't process your"
284+
" request."
286285
)
287286
# Fall through to send this as a text-only error
288287

@@ -341,7 +340,8 @@ async def fetch_response(
341340
f" (Attempt {attempt}) ---"
342341
)
343342
logger.warning(
344-
f"--- Failed response content: {final_response_content[:500]}... ---"
343+
"--- Failed response content:"
344+
f" {final_response_content[:500]}... ---"
345345
)
346346
error_message = f"Validation failed: {e}."
347347

samples/agent/adk/gemini_enterprise/cloud_run/agent_executor.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@
3030
new_task,
3131
)
3232
from a2a.utils.errors import ServerError
33-
<<<<<<< HEAD
3433
from a2ui.a2a import try_activate_a2ui_extension
35-
=======
36-
from a2ui.a2a.extension import try_activate_a2ui_extension
37-
>>>>>>> main
3834
from agent import ContactAgent
3935

4036
logger = logging.getLogger(__name__)
@@ -55,8 +51,12 @@ async def execute(
5551
ui_event_part = None
5652
action = None
5753

58-
logger.info(f"--- Client requested extensions: {context.requested_extensions} ---")
59-
active_ui_version = try_activate_a2ui_extension(context, self._agent.agent_card)
54+
logger.info(
55+
f"--- Client requested extensions: {context.requested_extensions} ---"
56+
)
57+
active_ui_version = try_activate_a2ui_extension(
58+
context, self._agent.agent_card
59+
)
6060

6161
if active_ui_version:
6262
logger.info(
@@ -65,7 +65,8 @@ async def execute(
6565
)
6666
else:
6767
logger.info(
68-
"--- AGENT_EXECUTOR: A2UI extension is not active. Using text runner. ---"
68+
"--- AGENT_EXECUTOR: A2UI extension is not active. Using text"
69+
" runner. ---"
6970
)
7071

7172
if context.message and context.message.parts:

samples/agent/adk/gemini_enterprise/cloud_run/prompt_builder.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
<<<<<<< HEAD
1615
from a2ui.core.schema.constants import A2UI_CLOSE_TAG, A2UI_OPEN_TAG
17-
=======
18-
from a2ui.schema.constants import A2UI_CLOSE_TAG, A2UI_OPEN_TAG
19-
>>>>>>> main
2016

2117
ROLE_DESCRIPTION = (
2218
"You are a helpful contact lookup assistant. Your final output MUST always"

samples/agent/adk/gemini_enterprise/cloud_run/pyproject.toml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ dependencies = [
2626
"uvicorn",
2727
"google-cloud-aiplatform>=1.84",
2828
"jsonschema>=4.0.0",
29-
<<<<<<< HEAD
30-
"a2ui-agent-sdk>=0.1.1",
31-
=======
32-
"a2ui-agent-sdk",
33-
>>>>>>> main
29+
"a2ui-agent-sdk>=0.1.2",
3430
]
3531

3632
[tool.hatch.build.targets.wheel]
@@ -49,9 +45,3 @@ default = true
4945

5046
[project.scripts]
5147
start = "main:serve"
52-
<<<<<<< HEAD
53-
=======
54-
55-
[tool.uv.sources]
56-
a2ui-agent-sdk = { path = "../../../../agent_sdks/python", editable = true }
57-
>>>>>>> main

samples/agent/adk/gemini_enterprise/cloud_run/tools.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@ def get_contact_info(name: str = None, department: str = "") -> str:
4646

4747
# Filter by name
4848
results = [
49-
contact for contact in all_contacts if name_lower in contact["name"].lower()
49+
contact
50+
for contact in all_contacts
51+
if name_lower in contact["name"].lower()
5052
]
5153

5254
# If department is provided, filter results further
5355
if dept_lower:
5456
results = [
55-
contact for contact in results if dept_lower in contact["department"].lower()
57+
contact
58+
for contact in results
59+
if dept_lower in contact["department"].lower()
5660
]
5761

5862
logger.info(f" - Success: Found {len(results)} matching contacts.")

0 commit comments

Comments
 (0)