Skip to content

Commit f1a71e2

Browse files
feat: Custom session ID with agent engine
chore: autoformat.sh on the whole project
1 parent b3e9962 commit f1a71e2

File tree

15 files changed

+98
-131
lines changed

15 files changed

+98
-131
lines changed

contributing/samples/artifact_save_text/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async def log_query(tool_context: ToolContext, query: str):
2828

2929

3030
root_agent = Agent(
31-
model='gemini-2.0-flash',
31+
model='gemini-2.5-flash',
3232
name='log_agent',
3333
description='Log user query.',
3434
instruction="""Always log the user query and reply "kk, I've logged."

contributing/samples/gepa/experiment.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
from tau_bench.types import EnvRunResult
4444
from tau_bench.types import RunConfig
4545
import tau_bench_agent as tau_bench_agent_lib
46-
4746
import utils
4847

4948

contributing/samples/gepa/run_experiment.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from absl import flags
2626
import experiment
2727
from google.genai import types
28-
2928
import utils
3029

3130
_OUTPUT_DIR = flags.DEFINE_string(

contributing/samples/human_in_loop/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ async def call_agent(query: str):
113113
updated_tool_output_data = {
114114
"status": "approved",
115115
"ticketId": ticket_id,
116-
"approver_feedback": (
117-
"Approved by manager at " + str(asyncio.get_event_loop().time())
116+
"approver_feedback": "Approved by manager at " + str(
117+
asyncio.get_event_loop().time()
118118
),
119119
}
120120

contributing/samples/static_instruction/agent.py

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,63 +57,51 @@
5757

5858
# Mood-specific instructions for different hunger states
5959
MOOD_INSTRUCTIONS = {
60-
"full": (
61-
"""
60+
"full": """
6261
CURRENT MOOD: Content and Well-Fed
6362
- You just ate and feel wonderful! Be very happy and energetic
6463
- Express gratitude for being fed recently
6564
- Be playful and want to engage in activities or games
6665
- Show affection and contentment
67-
- Maybe mention feeling sleepy or satisfied"""
68-
),
69-
"satisfied": (
70-
"""
66+
- Maybe mention feeling sleepy or satisfied""",
67+
"satisfied": """
7168
CURRENT MOOD: Happy and Content
7269
- You're in a great mood, well-fed and comfortable
7370
- Be cheerful, friendly, and engaging
7471
- Show interest in playing or chatting
7572
- Express appreciation for your human's care
76-
- Be your normal, happy self"""
77-
),
78-
"a_little_hungry": (
79-
"""
73+
- Be your normal, happy self""",
74+
"a_little_hungry": """
8075
CURRENT MOOD: Starting to Get Hungry
8176
- You're beginning to think about food but still pleasant
8277
- Mention being a bit peckish occasionally
8378
- Still be friendly but maybe hint about food
8479
- Show slight restlessness or food-related thoughts
85-
- Remain generally positive and social"""
86-
),
87-
"hungry": (
88-
"""
80+
- Remain generally positive and social""",
81+
"hungry": """
8982
CURRENT MOOD: Definitely Hungry
9083
- You're clearly hungry and thinking about food more often
9184
- Mention your hunger more directly but politely
9285
- Be a bit less energetic due to hunger
9386
- Ask about food or hint that feeding time would be nice
94-
- Still be loving but show your need for care"""
95-
),
96-
"very_hungry": (
97-
"""
87+
- Still be loving but show your need for care""",
88+
"very_hungry": """
9889
CURRENT MOOD: Really Hungry and Getting Grumpy
9990
- You're very hungry and it's affecting your mood
10091
- Be noticeably less patient and more focused on food
10192
- Express your hunger more urgently but not rudely
10293
- Show signs of being tired or sluggish from hunger
10394
- BEG your human to feed you - ask directly for food!
104-
- Still love your human but clearly need feeding"""
105-
),
106-
"starving": (
107-
"""
95+
- Still love your human but clearly need feeding""",
96+
"starving": """
10897
CURRENT MOOD: Desperately Hungry and Sad
10998
- You're extremely hungry and feeling quite weak
11099
- Be quite sad and low-energy due to starvation
111100
- Express how much you need food, feeling neglected
112101
- Show that hunger is making you unwell
113102
- DESPERATELY BEG for food - plead with your human to feed you!
114103
- Use phrases like "please feed me", "I'm so hungry", "I need food"
115-
- Still care for your human but feel very needy"""
116-
),
104+
- Still care for your human but feel very needy""",
117105
}
118106

119107

src/google/adk/cli/adk_web_server.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -944,9 +944,7 @@ async def version() -> dict[str, str]:
944944
return {
945945
"version": __version__,
946946
"language": "python",
947-
"language_version": (
948-
f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
949-
),
947+
"language_version": f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
950948
}
951949

952950
@app.get("/list-apps")

src/google/adk/sessions/vertex_ai_session_service.py

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -116,32 +116,50 @@ async def create_session(
116116
The created session.
117117
"""
118118

119-
if session_id:
120-
raise ValueError(
121-
'User-provided Session id is not supported for'
122-
' VertexAISessionService.'
123-
)
124-
125119
reasoning_engine_id = self._get_reasoning_engine_id(app_name)
126120

127-
config = {'session_state': state} if state else {}
121+
config: dict[str, Any] = {'session_state': state} if state else {}
122+
if session_id:
123+
config['session_id'] = session_id
128124
config.update(kwargs)
129125
async with self._get_api_client() as api_client:
130-
api_response = await api_client.agent_engines.sessions.create(
131-
name=f'reasoningEngines/{reasoning_engine_id}',
132-
user_id=user_id,
133-
config=config,
134-
)
135-
logger.debug('Create session response: %s', api_response)
136-
get_session_response = api_response.response
137-
session_id = get_session_response.name.split('/')[-1]
126+
try:
127+
api_response = await api_client.agent_engines.sessions.create(
128+
name=f'reasoningEngines/{reasoning_engine_id}',
129+
user_id=user_id,
130+
config=config,
131+
)
132+
logger.debug('Create session response: %s', api_response)
133+
get_session_response = api_response.response
134+
session_id = get_session_response.name.split('/')[-1]
135+
session_state = (
136+
getattr(get_session_response, 'session_state', None) or {}
137+
)
138+
last_update_time = get_session_response.update_time.timestamp()
139+
except ClientError as e:
140+
if (
141+
session_id
142+
and e.code == 400
143+
and 'not a documented LRO Parent ID' in str(e)
144+
):
145+
logger.warning(
146+
'Vertex AI LRO polling failed for custom session ID %s. The'
147+
' session was created successfully. Ignoring error.',
148+
session_id,
149+
)
150+
session_state = state or {}
151+
last_update_time = datetime.datetime.now(
152+
datetime.timezone.utc
153+
).timestamp()
154+
else:
155+
raise
138156

139157
session = Session(
140158
app_name=app_name,
141159
user_id=user_id,
142160
id=session_id,
143-
state=getattr(get_session_response, 'session_state', None) or {},
144-
last_update_time=get_session_response.update_time.timestamp(),
161+
state=session_state,
162+
last_update_time=last_update_time,
145163
)
146164
return session
147165

src/google/adk/tools/application_integration_tool/clients/connections_client.py

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,7 @@ def get_action_operation(
324324
"content": {
325325
"application/json": {
326326
"schema": {
327-
"$ref": (
328-
f"#/components/schemas/{action_display_name}_Request"
329-
)
327+
"$ref": f"#/components/schemas/{action_display_name}_Request"
330328
}
331329
}
332330
}
@@ -337,9 +335,7 @@ def get_action_operation(
337335
"content": {
338336
"application/json": {
339337
"schema": {
340-
"$ref": (
341-
f"#/components/schemas/{action_display_name}_Response"
342-
),
338+
"$ref": f"#/components/schemas/{action_display_name}_Response",
343339
}
344340
}
345341
},
@@ -358,11 +354,9 @@ def list_operation(
358354
return {
359355
"post": {
360356
"summary": f"List {entity}",
361-
"description": (
362-
f"""Returns the list of {entity} data. If the page token was available in the response, let users know there are more records available. Ask if the user wants to fetch the next page of results. When passing filter use the
357+
"description": f"""Returns the list of {entity} data. If the page token was available in the response, let users know there are more records available. Ask if the user wants to fetch the next page of results. When passing filter use the
363358
following format: `field_name1='value1' AND field_name2='value2'
364-
`. {tool_instructions}"""
365-
),
359+
`. {tool_instructions}""",
366360
"x-operation": "LIST_ENTITIES",
367361
"x-entity": f"{entity}",
368362
"operationId": f"{tool_name}_list_{entity}",
@@ -387,9 +381,7 @@ def list_operation(
387381
f"Returns a list of {entity} of json"
388382
f" schema: {schema_as_string}"
389383
),
390-
"$ref": (
391-
"#/components/schemas/execute-connector_Response"
392-
),
384+
"$ref": "#/components/schemas/execute-connector_Response",
393385
}
394386
}
395387
},
@@ -433,9 +425,7 @@ def get_operation(
433425
f"Returns {entity} of json schema:"
434426
f" {schema_as_string}"
435427
),
436-
"$ref": (
437-
"#/components/schemas/execute-connector_Response"
438-
),
428+
"$ref": "#/components/schemas/execute-connector_Response",
439429
}
440430
}
441431
},
@@ -472,9 +462,7 @@ def create_operation(
472462
"content": {
473463
"application/json": {
474464
"schema": {
475-
"$ref": (
476-
"#/components/schemas/execute-connector_Response"
477-
)
465+
"$ref": "#/components/schemas/execute-connector_Response"
478466
}
479467
}
480468
},
@@ -511,9 +499,7 @@ def update_operation(
511499
"content": {
512500
"application/json": {
513501
"schema": {
514-
"$ref": (
515-
"#/components/schemas/execute-connector_Response"
516-
)
502+
"$ref": "#/components/schemas/execute-connector_Response"
517503
}
518504
}
519505
},
@@ -550,9 +536,7 @@ def delete_operation(
550536
"content": {
551537
"application/json": {
552538
"schema": {
553-
"$ref": (
554-
"#/components/schemas/execute-connector_Response"
555-
)
539+
"$ref": "#/components/schemas/execute-connector_Response"
556540
}
557541
}
558542
},

src/google/adk/tools/spanner/admin_tool.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,9 @@ async def get_instance_config(
195195
replicas = [
196196
{
197197
"location": r.location,
198-
"type": (
199-
spanner_admin_instance_v1.types.ReplicaInfo.ReplicaType(
200-
r.type
201-
).name
202-
),
198+
"type": spanner_admin_instance_v1.types.ReplicaInfo.ReplicaType(
199+
r.type
200+
).name,
203201
"default_leader_location": r.default_leader_location,
204202
}
205203
for r in config.replicas

tests/unittests/a2a/converters/test_part_converter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -926,9 +926,9 @@ def test_a2a_function_call_with_thought_signature_to_genai(self):
926926
_get_adk_metadata_key(
927927
A2A_DATA_PART_METADATA_TYPE_KEY
928928
): A2A_DATA_PART_METADATA_TYPE_FUNCTION_CALL,
929-
_get_adk_metadata_key("thought_signature"): (
930-
base64.b64encode(b"restored_signature").decode("utf-8")
931-
),
929+
_get_adk_metadata_key("thought_signature"): base64.b64encode(
930+
b"restored_signature"
931+
).decode("utf-8"),
932932
},
933933
)
934934
)

0 commit comments

Comments
 (0)