Skip to content

Commit 615f7de

Browse files
committed
chore: apply pre-commit formatting and fix mypy untyped-decorator
1 parent b19139f commit 615f7de

3 files changed

Lines changed: 37 additions & 59 deletions

File tree

src/google/adk/agents/llm_agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,14 +978,14 @@ def __maybe_save_output_to_state(self, event: Event):
978978
def __model_validator_after(self) -> LlmAgent:
979979
return self
980980

981-
@field_validator('include_sources', mode='after')
981+
@field_validator('include_sources', mode='after') # type: ignore[misc]
982982
@classmethod
983983
def _validate_include_sources(
984984
cls, v: Optional[list[str]]
985985
) -> Optional[list[str]]:
986986
if v is not None and len(v) == 0:
987987
raise ValueError(
988-
"include_sources=[] keeps nothing. Use None to disable filtering."
988+
'include_sources=[] keeps nothing. Use None to disable filtering.'
989989
)
990990
return v
991991

tests/unittests/agents/test_llm_agent_include_contents.py

Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -250,19 +250,17 @@ async def test_include_contents_none_sequential_agents():
250250

251251
def test_include_sources_empty_list_raises():
252252
"""include_sources=[] must raise ValueError — use None to disable filtering."""
253-
with pytest.raises(ValueError, match='include_sources=\\[\\]'):
253+
with pytest.raises(ValueError, match="include_sources=\\[\\]"):
254254
LlmAgent(
255-
name='agent',
256-
model='gemini-2.5-flash',
255+
name="agent",
256+
model="gemini-2.5-flash",
257257
include_sources=[],
258258
)
259259

260260

261261
def test_include_sources_none_is_accepted():
262262
"""include_sources=None (default) must not raise."""
263-
agent = LlmAgent(
264-
name='agent', model='gemini-2.5-flash', include_sources=None
265-
)
263+
agent = LlmAgent(name="agent", model="gemini-2.5-flash", include_sources=None)
266264
assert agent.include_sources is None
267265

268266

@@ -275,43 +273,37 @@ def test_include_sources_none_is_accepted():
275273
async def test_include_sources_user_only_drops_upstream_agent_entries():
276274
"""Downstream agent with include_sources=['user'] receives only the human user message."""
277275
agent1_model = testing_utils.MockModel.create(
278-
responses=['Upstream agent reply']
276+
responses=["Upstream agent reply"]
279277
)
280278
agent1 = LlmAgent(
281-
name='upstream',
279+
name="upstream",
282280
model=agent1_model,
283-
instruction='You are upstream',
281+
instruction="You are upstream",
284282
)
285283

286284
agent2_model = testing_utils.MockModel.create(
287-
responses=['Downstream response']
285+
responses=["Downstream response"]
288286
)
289287
agent2 = LlmAgent(
290-
name='downstream',
288+
name="downstream",
291289
model=agent2_model,
292-
include_sources=['user'],
293-
instruction='You are downstream',
290+
include_sources=["user"],
291+
instruction="You are downstream",
294292
)
295293

296-
sequential = SequentialAgent(
297-
name='pipeline', sub_agents=[agent1, agent2]
298-
)
294+
sequential = SequentialAgent(name="pipeline", sub_agents=[agent1, agent2])
299295
runner = testing_utils.InMemoryRunner(sequential)
300-
runner.run('Original user request')
296+
runner.run("Original user request")
301297

302298
agent2_contents = testing_utils.simplify_contents(
303299
agent2_model.requests[0].contents
304300
)
305301

306302
# User message must be present
307-
assert any(
308-
'Original user request' in str(c) for _, c in agent2_contents
309-
)
303+
assert any("Original user request" in str(c) for _, c in agent2_contents)
310304
# Upstream agent's narrative entry must be absent
311-
assert not any(
312-
'Upstream agent reply' in str(c) for _, c in agent2_contents
313-
)
314-
assert not any('For context:' in str(c) for _, c in agent2_contents)
305+
assert not any("Upstream agent reply" in str(c) for _, c in agent2_contents)
306+
assert not any("For context:" in str(c) for _, c in agent2_contents)
315307

316308

317309
# ---------------------------------------------------------------------------
@@ -326,30 +318,28 @@ async def test_include_sources_user_self_drops_upstream_across_turns():
326318
narrative entries from the upstream agent across multiple invocations.
327319
"""
328320
agent1_model = testing_utils.MockModel.create(
329-
responses=['Turn1 upstream reply', 'Turn2 upstream reply']
321+
responses=["Turn1 upstream reply", "Turn2 upstream reply"]
330322
)
331323
agent1 = LlmAgent(
332-
name='upstream',
324+
name="upstream",
333325
model=agent1_model,
334-
instruction='You are upstream',
326+
instruction="You are upstream",
335327
)
336328

337329
agent2_model = testing_utils.MockModel.create(
338-
responses=['Turn1 downstream', 'Turn2 downstream']
330+
responses=["Turn1 downstream", "Turn2 downstream"]
339331
)
340332
agent2 = LlmAgent(
341-
name='downstream',
333+
name="downstream",
342334
model=agent2_model,
343-
include_sources=['user', 'self'],
344-
instruction='You are downstream',
335+
include_sources=["user", "self"],
336+
instruction="You are downstream",
345337
)
346338

347-
sequential = SequentialAgent(
348-
name='pipeline', sub_agents=[agent1, agent2]
349-
)
339+
sequential = SequentialAgent(name="pipeline", sub_agents=[agent1, agent2])
350340
runner = testing_utils.InMemoryRunner(sequential)
351-
runner.run('Turn 1 user message')
352-
runner.run('Turn 2 user message')
341+
runner.run("Turn 1 user message")
342+
runner.run("Turn 2 user message")
353343

354344
# Second invocation of downstream agent — should see user messages + own
355345
# prior turn, but not upstream's narrative entries.
@@ -358,14 +348,10 @@ async def test_include_sources_user_self_drops_upstream_across_turns():
358348
)
359349

360350
# User messages must be present
361-
assert any(
362-
'Turn 1 user message' in str(c) for _, c in agent2_second_contents
363-
)
364-
assert any(
365-
'Turn 2 user message' in str(c) for _, c in agent2_second_contents
366-
)
351+
assert any("Turn 1 user message" in str(c) for _, c in agent2_second_contents)
352+
assert any("Turn 2 user message" in str(c) for _, c in agent2_second_contents)
367353
# Upstream agent's narrative entries must be absent
368354
assert not any(
369-
'upstream reply' in str(c).lower() for _, c in agent2_second_contents
355+
"upstream reply" in str(c).lower() for _, c in agent2_second_contents
370356
)
371-
assert not any('For context:' in str(c) for _, c in agent2_second_contents)
357+
assert not any("For context:" in str(c) for _, c in agent2_second_contents)

tests/unittests/flows/llm_flows/test_contents_source_filter.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,15 @@ def _user_event(text: str, invocation_id: str = 'inv') -> Event:
2424
return Event(
2525
invocation_id=invocation_id,
2626
author='user',
27-
content=types.Content(
28-
role='user', parts=[types.Part(text=text)]
29-
),
27+
content=types.Content(role='user', parts=[types.Part(text=text)]),
3028
)
3129

3230

33-
def _model_event(
34-
text: str, author: str, invocation_id: str = 'inv'
35-
) -> Event:
31+
def _model_event(text: str, author: str, invocation_id: str = 'inv') -> Event:
3632
return Event(
3733
invocation_id=invocation_id,
3834
author=author,
39-
content=types.Content(
40-
role='model', parts=[types.Part(text=text)]
41-
),
35+
content=types.Content(role='model', parts=[types.Part(text=text)]),
4236
)
4337

4438

@@ -222,7 +216,7 @@ def test_source_filter_self_keeps_fc_call_and_response_together():
222216
# FC call (role=model) and FC response (role=user) both belong to 'self'
223217
roles = [c.role for c in result]
224218
assert 'model' in roles # function call kept
225-
assert 'user' in roles # function response kept (no orphan)
219+
assert 'user' in roles # function response kept (no orphan)
226220

227221

228222
def test_source_filter_without_self_drops_fc_call_and_response_together():
@@ -240,9 +234,7 @@ def test_source_filter_without_self_drops_fc_call_and_response_together():
240234
# Both FC call and FC response are dropped — no orphaned function_response part
241235
assert not any(c.role == 'model' for c in result)
242236
assert not any(
243-
p.function_response is not None
244-
for c in result
245-
for p in (c.parts or [])
237+
p.function_response is not None for c in result for p in c.parts or []
246238
)
247239

248240

0 commit comments

Comments
 (0)