Skip to content

Commit 096904a

Browse files
committed
feat(state-management): add aggregate status helper outputs
Add 4 new outputs for easier child status checking: - all_children_done: bool when all children completed - any_child_failed: bool when any child failed - progress_pct: percentage of children done (0-100) - children_summary: dict with counts by status
1 parent 0935a90 commit 096904a

1 file changed

Lines changed: 47 additions & 2 deletions

File tree

  • src/workflows_mcp/templates/agents/state-management

src/workflows_mcp/templates/agents/state-management/main.yaml

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,29 @@ blocks:
254254
task['updated_at'] = now
255255
state['updated_at'] = now
256256
257-
# Compute pending children
257+
# Compute children status aggregates
258258
children = task.get('children', [])
259+
child_statuses = [state['tasks'].get(c, {}).get('status', 'pending') for c in children]
260+
261+
children_done = sum(1 for s in child_statuses if s == 'done')
262+
children_failed = sum(1 for s in child_statuses if s == 'failed')
263+
children_in_progress = sum(1 for s in child_statuses if s == 'in-progress')
264+
children_pending_count = len(children) - children_done - children_failed - children_in_progress
265+
266+
# Aggregate status helpers
267+
all_children_done = len(children) > 0 and children_done == len(children)
268+
any_child_failed = children_failed > 0
269+
progress_pct = round((children_done / len(children) * 100), 1) if children else 100.0
270+
271+
children_summary = {
272+
'total': len(children),
273+
'done': children_done,
274+
'failed': children_failed,
275+
'in_progress': children_in_progress,
276+
'pending': children_pending_count
277+
}
278+
279+
# List of child IDs that aren't complete (for iteration)
259280
pending = [c for c in children if state['tasks'].get(c, {}).get('status') not in ('done', 'failed')]
260281
261282
# Build audit entry
@@ -287,7 +308,11 @@ blocks:
287308
'operation': operation,
288309
'audit_entry': audit_entry,
289310
'pending_children': pending,
290-
'task': task
311+
'task': task,
312+
'all_children_done': all_children_done,
313+
'any_child_failed': any_child_failed,
314+
'progress_pct': progress_pct,
315+
'children_summary': children_summary
291316
}))
292317
EOF
293318
env:
@@ -401,3 +426,23 @@ outputs:
401426
description: The target task's data field
402427
type: dict
403428
value: "{{(blocks.build_task.outputs.stdout | fromjson).task.data}}"
429+
430+
all_children_done:
431+
description: True if all children have status 'done' (and there is at least one child)
432+
type: bool
433+
value: "{{(blocks.build_task.outputs.stdout | fromjson).all_children_done}}"
434+
435+
any_child_failed:
436+
description: True if any child has status 'failed'
437+
type: bool
438+
value: "{{(blocks.build_task.outputs.stdout | fromjson).any_child_failed}}"
439+
440+
progress_pct:
441+
description: Percentage of children completed (0-100). Returns 100 if no children.
442+
type: num
443+
value: "{{(blocks.build_task.outputs.stdout | fromjson).progress_pct}}"
444+
445+
children_summary:
446+
description: Summary counts of children by status (total, done, failed, in_progress, pending)
447+
type: dict
448+
value: "{{(blocks.build_task.outputs.stdout | fromjson).children_summary}}"

0 commit comments

Comments
 (0)