From 31de282a2b2cdfd77bc96b1f023e8752ee6bb3a7 Mon Sep 17 00:00:00 2001 From: Utkarsh patwa Date: Mon, 16 Nov 2026 21:21:02 +0530 Subject: [PATCH] fix(workflow): propagate delegated child output to parent context in use_as_output When a node runs a child with use_as_output=True without explicitly returning its result (e.g. await ctx.run_node(child, use_as_output=True)), the child's output was emitted to the event stream but never set on the parent's ctx.output. Consequently, downstream workflow steps and graph successors received None. This patch: - Sets ctx.output = child_ctx.output on the parent context when use_as_output=True finishes. - Permits idempotent assignment of equivalent values in Context.output.setter so that explicit returns do not raise Output already set. - Adds regression test covering downstream node input propagation in test_workflow_dynamic_nodes.py. Closes #8183 Signed-off-by: Utkarsh patwa --- src/google/adk/agents/context.py | 7 +++++ .../adk/workflow/_dynamic_node_scheduler.py | 9 ++++++ .../workflow/test_workflow_dynamic_nodes.py | 29 +++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/src/google/adk/agents/context.py b/src/google/adk/agents/context.py index dac4a517d60..65a24c22e72 100644 --- a/src/google/adk/agents/context.py +++ b/src/google/adk/agents/context.py @@ -371,6 +371,13 @@ def output(self) -> Any: @output.setter def output(self, value: Any) -> None: if self._output_value is not None: + if self._output_value is value: + return + try: + if self._output_value == value: + return + except Exception: + pass raise ValueError( 'Output already set. A node can produce at most one output.' ) diff --git a/src/google/adk/workflow/_dynamic_node_scheduler.py b/src/google/adk/workflow/_dynamic_node_scheduler.py index ed24bd49b54..fe2a8119850 100644 --- a/src/google/adk/workflow/_dynamic_node_scheduler.py +++ b/src/google/adk/workflow/_dynamic_node_scheduler.py @@ -849,6 +849,15 @@ async def run_node_internal( resume_inputs=resume_inputs, ) + if ( + use_as_output + and not isinstance(ctx.node, Workflow) + and child_ctx + and child_ctx.output is not None + ): + if ctx.output is None: + ctx.output = child_ctx.output + transfer_to_agent = child_ctx.actions.transfer_to_agent if child_ctx else None if child_ctx and child_ctx.actions.skip_summarization: ctx.actions.skip_summarization = True diff --git a/tests/unittests/workflow/test_workflow_dynamic_nodes.py b/tests/unittests/workflow/test_workflow_dynamic_nodes.py index 805e7dc0ae0..5455f4262ab 100644 --- a/tests/unittests/workflow/test_workflow_dynamic_nodes.py +++ b/tests/unittests/workflow/test_workflow_dynamic_nodes.py @@ -767,6 +767,35 @@ async def parent(*, ctx, node_input): assert len(parent_outputs) == 0 +@pytest.mark.asyncio +async def test_dynamic_node_use_as_output_propagates_to_downstream_node(): + """Dynamic child with use_as_output=True sets parent ctx.output for downstream nodes. + + Regression test for #8183: Calling await ctx.run_node(..., use_as_output=True) + without an explicit return must populate the parent node's output so that + downstream workflow steps receive the delegated value. + """ + + @node(rerun_on_resume=True) + async def child(ctx, node_input): + return '10 folders' + + @node(rerun_on_resume=True) + async def dispatch(ctx, node_input): + await ctx.run_node(child, node_input, use_as_output=True) + + def receipt(node_input: str | None = None) -> str: + return 'Packed: ' + (node_input or 'MISSING_ORDER') + + wf = Workflow(name='wf_delegated', edges=[(START, dispatch, receipt)]) + ss = InMemorySessionService() + runner = create_runner(app_name='test', node=wf, session_service=ss) + session = await ss.create_session(app_name='test', user_id='u') + events = await _run(runner, ss, session, 'Please pack 10 folders.') + outputs = _outputs(events) + assert any('Packed: 10 folders' in str(o) for o in outputs) + + # ========================================================================= # None-output completion after interrupt # =========================================================================