Commit Graph

2443 Commits

Author SHA1 Message Date
Wei (Jack) Sun dfdf00a6de fix(runners): exclude LlmAgent from node execution path in Runner
LlmAgent inherits from BaseNode but should not go through _run_node_async because it needs the full agent tracing and plugin lifecycle that is currently missing in that path.

Change-Id: Ia2f36f61f80cb5f089e67cccf569c9b2d2e1f306
2026-04-04 09:51:22 -07:00
Wei (Jack) Sun 03b7c95c9c fix(workflow): ensure non-rerunnable nodes complete and trigger downstream on resume
Extract output forwarding logic to a helper method and standardize response unwrapping. Update tests to explicitly set rerun_on_resume=True where re-running is expected.

Change-Id: I9af28ceee5d74a1086d13bbc13ccaae87936817f
2026-04-04 09:42:27 -07:00
Bo Yang 5a76251659 test: add automated workflow sample replay tests and associated session data files
Change-Id: I8cfb5d28d310da05d081688d725d39302d85c105
2026-04-04 08:53:48 -07:00
Wei (Jack) Sun 0b32bc2edc chore(samples): align new_workflow_samples with workflow_samples
Change-Id: I7fdab8cc670e1c062496adf2320c84cac5f7ac6b
2026-04-03 23:05:38 -07:00
Wei (Jack) Sun c826e6d68d fix(workflow): handle empty parent path in is_descendant and direct_child_name
Change-Id: Idc4f8c029c10d04ef33ca0921bb2dfae4b342ee7
2026-04-03 21:09:56 -07:00
Wei (Jack) Sun c55d794939 fix(workflow): isolate node state per run to fix infinite loop
Fixes the infinite loop observed in the 'request_input_rerun' sample where resume_inputs were inappropriately carried over during backedge execution.

- Implement _create_node_state_for_new_run to create a fresh NodeState for new execution runs, preserving only the run_counter.

- Clear resume_inputs in _handle_completion after successful completion to avoid carryover to subsequent runs.

- Remove XFAIL from test_dynamic_node_parallel_execution as it now passes due to better state isolation.

Change-Id: I866cda8a6b9252a3d5f93f277b428b88fcbcef36
2026-04-03 20:47:20 -07:00
Wei (Jack) Sun d50c025dca test(workflow): add failure and cancellation tests for node and workflow
Change-Id: I05eee558f960cc97e18fa9305578f929f1d1914a
2026-04-03 20:06:55 -07:00
Wei (Jack) Sun c51c05c2bd feat(workflow): add node-level retry support in NodeRunner
Change-Id: Iba8c6d12e2e9a232d7422890415684901a7e25ab
2026-04-03 20:01:10 -07:00
Wei (Jack) Sun aa7925b0cd fix(workflow): Prevent re-execution of completed dynamic nodes on resume
By checking if the node has output before checking if it has resolved interrupts, we avoid re-running a node that has already completed.

Change-Id: I77b150b722830682cef9325e6a44499e84ccde09
2026-04-03 19:29:09 -07:00
Xuan Yang cc51a76d55 refactor(agents): Separate 2.0 LlmAgent into llm_agent_workflow/ and llm_agent_node/
Move the 2.0 Mesh-based LlmAgent from agents/llm_agent.py to
agents/llm_agent_workflow/ and the 2.0 workflow nodes from
agents/llm/new/ to agents/llm_agent_node/. This clears the
agents/llm_agent.py slot for the upcoming 1.X LlmAgent restoration.

Change-Id: I491652a61e6668433d8e51e93cdeaac0212ab5b6
2026-04-03 15:26:49 -07:00
Wei (Jack) Sun 66090d6ee5 fix(workflow): Prevent run_id reset for WAITING nodes
This allows JoinNode to reuse the same run_id and state key across multiple triggers in the same logical run, fixing the fan-out/fan-in pattern.

Change-Id: Ic9fd476f6176fe87cc6b3e2cf21013c5683a310c
2026-04-03 15:22:03 -07:00
Bo Yang 6d930e880d refactor: consolidate root_node and root_agent into a single root_agent field in App and Runner classes
Change-Id: Id8c3bb09babd5a6acab647f5e562291630841a12
2026-04-03 10:57:54 -07:00
Shangjie Chen db25881ca0 feat: implement auto-incrementing run IDs for dynamic nodes to support parallel execution and resumption
Change-Id: I0f0a2760939be9ac2a83f24a8e2e14af0cd3ae58
2026-04-03 01:07:49 -07:00
Shangjie Chen 3533aa382d feat: Add model validator to derive run IDs from paths and update node name property to strip run ID suffixes
Change-Id: Ib2b8aae88ff3336406fa439ffc6c81eae441a5af
2026-04-02 23:42:15 -07:00
Bo Yang 8021312bc1 feat: add set_model_response action to support structured tool outputs and agent termination
Change-Id: Ib42a4b45d882ab12480480ae6825babbec773dcf
2026-04-02 18:27:45 -07:00
Wei (Jack) Sun 80e90c9bd6 feat(skills): Add adk-sample-creator skill for authoring samples
Enables automated creation and evaluation of both workflow and standalone agent samples.

Change-Id: I1cd81238e8d6992f58f7893727871982945e6aba
2026-04-02 18:26:12 -07:00
Shangjie Chen 0e06e5bf5f fix(workflow): use rsplit for safer node name extraction
Change-Id: If026dd772dc32ddfc9bdab109147bfae8424e5d1
2026-04-02 17:28:15 -07:00
Shangjie Chen e8c8b15e29 fix(workflow): Standardize node paths to name@run_id to prevent state collision and fix descendant bug
- Enforce uniform name@run_id pathing across workflow utilities.

Change-Id: If94390a5f11221e2c22cfd0716fa92f7b5b85bb4
2026-04-02 17:28:15 -07:00
George Weale 17e35a8e07 fix(tests): add _state_schema to InvocationContext mocks
The state_schema commit added _state_schema to InvocationContext,
but tests using Mock(spec=InvocationContext) didn't expose it.

Change-Id: Ifafeda8fb41447f5c802dfbc8e9b8cf8825ffc1a
2026-04-02 15:28:34 -07:00
Xuan Yang a633b9336c refactor: Copy flows/ to ADK 2.0
This is done by `cp -r`, no changes on the existing code.

Change-Id: Ia6918142e5994ba11b84407cadbae8c84f263e08
2026-04-02 12:57:04 -07:00
George Weale cf05bf831b feat(state): Enforce state_schema at runtime in Workflow
Add optional state_schema (Pydantic BaseModel) to Workflow that
validates ctx.state mutations, Event(state={...}) deltas, and
FunctionNode parameter bindings. Schema propagates to all nodes
via InvocationContext. Prefixed keys (app:, user:, temp:) bypass
validation.

Change-Id: I1c39713e56fbba8f5191801eab4c5aac224888b5
2026-04-02 11:22:54 -07:00
Shangjie Chen 231eb5bac6 refactor(workflow): use run_id in output_for for precise state rehydration
Transition `output_for` from a simple path list to a list of `(node_path, run_id)`
tuples. This enforces deterministic rehydration by ensuring events are only
attributed back to the specific execution run that requested them.
- Update `NodeInfo` schema to store `(path, run_id)` tuples in `output_for`.
- Refactor `DynamicNodeScheduler` to use both path and `run_id` for rehydration matching.
- Propagate current `run_id` upward when delegating output to ancestors.
- Add defensive error logging for events missing a `run_id` during rehydration scan.
- Add regression tests for run-id isolation and nested multi-turn delegation.

Change-Id: I853f5bb9a6b2343a38d3ac03fc7355032ba7c064
2026-04-01 23:47:30 -07:00
Wei (Jack) Sun abd5a77972 chore: Add __init__.py for agents/llm/new folder.
Change-Id: Ic2a614d2ac7499a1c46d467a63b456d61570956c
2026-04-01 21:17:53 -07:00
Bo Yang 62aeab4601 refactor(agents): streamline tool output handling and execution flow
- Extract ToolActions merging logic into a helper function
- Simplify tool output serialization and eliminate NodeInfo dependency
- Propagate ToolActions directly through the execution flow
- Update relevant unit tests

Change-Id: Ib480333c8ab2c45ac143149bd1054fa032abc39a
2026-04-01 18:46:15 -07:00
Bo Yang 4121f79af1 refactor(agents): simplify tool execution flow by returning ToolActions directly
- Encapsulate tool outputs into ToolNodeOutput
- Return ToolActions directly from RunToolsNode instead of bubbling up to ctx.actions
- Update termination logic in SingleLlmAgentNode

Change-Id: I3719592502623678fe051bc082b3891838ab3c13
2026-04-01 18:12:49 -07:00
Yifan Wang 4dc4017ad6 Remove obsolete test
Change-Id: I8346a3349a221fe9343a2c9e2d0ee4514cf2d454
2026-04-01 17:55:28 -07:00
Shangjie Chen 798749a937 refactor: Remove redundant _node_name parameter from dynamic node scheduling methods
Change-Id: I143cbca3ef1b3ded4191504d057cddd6f03708f3
2026-04-01 17:35:35 -07:00
Shangjie Chen bd015ea7bd feat(workflow): Refactor DynamicNodeState to use nested dictionary structure
- Groups state, output, and task into DynamicNodeRun\n- Separates iterations by run_id inside dict[str, dict[str, DynamicNodeRun]]\n- Adds fallback for single active run backward compatibility\n- Updates unit tests to verify nested state accesses

Change-Id: Ib2c18b56df18cbc2b544c31ba19c86097361d30e
2026-04-01 17:07:40 -07:00
Bo Yang 62122013e4 feat: add sub-agents sample demonstrating hierarchical agent delegation
Change-Id: Id7509801547d6ba3911ef5cd152f337ef0cd9317
2026-04-01 15:03:34 -07:00
Xuan Yang 7c9c3aa674 test(runners): fix test_runner_node.py failures
Why the test fails:
- The Runner is now designed to propagate errors from nodes (from _cleanup_root_task). Swallowing errors silently is not the intended behavior.
- The run_node implementation in src/google/adk/agents/context.py
 explicitly checks for rerun_on_resume flag

Change-Id: I8c554bb5764a818e9d2dfafab0ecd35712921fcf
2026-04-01 14:47:35 -07:00
Bo Yang add8ad3235 Start to build samples for features in llm agent.
Change-Id: I903a7aa485b2e4051487b68ff1484f6729f70720
2026-04-01 14:40:08 -07:00
Bo Yang 9c345de849 refactor: move new llm implementation to the folder 'new' and rename them to the final names.
Change-Id: I38474a39a502b890de3e6e28cce5484e1f0e5e01
2026-04-01 13:38:35 -07:00
Xuan Yang 677d18a7a9 fix(workflow): Fix node wrapper equality for duplicate checks
Ignore runtime caches in _LlmAgentWrapper equality comparison. This allows Comparing wrappers for registry duplicate checks without failing on separate instances of runtime variables.

This is to fix the broken tests/unittests/workflow/test_dynamic_node_registry.py::test_llm_agent_wrapper_deep_check_success test, without this change:

```
node1 = _LlmAgentWrapper(agent=agent)
node2 = _LlmAgentWrapper(agent=agent)
assert node1 == node2 ---> fails
```

Change-Id: I25d9ca4152a8ecba73b396f307d5398eb9b17f39
2026-04-01 13:37:20 -07:00
Bo Yang 8a7d30dc99 refactor: move auth, confirmation, and long-running tool handling logic from parallel to individual tool call nodes
Change-Id: I3cf504648ca1bf3907b152440043d2a0c47c1781
2026-04-01 13:17:57 -07:00
Bo Yang 1701611594 refactor: remove ParallelToolCallResult and use node_info.message_as_output for event handling and action propagation.
Change-Id: I2e1e4f78abbe610895bae9176392e8bb3d280356
2026-04-01 12:04:41 -07:00
Shangjie Chen 88638ba402 feat(workflow): Add custom run_id support to ctx.run_node()
Allow callers to pass run_id to ctx.run_node() so child node events
use a caller-specified run ID instead of the default '1'. Also rename
the deprecated positional `run_id` to `_node_name` in the
ScheduleDynamicNode protocol to reflect what it actually carries.

Change-Id: I6ef1709fa9f1c0f33794f804c5da7bfa561f6ee3
2026-04-01 11:44:51 -07:00
Bo Yang f602a7ac84 feat: add run_id support to node execution and update parallel tool call naming and agent structure
Change-Id: I45ba2a17a5970bae8320cc5e8160ce1d3cabc3ed
2026-04-01 11:33:30 -07:00
Bo Yang 9ed61bc44b refactor: update LLM nodes to use message content as output via node_info flag
Change-Id: I83981d77993459f994fb61fa642d19eb47aeb221
2026-04-01 11:33:10 -07:00
Bo Yang b8fa48abb9 refactor(events): Remove unnecessary null checks for actions and node_info
Remove defensive null checks for EventActions and NodeInfo properties
    as these fields are now populated by default factories and are guaranteed
    to be non-null when accessed on Event objects.

Change-Id: I6ae7a38a258589be8945dcd82f005f2f9ba4d9ea
2026-04-01 11:08:09 -07:00
Wei (Jack) Sun 70ddcfee25 feat(workflow): Migrate dynamic node tests and fix resume/error gaps
DynamicNodeScheduler: auto-complete rerun_on_resume=False nodes with
resume_inputs dict instead of re-executing.
NodeRunner: pass node.rerun_on_resume to child Context for validation.
Runner: re-raise root node exceptions so callers see failures.

Change-Id: I21aa28d7f2fa3a1738d519e39477e341ae2accda
2026-03-31 23:20:25 -07:00
Wei (Jack) Sun b07654401b test(workflow): Migrate output deduplication tests to new Workflow
4 pass, 1 xfail (terminal node route not propagated — _finalize
sets ctx.output but not ctx.route from terminal node).

Change-Id: I65b24e6401124685625be62b38ed73e03f0c6fe8
2026-03-31 23:19:28 -07:00
Bo Yang ca476aa130 test(agents): Update before_cb test to return LlmResponse
Update the before_model_callback tests in test_single_llm_agent to
return an `LlmResponse` wrapping `types.Content` instead of a raw
`types.Content`. This matches the callback signature.

Change-Id: Ie7ca7c8e663dd764aa1a22238efaf27a2c8c7e17
2026-03-31 22:57:57 -07:00
Wei (Jack) Sun 6ec158fefc test(workflow): Migrate agent and tool node tests to new Workflow
Agent: 1 pass, 1 xfail (BaseAgent needs ctx.event_author once it
extends BaseNode).
Tool: 1 pass (FunctionTool piping verified with input from upstream).

Change-Id: I1df16c2a69fd685873492154de5caf25aeaeaa1c
2026-03-31 20:57:36 -07:00
Shangjie Chen 85303e1b6e test(workflow): Add nested ctx.run_node() test and rename tests
Add integration test for nested ctx.run_node() (outer → middle →
inner) verifying interrupt propagation and resume across layers.
Rename child_tracker references to default_scheduler in test names.

Change-Id: Ia360e0f8d8c1b7eade432529c755f3cf32f3e968
2026-03-31 20:24:22 -07:00
Bo Yang cf0f034559 refactor: update message_as_output type hint to allow None values
Change-Id: Id1ae07abc1356194b220c17465a42ff3ba919ee9
2026-03-31 20:11:41 -07:00
Bo Yang dd3fc8b0f4 feat: update nested workflow agent to pass year state to downstream agents and format aggregation output
Change-Id: I6924a0db6d9e71439b0da1e65d1759bfa476a402
2026-03-31 20:11:03 -07:00
Bo Yang dd88f9320d docs: update description of inline image from square to circle in agent workflow sample
Change-Id: I002617036f843460d7c1891da60dd16bd0db11a9
2026-03-31 20:10:54 -07:00
Shangjie Chen a68e70d5da feat(workflow): Add DefaultNodeScheduler for standalone node resume via ctx.run_node()
Change-Id: Id02bdb537a80c002add7156c799991519141914a
2026-03-31 19:40:39 -07:00
Wei (Jack) Sun 1310e30f17 chore(samples): sync new_workflow_samples to match old samples 1:1
Add missing shared_sub_agent and use_as_output samples.
Restore stream_sentence stage and numbering in message sample.

Change-Id: Ib295da3ca4712f4062987c03a35823ad4777b186
2026-03-31 17:49:28 -07:00
Shangjie Chen 35538c9a21 feat(events): Add message_as_output to NodeInfo
LlmCallNode sets message_as_output=True on pure text responses.
_maybe_save_output_to_state sets it for single_turn agents in the
old path. NodeRunner auto-detects this flag and sets
_output_delegated, removing manual delegation in
SingleAgentReactNode, LlmAgentWrapper, and suppressing duplicate
output events in the old path.

Change-Id: I1d6728e128e38eb47ff4a6137ab803e355a51e83
2026-03-31 17:48:43 -07:00