Skip to content

Commit aceb7be

Browse files
DeanChensjcopybara-github
authored andcommitted
refactor: Clean up unused variables and arguments in adk/workflow
- Remove unused local variable `target_state` in `_workflow.py`. - Remove unused `ctx` argument from `NodeRunner._attempt_retry`. - Remove unused `node_path` and `curr_parent_ctx` arguments from `check_interception` utility function. Co-authored-by: Shangjie Chen <deanchen@google.com> PiperOrigin-RevId: 941198065
1 parent 451c8cc commit aceb7be

5 files changed

Lines changed: 2 additions & 45 deletions

File tree

src/google/adk/workflow/_dynamic_node_scheduler.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,9 @@ async def _check_existing_run(
266266

267267
# Delegate replay and same-turn interception check to ReplayInterceptor.
268268
result = check_interception(
269-
node_path=node_path,
270269
node=curr_node,
271270
recovered=run.recovered_state,
272271
current_run=run,
273-
curr_parent_ctx=curr_parent_ctx,
274272
)
275273

276274
if not result.should_run:

src/google/adk/workflow/_node_runner.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ async def run(
157157
)
158158
await self._enqueue_event(error_event, ctx)
159159

160-
if not await self._attempt_retry(e, ctx, attempt_count):
160+
if not await self._attempt_retry(e, attempt_count):
161161
ctx._error = e
162162
ctx._error_node_path = ctx.node_path
163163
logger.debug("node %s end.", ctx.node_path)
@@ -169,9 +169,7 @@ async def run(
169169
)
170170
attempt_count += 1
171171

172-
async def _attempt_retry(
173-
self, e: Exception, ctx: Context, attempt_count: int
174-
) -> bool:
172+
async def _attempt_retry(self, e: Exception, attempt_count: int) -> bool:
175173
"""Checks if node should retry and sleeps if so."""
176174
from ._node_state import NodeState
177175
from .utils._retry_utils import _get_retry_delay

src/google/adk/workflow/_workflow.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,8 @@ def _start_node_task(
555555
recovered = loop_state.recovered_executions[key]
556556

557557
result = check_interception(
558-
node_path=f'{ctx.node_path}/{node_name}@{run_id}',
559558
node=node,
560559
recovered=recovered,
561-
curr_parent_ctx=ctx,
562560
)
563561

564562
if not result.should_run:
@@ -688,7 +686,6 @@ def _buffer_downstream_triggers(
688686
use_sub_branch = len(next_nodes) > 1
689687
for target_name in next_nodes:
690688
target_node = self._get_static_node_by_name(target_name)
691-
target_state = loop_state.nodes.get(target_name)
692689

693690
if target_node._requires_all_predecessors:
694691
# Wait for all predecessors

src/google/adk/workflow/utils/_replay_interceptor.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,9 @@ class InterceptionResult:
5656

5757
def check_interception(
5858
*,
59-
node_path: str,
6059
node: BaseNode,
6160
recovered: _ChildScanState | None = None,
6261
current_run: DynamicNodeRun | None = None,
63-
curr_parent_ctx: Context,
6462
) -> InterceptionResult:
6563
"""Determine if a node execution should be intercepted based on history."""
6664
from .._workflow import Workflow # pylint: disable=g-import-not-at-top

tests/unittests/workflow/utils/test_replay_interceptor.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
replay interception.
1919
"""
2020

21-
from unittest.mock import MagicMock
22-
23-
from google.adk.agents.context import Context
2421
from google.adk.workflow._base_node import BaseNode
2522
from google.adk.workflow._dynamic_node_scheduler import DynamicNodeRun
2623
from google.adk.workflow._node_state import NodeState
@@ -30,13 +27,6 @@
3027
import pytest
3128

3229

33-
def _make_parent_ctx():
34-
ctx = MagicMock(spec=Context)
35-
ctx._invocation_context = MagicMock()
36-
ctx.resume_inputs = {}
37-
return ctx
38-
39-
4030
def test_same_turn_completed():
4131
"""Same-turn completed run intercepts and returns cached output."""
4232
# Given a same-turn completed run
@@ -45,14 +35,11 @@ def test_same_turn_completed():
4535
output='cached-out',
4636
transfer_to_agent='target-agent',
4737
)
48-
ctx = _make_parent_ctx()
4938

5039
# When checked
5140
result = check_interception(
52-
node_path='wf/node@1',
5341
node=BaseNode(name='node'),
5442
current_run=run,
55-
curr_parent_ctx=ctx,
5643
)
5744

5845
# Then it intercepts with cached results
@@ -67,14 +54,11 @@ def test_same_turn_waiting():
6754
run = DynamicNodeRun(
6855
state=NodeState(status=NodeStatus.WAITING, interrupts=['fc-1']),
6956
)
70-
ctx = _make_parent_ctx()
7157

7258
# When checked
7359
result = check_interception(
74-
node_path='wf/node@1',
7560
node=BaseNode(name='node'),
7661
current_run=run,
77-
curr_parent_ctx=ctx,
7862
)
7963

8064
# Then it intercepts and keeps waiting
@@ -91,14 +75,11 @@ def test_cross_turn_unresolved_interrupts_no_rerun():
9175
resolved_ids={'fc-1'},
9276
)
9377
node = BaseNode(name='node', rerun_on_resume=False)
94-
ctx = _make_parent_ctx()
9578

9679
# When checked
9780
result = check_interception(
98-
node_path='wf/node@1',
9981
node=node,
10082
recovered=recovered,
101-
curr_parent_ctx=ctx,
10283
)
10384

10485
# Then it stays waiting on unresolved interrupts
@@ -116,14 +97,11 @@ def test_cross_turn_unresolved_interrupts_rerun():
11697
resolved_responses={'fc-1': 'ans'},
11798
)
11899
node = BaseNode(name='node', rerun_on_resume=True)
119-
ctx = _make_parent_ctx()
120100

121101
# When checked
122102
result = check_interception(
123-
node_path='wf/node@1',
124103
node=node,
125104
recovered=recovered,
126-
curr_parent_ctx=ctx,
127105
)
128106

129107
# Then it reruns with partial resolved inputs
@@ -140,14 +118,11 @@ def test_cross_turn_completed():
140118
route='route-a',
141119
)
142120
node = BaseNode(name='node')
143-
ctx = _make_parent_ctx()
144121

145122
# When checked
146123
result = check_interception(
147-
node_path='wf/node@1',
148124
node=node,
149125
recovered=recovered,
150-
curr_parent_ctx=ctx,
151126
)
152127

153128
# Then it fast-forwards with cached output and route
@@ -166,17 +141,11 @@ def test_cross_turn_all_resolved_no_rerun():
166141
resolved_responses={'fc-1': 'ans'},
167142
)
168143
node = BaseNode(name='node', rerun_on_resume=False)
169-
ctx = _make_parent_ctx()
170-
ctx.resume_inputs = {
171-
'fc-1': {'result': 'ans'}
172-
} # Simulate FunctionResponse dict
173144

174145
# When checked
175146
result = check_interception(
176-
node_path='wf/node@1',
177147
node=node,
178148
recovered=recovered,
179-
curr_parent_ctx=ctx,
180149
)
181150

182151
# Then it auto-completes
@@ -194,14 +163,11 @@ def test_cross_turn_all_resolved_rerun():
194163
resolved_responses={'fc-1': 'ans'},
195164
)
196165
node = BaseNode(name='node', rerun_on_resume=True)
197-
ctx = _make_parent_ctx()
198166

199167
# When checked
200168
result = check_interception(
201-
node_path='wf/node@1',
202169
node=node,
203170
recovered=recovered,
204-
curr_parent_ctx=ctx,
205171
)
206172

207173
# Then it reruns

0 commit comments

Comments
 (0)