Commit 5334b45
authored
feat(workflow): LLM-agent-as-node, task mode, and node-as-tool (Part 6) (#593)
* feat(workflow): add LLM-agent-as-node, task mode, and node-as-tool
Part 6/9 of the feature/workflows split. Lets agents participate in workflows.
- nodes/llm_agent_wrapper: runs a BaseAgent as a workflow node — streaming,
transfer_to_agent hand-offs, workflow instruction scope, and task mode (loops
until the agent calls finish_task, whose args become the node output). It
registers the agent node-builder, explicitly excluding BaseTool (which also
exposes runAsync) so tool-before-agent precedence holds regardless of
registration order.
- nodes/node_tool: exposes a node/workflow as a tool an agent can call.
- tools/finish_task_tool: the finish_task tool backing task mode.
- agents/llm_agent: task mode (mode/finishTaskTool) and registers the
request-input + request-confirmation LLM request processors.
- agents/processors/request_input_llm_request_processor: agent-side HITL
(request user input mid-run).
- agents/{invocation_context,instructions}, basic_llm_request_processor:
workflow instruction scope and {Class.field}/<field from node> placeholder
resolution.
Wired into the public barrel (LLMAgentWrapper, NodeTool) and
register_builtin_nodes; llm_agent 3-way merged onto current main.
Tests: node_api (16), llm_agent (7), multi_agent (3), instructions (37), plus
the workflow integration suite (15 files / 35 tests, recorded model responses).
Full core suite green (2476), integration workflows green, docs:check + tsc
clean.
* fix(workflow): reconcile Part 6 with the updated engine
Rebased Part 6 onto the current Part 5 and reconciled with the Parts 2-5
conventions:
- executeChildNode now takes a single params object (node_tool.ts).
- Move the LLM-agent-wrapper builder into the static node_builders.ts const
list; drop its registerNodeBuilder self-registration and the now-obsolete
register_builtin_nodes.ts (the const list replaces side-effect
registration).
* fix(workflow): address Part 6 review comments
node-as-tool (node_tool.ts):
- Bound node -> tool -> node recursion with a MAX_NODE_TOOL_DEPTH cap,
tracked via a new immutable InvocationContext.nodeToolDepth carried
through a depth+1 clone (so it survives agent-run ic clones).
- Require the invocation event queue and a function-call id (throw
otherwise) instead of falling back to a dead queue / a collapsing runId;
drop the structural cast on eventQueue.
- Pass an empty parent nodePath so the child path is a single segment, not
the node name doubled.
- Derive the tool parameter schema by narrowing isZodObject inline (drops
the `as never`).
instanceof -> brand guards:
- llm_agent.ts uses isBaseNode; the request-input processor uses isNodeTool
(new brand + guard on NodeTool). Both imports become type-only, removing
the agents -> workflow value cycle.
task mode (llm_agent_wrapper.ts): throw when a task-mode agent ends without
a successful finish_task, instead of reporting the node COMPLETE with no
output (its turn loop stays bounded by the invocation maxLlmCalls).
InvocationContext: add clone(overrides) and use it for both the
workflow-instruction-scope and node-tool-depth children (removes the
`as unknown as InvocationContextParams` cast); remove the unused
agentStates / endOfAgents fields; export WorkflowInstructionScope from
common.ts / index.ts (public field type) instead of suppressing the
TypeDoc warning.
* test(workflow): use the shared createIc fixture (drop hand-rolled casts)
Replace the duplicated hand-rolled createIc (with `as unknown as Session` /
`as unknown as BaseAgent`) in the Part 6 workflow tests with the shared
test_helpers.createIc (createSession + a real BaseAgent), removing the
repeated double-casts the review flagged.
* docs(workflow): de-link isNodeTool in NodeTool brand comment
* fix(workflow): re-publish Part 6 nodes after the Part 5 export change
Part 5 replaced the `export * from './workflow/index.js'` star in index.ts with
explicit named re-exports in common.ts, so Part 6's public additions must be
listed there too:
- Add LLMAgentWrapper / NodeTool and the LLMAgentWrapperConfig type to the
common.ts workflow block (they reach the web entry point this way, and the
block now mirrors the barrel exactly).
- Update node_api_test to subclass the renamed `WorkflowNode` base class.1 parent 1b90f3b commit 5334b45
38 files changed
Lines changed: 3614 additions & 21 deletions
File tree
- core
- src
- agents
- processors
- tools
- workflow
- nodes
- test
- agents
- workflow
- tests/integration/workflows
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
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 | + | |
12 | 38 | | |
13 | 39 | | |
14 | 40 | | |
| |||
39 | 65 | | |
40 | 66 | | |
41 | 67 | | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
48 | 76 | | |
49 | 77 | | |
50 | | - | |
51 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
52 | 89 | | |
53 | 90 | | |
54 | | - | |
| 91 | + | |
55 | 92 | | |
56 | 93 | | |
57 | 94 | | |
| |||
115 | 152 | | |
116 | 153 | | |
117 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
118 | 163 | | |
119 | 164 | | |
120 | 165 | | |
| |||
130 | 175 | | |
131 | 176 | | |
132 | 177 | | |
133 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
134 | 182 | | |
135 | 183 | | |
136 | 184 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
22 | 37 | | |
23 | 38 | | |
24 | 39 | | |
| |||
38 | 53 | | |
39 | 54 | | |
40 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
41 | 59 | | |
42 | 60 | | |
43 | 61 | | |
| |||
185 | 203 | | |
186 | 204 | | |
187 | 205 | | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
188 | 228 | | |
189 | 229 | | |
190 | 230 | | |
| |||
203 | 243 | | |
204 | 244 | | |
205 | 245 | | |
| 246 | + | |
| 247 | + | |
206 | 248 | | |
| 249 | + | |
207 | 250 | | |
208 | 251 | | |
209 | 252 | | |
| |||
236 | 279 | | |
237 | 280 | | |
238 | 281 | | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
239 | 295 | | |
240 | 296 | | |
241 | 297 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
10 | 14 | | |
11 | 15 | | |
12 | 16 | | |
| |||
68 | 72 | | |
69 | 73 | | |
70 | 74 | | |
| 75 | + | |
71 | 76 | | |
72 | 77 | | |
73 | 78 | | |
| |||
193 | 198 | | |
194 | 199 | | |
195 | 200 | | |
196 | | - | |
| 201 | + | |
197 | 202 | | |
198 | 203 | | |
199 | 204 | | |
| |||
259 | 264 | | |
260 | 265 | | |
261 | 266 | | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
262 | 277 | | |
263 | 278 | | |
264 | 279 | | |
| |||
323 | 338 | | |
324 | 339 | | |
325 | 340 | | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
326 | 346 | | |
327 | 347 | | |
328 | 348 | | |
| |||
362 | 382 | | |
363 | 383 | | |
364 | 384 | | |
| 385 | + | |
365 | 386 | | |
366 | 387 | | |
367 | 388 | | |
| 389 | + | |
368 | 390 | | |
369 | 391 | | |
370 | 392 | | |
| |||
389 | 411 | | |
390 | 412 | | |
391 | 413 | | |
| 414 | + | |
392 | 415 | | |
393 | 416 | | |
394 | 417 | | |
| |||
404 | 427 | | |
405 | 428 | | |
406 | 429 | | |
| 430 | + | |
407 | 431 | | |
408 | 432 | | |
409 | 433 | | |
| |||
500 | 524 | | |
501 | 525 | | |
502 | 526 | | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
503 | 538 | | |
504 | 539 | | |
505 | 540 | | |
| |||
788 | 823 | | |
789 | 824 | | |
790 | 825 | | |
791 | | - | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
792 | 831 | | |
793 | 832 | | |
794 | 833 | | |
| |||
978 | 1017 | | |
979 | 1018 | | |
980 | 1019 | | |
981 | | - | |
982 | | - | |
983 | | - | |
984 | | - | |
985 | | - | |
986 | | - | |
987 | | - | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
988 | 1054 | | |
989 | 1055 | | |
990 | 1056 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
44 | 47 | | |
45 | 48 | | |
| 49 | + | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
| |||
0 commit comments