MCPcopy
hub / github.com/google/adk-python / _normalize_ids

Function _normalize_ids

src/google/adk/cli/agent_test_runner.py:349–428  ·  view source on GitHub ↗

Filters partial events and normalizes event, function call, and response IDs.

(events: list[AdkEvent])

Source from the content-addressed store, hash-verified

347
348
349def _normalize_ids(events: list[AdkEvent]) -> list[AdkEvent]:
350 """Filters partial events and normalizes event, function call, and response IDs."""
351 events = [e for e in events if not getattr(e, "partial", False)]
352
353 # Re-assign sequential event IDs
354 for i, e in enumerate(events, 1):
355 e.id = f"e-{i}"
356
357 # Post-process all events to inject deterministic function IDs
358 final_fc_counter = 0
359 final_orig_to_new_id = {}
360 for e in events:
361 for fc in e.get_function_calls():
362 orig_id = fc.id
363 final_fc_counter += 1
364 new_id = f"fc-{final_fc_counter}"
365 final_orig_to_new_id[orig_id] = new_id
366 fc.id = new_id
367 if e.long_running_tool_ids:
368 e.long_running_tool_ids = {
369 new_id if tid == orig_id else tid for tid in e.long_running_tool_ids
370 }
371 if fc.args:
372 for k, v in fc.args.items():
373 if v == orig_id:
374 fc.args[k] = new_id
375
376 # Pass 2: Update actions and user responses in all events
377 call_name_to_ids = {}
378 for e in events:
379 for fc in e.get_function_calls():
380 call_name_to_ids.setdefault(fc.name, []).append(fc.id)
381
382 if getattr(e, "branch", None) and e.branch.startswith("task:"):
383 parts = e.branch.split(":")
384 if len(parts) > 1:
385 fc_id = parts[1]
386 if fc_id in final_orig_to_new_id:
387 e.branch = f"task:{final_orig_to_new_id[fc_id]}"
388
389 # Task wrappers stamp isolation_scope with the dispatching FC's
390 # id (random at run time) and ``node_info.path`` encodes
391 # ``<name>@<fc.id>`` for the same id — remap both.
392 if e.isolation_scope in final_orig_to_new_id:
393 e.isolation_scope = final_orig_to_new_id[e.isolation_scope]
394 if e.node_info.path:
395 e.node_info.path = _remap_node_path(
396 e.node_info.path, final_orig_to_new_id
397 )
398 if e.node_info.output_for:
399 e.node_info.output_for = [
400 _remap_node_path(pth, final_orig_to_new_id)
401 for pth in e.node_info.output_for
402 ]
403
404 if e.content and e.content.parts:
405 for part in e.content.parts:
406 if part.function_response:

Callers 2

test_agent_replayFunction · 0.85
rebuild_testsFunction · 0.85

Calls 10

getattrFunction · 0.85
_remap_node_pathFunction · 0.85
_remap_ids_in_argsFunction · 0.85
get_function_callsMethod · 0.80
setdefaultMethod · 0.80
splitMethod · 0.80
popMethod · 0.80
itemsMethod · 0.45
appendMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected