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

Function normalize_events

src/google/adk/cli/agent_test_runner.py:172–222  ·  view source on GitHub ↗
(events, is_json=False)

Source from the content-addressed store, hash-verified

170
171
172def normalize_events(events, is_json=False):
173 normalized = []
174 for e in events:
175 if is_json:
176 d = dict(e)
177 for k in EXCLUDED_EVENT_FIELDS:
178 d.pop(k, None)
179 d.pop(alias_generators.to_camel(k), None)
180 d = {k: v for k, v in d.items() if v is not None}
181 else:
182 d = e.model_dump(
183 mode="json",
184 by_alias=True,
185 exclude=EXCLUDED_EVENT_FIELDS,
186 exclude_none=True,
187 )
188
189 if "content" in d and isinstance(d["content"], dict):
190 content = d["content"]
191 if "parts" in content and isinstance(content["parts"], list):
192 for part in content["parts"]:
193 if isinstance(part, dict) and "thoughtSignature" in part:
194 del part["thoughtSignature"]
195
196 if "longRunningToolIds" in d:
197 if isinstance(d["longRunningToolIds"], list):
198 if not d["longRunningToolIds"]:
199 del d["longRunningToolIds"]
200 else:
201 d["longRunningToolIds"] = sorted(d["longRunningToolIds"])
202
203 if "actions" in d:
204 actions = d["actions"]
205 if isinstance(actions, dict):
206 # Remove empty dicts inside actions
207 for k in list(actions.keys()):
208 if actions[k] == {}:
209 del actions[k]
210 # If actions itself is now empty, remove it!
211 if not actions:
212 del d["actions"]
213
214 actions = d.get("actions", {})
215 state_delta = actions.get("stateDelta", {}) if actions else {}
216 if state_delta:
217 keys_to_remove = [k for k in state_delta if k.endswith("_join_state")]
218 for k in keys_to_remove:
219 del state_delta[k]
220
221 normalized.append(d)
222 return normalized
223
224
225def make_sort_key(d):

Callers 1

test_agent_replayFunction · 0.85

Calls 6

popMethod · 0.80
itemsMethod · 0.45
model_dumpMethod · 0.45
keysMethod · 0.45
getMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected