Commit 495c85c
authored
docs(workflow): workflow samples (Part 8) (#595)
* docs(workflow): add workflow samples
Part 8/9 (final) of the feature/workflows split. Runnable examples covering the
workflow API surface:
- basics: sequence, loop, loop_self, route, multi_triggers, state, node_output,
use_as_output, message
- parallelism & dynamic: fan_out_fan_in, parallel_worker,
dynamic_fan_out_fan_in, dynamic_nodes, nested_workflow
- HITL & auth: request_input, request_input_advanced, request_input_rerun,
auth_api_key, auth_oauth
- agents & tools: agent_in_workflow, node_as_tool, retry
- samples/workflows/README.md and a root `sample` script to run them
Samples import only the public `@google/adk` surface and typecheck cleanly
against source.
* docs(workflow): address PR #595 sample review feedback
- dynamic_nodes now uses a real `WorkflowConfig.dynamicEntry` (driving children
via `ctx.runNode()`) instead of a static `edges` graph, so it actually
demonstrates what the README row and Feature-coverage section claim — and the
imperative loop is bounded by `MAX_ATTEMPTS` instead of `for (;;)`, so an
off-topic input can't spin forever on live model calls.
- parallel_worker sets `maxParallelWorkers: 2`, demonstrating the bounded
concurrency the README advertises.
- Normalize all nine sample headers that still used the raw
`node dev/dist/esm/cli_entrypoint.js run ...` form to `npm run sample -- ...`,
matching the README and the other samples.
- Unify how the four HITL samples parse a human reply: normalize with
`.trim().toLowerCase()` (so "Approve"/"approve " no longer fall through) and
share one affirmative vocabulary, instead of three different idioms.
- README: note that `loop`'s graph cycle is intentionally uncapped and can
iterate many times; add a dynamicEntry bullet to Feature coverage.
- Fix a prompt typo ("relates the the" -> "relates to the") in parallel_worker.
* test(workflow): record/replay sample integration tests + per-test subfolders
Add integration tests that run the real workflow samples end-to-end with only
the model mocked, and reorganize tests/integration/workflows so every test lives
in its own subfolder.
- Harness (tests/integration/workflows/_harness/): a RecordReplayModel
registered into LLMRegistry mocks the model boundary for every agent —
including ones captured inside a dynamicEntry/ctx.runNode closure — matching
recorded responses to requests by a stable, id-normalized fingerprint
(concurrency/order independent). sample_harness runs the real sample rootAgent
through an InMemoryRunner; record mode (RECORD_MODEL_RESPONSES=1) calls the
live model and writes the fixture, replay is offline. rng provides a seeded
PRNG for the model-free non-deterministic samples (retry, loop_self).
- 21 of 22 samples covered, one folder each: agent.ts (vendored from the sample)
+ <sample>_test.ts + model_responses.json where model-backed; offline samples
need no fixture. auth_oauth is skipped (needs a live OAuth provider).
- Add `npm run record:samples` to re-record the model-backed fixtures.
- Move the existing Part 6 workflow integration tests into per-test subfolders
(workflow_test_utils.ts -> _harness/; node_as_tool_test.ts -> node_as_tool_llm/
to avoid colliding with the sample's node_as_tool/ folder), fixing relative
imports only. No Part 6 test logic changed.
* chore: drop the sampels
* feat(workflow): let WorkflowAgent take Workflow options directly
Adds an overload so the common case drops a layer of nesting:
new WorkflowAgent({name: 'root_agent', edges: [...]})
instead of
new WorkflowAgent(new Workflow({name: 'root_agent', edges: [...]}))
When given a WorkflowConfig, the agent constructs the Workflow internally and
takes its name/description from that config. The existing
`new WorkflowAgent(workflow, {name, description})` form is unchanged and still
supported, so this is purely additive.
The two forms are told apart with the `isBaseNode` brand rather than
`instanceof` (per the workflow conventions): a branded node is an already-built
Workflow, anything else is config to build one from.
* refactor(workflow): use the flattened WorkflowAgent signature in tests
Adopt the new `new WorkflowAgent({name, edges})` form across the vendored agents
under tests/integration/workflows, dropping the `new Workflow(...)` wrapper and
one level of nesting:
export const rootAgent = new WorkflowAgent({
name: 'root_agent',
edges: [['START', processInput, classifyInput]],
});
- Migrates the 20 vendored agents that build a Workflow (node_as_tool is a plain
LlmAgent and is unchanged), dropping the now-unused `Workflow` import where
nothing else needs it. nested_workflow keeps it for its sub-workflow node.
- The samples this code was originally vendored from were removed in the
preceding "chore: drop the sampels" commit, so only the self-contained test
copies are updated here.
The change is purely syntactic: the workflows built are identical, so the
recorded model_responses.json fixtures still match and all 56 workflow
integration tests pass unchanged.1 parent d2ae57b commit 495c85c
84 files changed
Lines changed: 5059 additions & 31 deletions
File tree
- core
- src/workflow
- test/workflow
- tests/integration/workflows
- _harness
- advanced_workflows
- agent_in_workflow
- agent_pipeline
- auth_api_key
- auth_workflow
- core_workflows
- dynamic_fan_out_fan_in
- dynamic_nodes
- fan_out_fan_in
- llm_loop
- llm_tool_agent
- loop_and_trigger
- loop_self
- loop
- message
- multi_triggers
- nested_workflow
- node_as_tool_hitl
- node_as_tool_llm
- node_as_tool
- node_output
- parallel_llm
- parallel_worker
- plain_text_resume
- request_input_advanced
- request_input_rerun
- request_input
- retry
- route_llm
- route
- sequence_llm
- sequence
- state
- task_mode
- tool_and_resilience
- use_as_output
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
38 | 60 | | |
39 | 61 | | |
40 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| |||
Lines changed: 228 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
0 commit comments