@memberjunction/task-graph 6.2.0-edge.5 → 6.2.0-edge.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +9 -7
  2. package/dist/TaskGraphDispatcher.d.ts +10 -0
  3. package/dist/TaskGraphDispatcher.d.ts.map +1 -1
  4. package/dist/TaskGraphDispatcher.js +229 -7
  5. package/dist/TaskGraphDispatcher.js.map +1 -1
  6. package/dist/TaskGraphService.d.ts +23 -6
  7. package/dist/TaskGraphService.d.ts.map +1 -1
  8. package/dist/TaskGraphService.js +169 -36
  9. package/dist/TaskGraphService.js.map +1 -1
  10. package/dist/TaskGraphSubmitterImpl.d.ts.map +1 -1
  11. package/dist/TaskGraphSubmitterImpl.js +1 -0
  12. package/dist/TaskGraphSubmitterImpl.js.map +1 -1
  13. package/dist/decision-node.d.ts +6 -0
  14. package/dist/decision-node.d.ts.map +1 -1
  15. package/dist/decision-node.js.map +1 -1
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +1 -0
  19. package/dist/index.js.map +1 -1
  20. package/dist/operations/TaskGraphDebugOperations.d.ts.map +1 -1
  21. package/dist/operations/TaskGraphDebugOperations.js +1 -0
  22. package/dist/operations/TaskGraphDebugOperations.js.map +1 -1
  23. package/dist/operations/TaskGraphOperations.d.ts +19 -7
  24. package/dist/operations/TaskGraphOperations.d.ts.map +1 -1
  25. package/dist/operations/TaskGraphOperations.js +67 -8
  26. package/dist/operations/TaskGraphOperations.js.map +1 -1
  27. package/dist/resolve-by-tool-name.d.ts +63 -0
  28. package/dist/resolve-by-tool-name.d.ts.map +1 -0
  29. package/dist/resolve-by-tool-name.js +116 -0
  30. package/dist/resolve-by-tool-name.js.map +1 -0
  31. package/dist/types.d.ts +10 -0
  32. package/dist/types.d.ts.map +1 -1
  33. package/dist/types.js.map +1 -1
  34. package/package.json +12 -11
package/README.md CHANGED
@@ -66,8 +66,8 @@ without standing up the agent framework.
66
66
 
67
67
  | File | Responsibility |
68
68
  |---|---|
69
- | `TaskGraphService.ts` | Validate a spec, resolve names to IDs in parallel, write parent + children + edges concurrently inside a single entity transaction. The only write path. |
70
- | `TaskGraphDispatcher.ts` | Single-pass poll, claim, pre-hydrated execute, evaluate edges, propagate, roll up, settle, credit cost. |
69
+ | `TaskGraphService.ts` | Validate a spec, resolve names to IDs in parallel (including sanitized native tool-name fallback and `Configuration.stepActionIds` for multi-step `steps[]` loop bodies), write parent + children + edges concurrently inside a single entity transaction. The only write path. |
70
+ | `TaskGraphDispatcher.ts` | Single-pass poll, claim, pre-hydrated execute (including multi-step `ForEach`/`While` `steps[]` chaining via `steps.<id>.*`), evaluate edges, propagate, roll up, settle, credit cost. |
71
71
  | `TaskClaimStore.ts` | The atomic claim protocol — guarded writes so two instances cannot run the same task. |
72
72
  | `TaskLoopExecutor.ts` | `ForEach` / `While` semantics: bounds, ordering, concurrency, delay, failure. |
73
73
  | `DispatcherConditionEvaluator.ts` | Edge conditions, over the superset context both dialects can read. |
@@ -211,11 +211,13 @@ section](../../guides/WORKFLOW_AND_TASK_GRAPH_GUIDE.md#cost-and-tokens-the-seam)
211
211
  cd packages/TaskGraph && pnpm test
212
212
  ```
213
213
 
214
- Unit tests cover the pure pieces — loop semantics, dispatchable kinds, configuration persistence,
215
- parent metadata. The dispatcher driving **real rows against SQL Server** is covered by the `IT74`
216
- bundle in `@memberjunction/integration-test-suite`, which uses a stub agent runner so it stays in
217
- the deterministic tier: no model calls, no tokens, real claim protocol, real condition evaluator,
218
- real rollup.
214
+ Unit tests cover the pure pieces — loop semantics (including multi-step `steps[]` loop bodies and
215
+ parallel array-append safety), dispatchable kinds, configuration persistence, and parent metadata.
216
+ The dispatcher driving **real rows against SQL Server** is covered by `IT74` (core graph dispatch),
217
+ `IT147` (deterministic multi-step `ForEach`/`While` `steps[]`, Flow graduation round-trip, and
218
+ agent-submitted `Tasks` settlement against `ActionEngineServer`), and `IT148` (live native
219
+ tool-calling LLM providers emitting and settling durable task graphs) in
220
+ `@memberjunction/integration-test-suite`.
219
221
 
220
222
  ---
221
223
 
@@ -745,6 +745,16 @@ export declare class TaskGraphDispatcher implements IShutdownable {
745
745
  * current item at all.
746
746
  */
747
747
  private runLoopTask;
748
+ /**
749
+ * Resolves every step's `ActionID` in a multi-step loop body (`steps[]`) once before iterating.
750
+ */
751
+ private resolveLoopStepActionIds;
752
+ /**
753
+ * Executes one pass of a multi-step action loop body (`op.steps[]`), chaining step outputs in
754
+ * memory via `steps.<id>.*`, evaluating per-step `condition` expressions, and folding per-step
755
+ * `outputMapping` declarations into the loop's running payload.
756
+ */
757
+ private executeMultiStepLoopPass;
748
758
  /**
749
759
  * Folds one pass's result into the loop's running payload.
750
760
  *
@@ -1 +1 @@
1
- {"version":3,"file":"TaskGraphDispatcher.d.ts","sourceRoot":"","sources":["../src/TaskGraphDispatcher.ts"],"names":[],"mappings":"AAsDA,OAAO,EAA4F,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC1I,OAAO,EAAE,aAAa,EAAgC,MAAM,wBAAwB,CAAC;AACrF,OAAO,EAAE,YAAY,EAA8F,MAAM,+BAA+B,CAAC;AAgIzJ;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,CAarI;AACD,OAAO,EAA0F,KAAK,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC1J,OAAO,EAEH,eAAe,EAEf,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,yBAAyB,EACzB,KAAK,kBAAkB,EAEvB,KAAK,yBAAyB,EAG9B,KAAK,iBAAiB,EAEzB,MAAM,SAAS,CAAC;AAkNjB;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG;I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OAKG;YACW,YAAY;IAyB1B;;;;;;;;;;;;;OAaG;YACW,eAAe;IA0D7B;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAUxB;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAmB5B;;;;;;;;;;;;;;OAcG;YACW,eAAe;IA2C7B;;;OAGG;YACW,oBAAoB;IAYlC,kGAAkG;YACpF,iBAAiB;IAiB/B;;;;;;;;;;;;;;OAcG;YACW,yBAAyB;IA2BvC;;;;;;;;;;OAUG;YACW,oBAAoB;IAqClC;;;;;;OAMG;IACH,OAAO,CAAC,uBAAuB;IAU/B;;;;;;OAMG;IACH,OAAO,CAAC,sBAAsB;IAc9B;;OAEG;YACW,cAAc;IAuB5B;;;;;;;OAOG;YACW,qBAAqB;IAQnC;;;;;;;;;;;;;;;;;;;;;;OAsBG;YACW,sBAAsB;IA+DpC;;;;;;;;;;;;;;;;;;;;;OAqBG;YACW,mBAAmB;IA2EjC;;;;;;;;;;;;;;;;;;OAkBG;YACW,qBAAqB;IAsCnC;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IASrB;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,wBAAwB;IA6BhC;;;;;;OAMG;IACH,OAAO,CAAC,kBAAkB;IAa1B;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,aAAa;IAerB;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IAwDzB;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IAmBhC,OAAO,CAAC,mBAAmB;IA6C3B,OAAO,CAAC,cAAc;IAqBtB,OAAO,CAAC,qBAAqB;CAYhC"}
@@ -18,12 +18,13 @@
18
18
  *
19
19
  * @module @memberjunction/task-graph
20
20
  */
21
- import { ComputeEligibleTasks, ComputeParentRollup, ComputeTasksToBlock, IsGraphStalled, ResolveExclusiveGroups, ComputeSkipCascade, ConfirmSkipSeeds, LayoutGraphNodes, ApplyOutputMapping, BuildMappedInput, ResolveMappedInput, LoadAgentRunTree, SumAgentRunTreeCost, WalkAgentRunTree, FinalizeAgentRunStep, InitAgentRunStep, DecisionReferencesIn, ResolveDecisionState, } from '@memberjunction/ai-core-plus';
21
+ import { ComputeEligibleTasks, ComputeParentRollup, ComputeTasksToBlock, IsGraphStalled, ResolveExclusiveGroups, ComputeSkipCascade, ConfirmSkipSeeds, LayoutGraphNodes, ApplyOutputMapping, BuildMappedInput, ResolveLoopBodyParams, LoadAgentRunTree, SumAgentRunTreeCost, WalkAgentRunTree, FinalizeAgentRunStep, InitAgentRunStep, DecisionReferencesIn, ResolveDecisionState, } from '@memberjunction/ai-core-plus';
22
22
  import { LogError, LogStatus, RunView } from '@memberjunction/core';
23
23
  import { ShutdownRegistry, UUIDsEqual } from '@memberjunction/global';
24
24
  import { TaskClaimStore, TERMINAL_PARENT_STATUSES, TERMINAL_PARENT_STATUS_SQL } from './TaskClaimStore.js';
25
25
  import { BuildConditionContext, DecideGate, EvaluateCondition, IsBrokenGuard, ParseConditionOutput, } from './condition-gate.js';
26
26
  import { BuildDecisionStepOutput, DecisionStepOutputAnswers, DecisionsPayloadConflict, FailedDecisionIDs, KeptDecisionAnswers, PassOverFailedDecisionPaths, QuestionsToAsk, ReadsFailedDecision, ReadDecisionStepConfiguration, ResolveGraphDecisions, StillHoldingDecisionOutput, } from './decision-node.js';
27
+ import { ResolveRecordsByNameOrToolName } from './resolve-by-tool-name.js';
27
28
  import { AIDecisionTaskRunner } from './AIDecisionTaskRunner.js';
28
29
  import { HumanTaskSQL, IsHumanTask } from './task-predicates.js';
29
30
  import { IsSettlementExpired, IsSubmittingRunReady, SelectUnsettledGraphIDs, SweepCutoff, UNSETTLED_SWEEP_WINDOW_HOURS, UNSETTLED_STARTUP_WINDOW_HOURS, } from './settlement-rescue.js';
@@ -1548,6 +1549,7 @@ export class TaskGraphDispatcher {
1548
1549
  let submittingAgentRunID = null;
1549
1550
  let invocation = {};
1550
1551
  let submittedByUserID = task.UserID;
1552
+ let parentAgentHierarchy = undefined;
1551
1553
  if (task.ParentID && prehydrated && (prehydrated.parentMetadata || prehydrated.parentTask)) {
1552
1554
  const parent = prehydrated.parentTask ?? null;
1553
1555
  const meta = (prehydrated.parentMetadata && typeof prehydrated.parentMetadata.reinvokeDepth === 'number')
@@ -1568,6 +1570,7 @@ export class TaskGraphDispatcher {
1568
1570
  const meta = ParseTaskGraphParentMetadata(parent.InputPayload);
1569
1571
  depth = meta.reinvokeDepth + 1;
1570
1572
  submittingAgentRunID = parent.AgentRunID;
1573
+ parentAgentHierarchy = meta.parentAgentHierarchy;
1571
1574
  invocation = { data: meta.invocation?.data, context: meta.invocation?.context };
1572
1575
  submittedByUserID = meta.submittedByUserID ?? parent.UserID ?? task.UserID;
1573
1576
  }
@@ -1582,6 +1585,7 @@ export class TaskGraphDispatcher {
1582
1585
  return {
1583
1586
  Depth: depth,
1584
1587
  SubmittingAgentRunID: submittingAgentRunID,
1588
+ ParentAgentHierarchy: parentAgentHierarchy,
1585
1589
  Invocation: invocation,
1586
1590
  ExecutionUser: executionUser,
1587
1591
  };
@@ -1738,6 +1742,7 @@ export class TaskGraphDispatcher {
1738
1742
  WorkflowName: parent.Name,
1739
1743
  ConversationDetailID: parent.ConversationDetailID ?? null,
1740
1744
  SubmittedByAgentRunID: meta.submittedByAgentRunID,
1745
+ SubmittedByUserID: meta.submittedByUserID ?? null,
1741
1746
  ReinvokeDepth: meta.reinvokeDepth,
1742
1747
  Tasks: [...graph.entityById.values()].map((t) => ({
1743
1748
  TaskID: t.ID,
@@ -3264,6 +3269,20 @@ export class TaskGraphDispatcher {
3264
3269
  // loop bodies second-class in every dimension — and reopened the unbounded-recursion hole
3265
3270
  // THROUGH loops, since each spawned run restarted the chain at zero.
3266
3271
  const graphContext = await this.graphContext(provider, task, prehydrated);
3272
+ // Pre-resolve ActionIDs once for multi-step action bodies (`op.steps[]`). Submit stamps
3273
+ // `config.stepActionIds`; fallback RunView covers callers constructing Task rows directly.
3274
+ const multiSteps = op.steps && op.steps.length > 0 ? op.steps : null;
3275
+ let stepActionIds = null;
3276
+ if (multiSteps) {
3277
+ if (!this.actionRunner) {
3278
+ return { Success: false, AgentRunID: null, ErrorMessage: 'No action runner is loaded on this host.' };
3279
+ }
3280
+ const resolvedIds = await this.resolveLoopStepActionIds(multiSteps, config?.stepActionIds, task.ActionID, provider, graphContext.ExecutionUser);
3281
+ if (!resolvedIds.Success || !resolvedIds.Map) {
3282
+ return { Success: false, AgentRunID: null, ErrorMessage: resolvedIds.ErrorMessage };
3283
+ }
3284
+ stepActionIds = resolvedIds.Map;
3285
+ }
3267
3286
  // THE LOOP'S PAYLOAD ACCUMULATES. Each iteration's output merges in, and the next iteration
3268
3287
  // — and the While condition — sees it. Without this the condition closure re-read the
3269
3288
  // payload as it was when the loop STARTED, so a `while payload.brandOK !== true` could never
@@ -3279,11 +3298,38 @@ export class TaskGraphDispatcher {
3279
3298
  // Bounds what the trace's payloads may cost. The pointers are never budgeted — those are the
3280
3299
  // durable record of the work and must survive whatever the payloads do.
3281
3300
  const budget = new IterationPayloadBudget();
3301
+ const isParallelForEach = task.StepType === 'ForEach' && op.executionMode === 'parallel';
3302
+ const deferredFoldsByIndex = new Map();
3282
3303
  const invokeBody = async ({ Index, Bindings }) => {
3283
- // Bindings go INTO the payload rather than beside it, so an authored mapping reaches the
3284
- // current item the same way it reaches anything else: `payload.<itemVariable>`.
3304
+ if (multiSteps && stepActionIds) {
3305
+ return this.executeMultiStepLoopPass({
3306
+ task,
3307
+ op,
3308
+ steps: multiSteps,
3309
+ stepActionIds,
3310
+ index: Index,
3311
+ bindings: Bindings,
3312
+ getLivePayload: () => livePayload,
3313
+ setLivePayload: (next) => { livePayload = next; },
3314
+ deferLivePayloadFold: isParallelForEach,
3315
+ deferredFoldsByIndex,
3316
+ dependencyOutputs,
3317
+ provider,
3318
+ executionUser: graphContext.ExecutionUser,
3319
+ invocation: graphContext.Invocation,
3320
+ iterationTrace,
3321
+ budget,
3322
+ });
3323
+ }
3324
+ // Bindings go INTO `iterationPayload` AND are passed explicitly to `ResolveLoopBodyParams`,
3325
+ // so durable single-arm loops honor BOTH legacy TaskGraph/Flow mappings (`payload.<itemVar>.*`,
3326
+ // `data.*`, `context.*`, `static:*`) AND the unified ForEachOperation/WhileOperation dialect
3327
+ // (`<itemVar>.*`, `{{<itemVar>.*}}`, inline `{{...}}`) while keeping unresolved paths/tokens literal.
3285
3328
  const iterationPayload = { ...livePayload, ...Bindings };
3286
- const resolved = ResolveMappedInput(bodyMapping, { payload: iterationPayload, ...graphContext.Invocation });
3329
+ const resolved = ResolveLoopBodyParams(bodyMapping, Bindings, {
3330
+ payload: iterationPayload,
3331
+ ...graphContext.Invocation,
3332
+ });
3287
3333
  /**
3288
3334
  * Folds an iteration's output into the running payload the next pass will see, and
3289
3335
  * records what the pass produced.
@@ -3375,20 +3421,33 @@ export class TaskGraphDispatcher {
3375
3421
  DependencyOutputs: dependencyOutputs,
3376
3422
  ContinuationDepth: graphContext.Depth,
3377
3423
  SubmittingAgentRunID: graphContext.SubmittingAgentRunID,
3424
+ ...(graphContext.ParentAgentHierarchy ? { ParentAgentHierarchy: graphContext.ParentAgentHierarchy } : {}),
3378
3425
  Provider: provider,
3379
3426
  ContextUser: graphContext.ExecutionUser,
3380
3427
  }), agentInput);
3381
3428
  };
3429
+ const evaluator = this.conditionEvaluator ?? new DispatcherConditionEvaluator();
3382
3430
  const outcome = task.StepType === 'ForEach'
3383
- ? await RunForEachLoop(op, { payload }, invokeBody)
3384
- : await RunWhileLoop(op, (iteration) => this.conditionEvaluator.Evaluate(op.condition,
3431
+ ? await RunForEachLoop(op, { payload, ...graphContext.Invocation }, invokeBody)
3432
+ : await RunWhileLoop(op, (iteration) => evaluator.Evaluate(op.condition,
3385
3433
  // BOTH forms, because a workflow should not have two condition dialects. An
3386
3434
  // EDGE condition is written `payload.brandOK !== true`; a loop condition used
3387
3435
  // to see the payload's keys spread at the top level and nothing named `payload`,
3388
3436
  // so the same expression that routes an edge failed here with
3389
3437
  // "payload is not defined". The spread stays for conditions already written
3390
3438
  // against it.
3391
- { ...livePayload, payload: livePayload, iteration }), invokeBody);
3439
+ { ...graphContext.Invocation, ...livePayload, payload: livePayload, iteration }), invokeBody);
3440
+ if (isParallelForEach) {
3441
+ // Replay parallel multi-step ForEach folds in deterministic ascending collection-index
3442
+ // order (0 .. N-1) rather than completion order, matching BaseAgent.executeForEachLoop.
3443
+ const orderedIndices = [...deferredFoldsByIndex.keys()].sort((a, b) => a - b);
3444
+ for (const idx of orderedIndices) {
3445
+ for (const fold of deferredFoldsByIndex.get(idx) ?? []) {
3446
+ livePayload = this.foldIterationOutput(task, livePayload, fold.Output, fold.Mapping);
3447
+ }
3448
+ }
3449
+ iterationTrace.sort((a, b) => a.index - b.index);
3450
+ }
3392
3451
  return {
3393
3452
  Success: outcome.Success,
3394
3453
  AgentRunID: null,
@@ -3404,6 +3463,165 @@ export class TaskGraphDispatcher {
3404
3463
  Output: this.applyStepOutputMapping(task, livePayload, outcome.Output, config?.outputMapping),
3405
3464
  };
3406
3465
  }
3466
+ /**
3467
+ * Resolves every step's `ActionID` in a multi-step loop body (`steps[]`) once before iterating.
3468
+ */
3469
+ async resolveLoopStepActionIds(steps, preResolved, primaryActionId, provider, contextUser) {
3470
+ const map = new Map(Object.entries(preResolved ?? {}));
3471
+ if (primaryActionId && steps.length > 0 && !map.has(steps[0].name)) {
3472
+ map.set(steps[0].name, primaryActionId);
3473
+ }
3474
+ const missing = [...new Set(steps.map((s) => s.name).filter((n) => !map.has(n)))];
3475
+ if (missing.length > 0) {
3476
+ const resolved = await ResolveRecordsByNameOrToolName({
3477
+ EntityName: 'MJ: Actions',
3478
+ Names: missing,
3479
+ Provider: provider,
3480
+ ContextUser: contextUser,
3481
+ });
3482
+ if (!resolved.Success || !resolved.Map) {
3483
+ return {
3484
+ Success: false,
3485
+ ErrorMessage: resolved.ErrorMessage ?? 'Failed to resolve loop step actions.',
3486
+ };
3487
+ }
3488
+ for (const [name, id] of resolved.Map.entries()) {
3489
+ map.set(name, id);
3490
+ }
3491
+ }
3492
+ const unresolved = [...new Set(steps.map((s) => s.name).filter((n) => !map.has(n)))];
3493
+ if (unresolved.length > 0) {
3494
+ return {
3495
+ Success: false,
3496
+ ErrorMessage: `Loop step "${steps[0].name}" references unknown action(s): ${unresolved.join(', ')}.`,
3497
+ };
3498
+ }
3499
+ return { Success: true, Map: map };
3500
+ }
3501
+ /**
3502
+ * Executes one pass of a multi-step action loop body (`op.steps[]`), chaining step outputs in
3503
+ * memory via `steps.<id>.*`, evaluating per-step `condition` expressions, and folding per-step
3504
+ * `outputMapping` declarations into the loop's running payload.
3505
+ */
3506
+ async executeMultiStepLoopPass(args) {
3507
+ const { task, op, steps, stepActionIds, index, bindings, getLivePayload, setLivePayload, deferLivePayloadFold, deferredFoldsByIndex, dependencyOutputs, provider, executionUser, invocation, iterationTrace, budget, } = args;
3508
+ const evaluator = this.conditionEvaluator ?? new DispatcherConditionEvaluator();
3509
+ const stepsOutputs = {};
3510
+ const stepInputsTrace = {};
3511
+ const executedFolds = [];
3512
+ // Working copy for intra-iteration step chaining; committed onto shared livePayload only via
3513
+ // explicit per-step `outputMapping` declarations (matching BaseAgent.executeLoopStepsIteration).
3514
+ let workingPayload = structuredClone(getLivePayload());
3515
+ let lastActionLogID;
3516
+ let lastStepOutput;
3517
+ for (let stepIdx = 0; stepIdx < steps.length; stepIdx++) {
3518
+ const step = steps[stepIdx];
3519
+ const stepKey = step.id?.trim() || `step_${stepIdx}`;
3520
+ const stepBindings = {
3521
+ ...bindings,
3522
+ index,
3523
+ steps: stepsOutputs,
3524
+ };
3525
+ if (!('item' in stepBindings) && task.StepType === 'ForEach') {
3526
+ const itemVar = op.itemVariable || 'item';
3527
+ stepBindings['item'] = bindings[itemVar];
3528
+ }
3529
+ if (step.condition?.trim()) {
3530
+ const conditionScope = {
3531
+ ...workingPayload,
3532
+ ...stepBindings,
3533
+ payload: { ...workingPayload, ...stepBindings },
3534
+ steps: stepsOutputs,
3535
+ index,
3536
+ iteration: index,
3537
+ ...(invocation.data !== undefined ? { data: invocation.data } : {}),
3538
+ ...(invocation.context !== undefined ? { context: invocation.context } : {}),
3539
+ };
3540
+ const verdict = evaluator.Evaluate(step.condition.trim(), conditionScope);
3541
+ if (!verdict.Success) {
3542
+ const errMsg = `Loop step "${stepKey}" condition failed: ${verdict.ErrorMessage}`;
3543
+ iterationTrace.push({
3544
+ index,
3545
+ payloadAtStart: budget.Take(stepInputsTrace),
3546
+ payloadAtEnd: budget.Take({ steps: stepsOutputs }),
3547
+ actionLogID: lastActionLogID,
3548
+ success: false,
3549
+ errorMessage: errMsg,
3550
+ });
3551
+ return { Success: false, ErrorMessage: errMsg, ActionLogID: lastActionLogID };
3552
+ }
3553
+ if (!verdict.Value) {
3554
+ continue;
3555
+ }
3556
+ }
3557
+ const stepPayload = { ...workingPayload, ...stepBindings };
3558
+ const resolvedParams = ResolveLoopBodyParams(step.params ?? {}, stepBindings, { payload: stepPayload, ...invocation });
3559
+ stepInputsTrace[stepKey] = resolvedParams;
3560
+ const actionId = stepActionIds.get(step.name);
3561
+ const actionOutcome = await this.actionRunner.RunActionForTask({
3562
+ TaskID: task.ID,
3563
+ ActionID: actionId,
3564
+ InputPayload: resolvedParams,
3565
+ DependencyOutputs: dependencyOutputs,
3566
+ Provider: provider,
3567
+ ContextUser: executionUser,
3568
+ });
3569
+ if (actionOutcome.ActionLogID) {
3570
+ lastActionLogID = actionOutcome.ActionLogID;
3571
+ }
3572
+ if (!actionOutcome.Success) {
3573
+ const errMsg = actionOutcome.ErrorMessage || `Loop step "${stepKey}" (${step.name}) failed`;
3574
+ iterationTrace.push({
3575
+ index,
3576
+ payloadAtStart: budget.Take(stepInputsTrace),
3577
+ payloadAtEnd: budget.Take({ steps: stepsOutputs }),
3578
+ actionLogID: lastActionLogID,
3579
+ success: false,
3580
+ errorMessage: errMsg,
3581
+ });
3582
+ return { Success: false, ErrorMessage: errMsg, ActionLogID: lastActionLogID };
3583
+ }
3584
+ const stepOutput = actionOutcome.Output && typeof actionOutcome.Output === 'object' && !Array.isArray(actionOutcome.Output)
3585
+ ? actionOutcome.Output
3586
+ : {};
3587
+ stepsOutputs[stepKey] = stepOutput;
3588
+ if (stepKey !== `step_${stepIdx}`) {
3589
+ stepsOutputs[`step_${stepIdx}`] ??= stepOutput;
3590
+ }
3591
+ lastStepOutput = stepOutput;
3592
+ const trimmedMapping = step.outputMapping?.trim();
3593
+ if (trimmedMapping) {
3594
+ workingPayload = this.foldIterationOutput(task, workingPayload, stepOutput, trimmedMapping);
3595
+ executedFolds.push({ Output: stepOutput, Mapping: trimmedMapping });
3596
+ }
3597
+ }
3598
+ if (deferLivePayloadFold) {
3599
+ deferredFoldsByIndex.set(index, executedFolds);
3600
+ }
3601
+ else if (executedFolds.length > 0) {
3602
+ let updatedLive = getLivePayload();
3603
+ for (const fold of executedFolds) {
3604
+ updatedLive = this.foldIterationOutput(task, updatedLive, fold.Output, fold.Mapping);
3605
+ }
3606
+ setLivePayload(updatedLive);
3607
+ }
3608
+ const combinedOutput = {
3609
+ ...(lastStepOutput ?? {}),
3610
+ steps: stepsOutputs,
3611
+ };
3612
+ iterationTrace.push({
3613
+ index,
3614
+ payloadAtStart: budget.Take(stepInputsTrace),
3615
+ payloadAtEnd: budget.Take(combinedOutput),
3616
+ actionLogID: lastActionLogID,
3617
+ success: true,
3618
+ });
3619
+ return {
3620
+ Success: true,
3621
+ Output: combinedOutput,
3622
+ ActionLogID: lastActionLogID,
3623
+ };
3624
+ }
3407
3625
  /**
3408
3626
  * Folds one pass's result into the loop's running payload.
3409
3627
  *
@@ -3494,6 +3712,7 @@ export class TaskGraphDispatcher {
3494
3712
  */
3495
3713
  async runAgentNode(task, provider, effectiveInput, dependencyOutputs, onProgress, resolvedContext) {
3496
3714
  const context = resolvedContext ?? await this.graphContext(provider, task);
3715
+ const presetName = task.ConfigurationObject?.agent?.presetName?.trim() || undefined;
3497
3716
  return this.agentRunner.RunAgentForTask({
3498
3717
  TaskID: task.ID,
3499
3718
  AgentID: task.AgentID,
@@ -3501,6 +3720,8 @@ export class TaskGraphDispatcher {
3501
3720
  DependencyOutputs: dependencyOutputs,
3502
3721
  ContinuationDepth: context.Depth,
3503
3722
  SubmittingAgentRunID: context.SubmittingAgentRunID,
3723
+ ...(context.ParentAgentHierarchy ? { ParentAgentHierarchy: context.ParentAgentHierarchy } : {}),
3724
+ ...(presetName ? { ConfigurationPresetName: presetName } : {}),
3504
3725
  Provider: provider,
3505
3726
  ContextUser: context.ExecutionUser,
3506
3727
  OnProgress: onProgress,
@@ -3671,6 +3892,7 @@ export class TaskGraphDispatcher {
3671
3892
  Fields: ['StepNumber'],
3672
3893
  OrderBy: 'StepNumber DESC',
3673
3894
  MaxRows: 1,
3895
+ SkipTotalRowCount: true,
3674
3896
  ResultType: 'simple',
3675
3897
  BypassCache: true,
3676
3898
  }, this.contextUser);