Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/google/adk/agents/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
)
Expand Down
9 changes: 9 additions & 0 deletions src/google/adk/workflow/_dynamic_node_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions tests/unittests/workflow/test_workflow_dynamic_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# =========================================================================
Expand Down
Loading