periplon 0.2.0

Rust SDK for building multi-agent AI workflows and automation
Documentation
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
# Task Groups API Reference

Complete reference for task group configuration schema.

## Table of Contents

1. [TaskGroup Schema]#taskgroup-schema
2. [ExecutionMode]#executionmode
3. [ErrorStrategy]#errorstrategy
4. [VariableDefinition]#variabledefinition
5. [VariableOutput]#variableoutput
6. [Complete Example]#complete-example

## TaskGroup Schema

### Fields

#### `description` (required)

**Type:** String

**Description:** Human-readable description of what this group does.

**Example:**
```yaml
description: "Build and test the application"
```

**Constraints:**
- Must not be empty
- Should be concise and descriptive
- Used in logs and UI

---

#### `execution_mode` (required)

**Type:** [ExecutionMode](#executionmode)

**Description:** Determines how tasks within the group execute.

**Values:**
- `sequential`: Tasks run one after another
- `parallel`: Tasks run concurrently
- `auto`: Automatically determine based on dependencies

**Example:**
```yaml
execution_mode: "parallel"
```

**Default:** None (must be specified)

---

#### `tasks` (optional)

**Type:** Array of Strings

**Description:** List of task IDs that belong to this group.

**Example:**
```yaml
tasks:
  - compile_code
  - run_tests
  - generate_docs
```

**Constraints:**
- Each task ID must reference an existing task
- Tasks can only belong to one group
- Required if `groups` is not specified

**Mutually Exclusive:** Either `tasks` or `groups` (or both) must be specified

---

#### `groups` (optional)

**Type:** Array of Strings

**Description:** List of child group IDs for hierarchical organization.

**Example:**
```yaml
groups:
  - build_phase
  - test_phase
  - deploy_phase
```

**Constraints:**
- Each group ID must reference an existing group
- Child groups must have `parent` field pointing to this group
- Creates parent-child hierarchy

**Mutually Exclusive:** Either `tasks` or `groups` (or both) must be specified

---

#### `depends_on` (optional)

**Type:** Array of Strings

**Description:** Group IDs that must complete before this group starts.

**Example:**
```yaml
depends_on:
  - build_group
  - test_group
```

**Constraints:**
- All dependency IDs must reference existing groups
- Cannot create circular dependencies
- All dependencies must complete successfully (unless condition allows failure)

**Default:** `[]` (no dependencies)

---

#### `parent` (optional)

**Type:** String

**Description:** ID of parent group for hierarchical nesting.

**Example:**
```yaml
parent: "ci_cd_pipeline"
```

**Constraints:**
- Must reference an existing group
- Parent must list this group in its `groups` field
- Creates parent-child relationship

**Default:** `null` (root-level group)

---

#### `condition` (optional)

**Type:** String (expression)

**Description:** Boolean expression that must evaluate to true for group to execute.

**Example:**
```yaml
condition: "${group.quality_check.score} >= 0.8"
```

**Expression Syntax:**
- Variable references: `${scope.variable}`
- Comparison operators: `==`, `!=`, `>`, `>=`, `<`, `<=`
- Logical operators: `&&`, `||`, `!`
- Parentheses for grouping: `(expr)`

**Supported Scopes:**
- `workflow`: Workflow-level inputs
- `group.group_id`: Group outputs
- `task.task_id`: Task outputs

**Examples:**
```yaml
# Simple comparison
condition: "${workflow.environment} == 'prod'"

# Numeric threshold
condition: "${group.tests.coverage} >= 0.8"

# Logical operators
condition: "${workflow.deploy} == true && ${group.tests.passed} == true"

# Complex expression
condition: "(${group.quality.score} >= 0.8 && ${workflow.environment} == 'prod') || ${workflow.force_deploy} == true"
```

**Default:** `null` (always execute)

---

#### `on_error` (optional)

**Type:** [ErrorStrategy](#errorstrategy)

**Description:** How to handle task failures within the group.

**Values:**
- `stop`: Stop group execution on first failure
- `continue`: Continue executing remaining tasks
- `rollback`: Execute rollback logic on failure

**Example:**
```yaml
on_error: "continue"
```

**Default:** `"stop"`

---

#### `timeout` (optional)

**Type:** Integer (seconds)

**Description:** Maximum execution time for the entire group.

**Example:**
```yaml
timeout: 600  # 10 minutes
```

**Constraints:**
- Must be positive integer
- Applies to entire group (including all child groups/tasks)
- On timeout, group fails and running tasks are cancelled

**Default:** No timeout (infinite)

**Inheritance:** Child groups inherit parent timeout if not specified

---

#### `max_concurrency` (optional)

**Type:** Integer

**Description:** Maximum number of tasks that can run in parallel.

**Example:**
```yaml
max_concurrency: 5
```

**Constraints:**
- Must be positive integer
- Only applies when `execution_mode: "parallel"`
- Limits concurrent task execution

**Default:** Unlimited (all tasks run concurrently)

**Use Cases:**
- Prevent resource exhaustion
- Rate limit external API calls
- Control memory/CPU usage

---

#### `inputs` (optional)

**Type:** Object (Map of String to [VariableDefinition](#variabledefinition))

**Description:** Variables consumed by this group.

**Example:**
```yaml
inputs:
  config_file:
    type: string
    required: true
    description: "Path to configuration file"
  threshold:
    type: number
    required: false
    default: 0.8
```

**See:** [VariableDefinition](#variabledefinition) for field details

**Default:** `{}` (no inputs)

---

#### `outputs` (optional)

**Type:** Object (Map of String to [VariableOutput](#variableoutput))

**Description:** Variables produced by this group.

**Example:**
```yaml
outputs:
  build_artifact:
    source:
      type: file
      path: "./dist/app.zip"
  test_results:
    source:
      type: state
      key: "test.results"
```

**See:** [VariableOutput](#variableoutput) for field details

**Default:** `{}` (no outputs)

---

## ExecutionMode

Enum specifying how tasks execute within a group.

### Values

#### `sequential`

Tasks execute one after another in order.

**Characteristics:**
- Predictable order
- Lower resource usage
- Tasks wait for previous to complete
- Task dependencies honored

**Use Cases:**
- Build pipelines (order matters)
- Database migrations
- Deployment steps

**Example:**
```yaml
execution_mode: "sequential"
tasks:
  - step1
  - step2
  - step3
```

**Execution:**
```
step1 → complete → step2 → complete → step3 → complete
```

---

#### `parallel`

Tasks execute concurrently.

**Characteristics:**
- Maximum throughput
- Higher resource usage
- Tasks run independently
- Can limit with `max_concurrency`

**Use Cases:**
- Independent tests
- Parallel data processing
- Multi-agent analysis

**Example:**
```yaml
execution_mode: "parallel"
max_concurrency: 3
tasks:
  - test1
  - test2
  - test3
  - test4
```

**Execution:**
```
test1 ─┐
test2 ─┼─→ (up to 3 concurrent)
test3 ─┤
test4 ─┘ (waits for slot)
```

---

#### `auto`

Automatically determine execution mode based on task dependencies.

**Behavior:**
- Analyzes task dependencies
- Parallelizes independent tasks
- Respects dependency order
- Optimizes execution plan

**Use Cases:**
- Complex workflows with mixed dependencies
- When optimal strategy unclear
- Dynamic task sets

**Example:**
```yaml
execution_mode: "auto"
tasks:
  - task_a          # No deps: runs first
  - task_b          # depends_on: [task_a]
  - task_c          # depends_on: [task_a]
  - task_d          # depends_on: [task_b, task_c]
```

**Execution:**
```
task_a → (task_b, task_c in parallel) → task_d
```

---

## ErrorStrategy

Enum specifying how to handle task failures.

### Values

#### `stop`

Stop group execution on first task failure.

**Behavior:**
- First failure stops the group immediately
- Remaining tasks are cancelled
- Group marked as failed
- Error propagates to parent

**Use Cases:**
- Critical pipelines
- When failures are unacceptable
- Fast failure detection

**Example:**
```yaml
on_error: "stop"
```

**Execution:**
```
task1 ✓ → task2 ✗ → [STOP] → task3 cancelled
Group status: Failed
```

---

#### `continue`

Continue executing remaining tasks despite failures.

**Behavior:**
- Failures don't stop execution
- All tasks attempt to run
- Collect all failures
- Group marked failed if any task failed

**Use Cases:**
- Test suites (want all results)
- Independent validations
- Comprehensive error reports

**Example:**
```yaml
on_error: "continue"
```

**Execution:**
```
task1 ✓ → task2 ✗ → task3 ✓ → task4 ✗
Group status: Failed (2/4 tasks failed)
```

---

#### `rollback`

Execute rollback logic on failure.

**Behavior:**
- On failure, execute rollback tasks
- Attempt to restore previous state
- Group marked failed with rollback attempted

**Use Cases:**
- Deployments (restore previous version)
- Database migrations
- Configuration updates

**Example:**
```yaml
on_error: "rollback"
```

**Note:** Requires rollback task definition (implementation-specific)

---

## VariableDefinition

Defines an input variable for a group.

### Fields

#### `type` (required)

**Type:** String

**Description:** Variable data type.

**Values:**
- `string`: Text value
- `number`: Numeric value (integer or float)
- `boolean`: True/false value
- `object`: JSON object
- `array`: JSON array

**Example:**
```yaml
type: string
```

---

#### `required` (optional)

**Type:** Boolean

**Description:** Whether variable must be provided.

**Example:**
```yaml
required: true
```

**Default:** `false`

**Behavior:**
- If `true` and variable not provided: validation error
- If `false` and variable not provided: use default (if specified)

---

#### `default` (optional)

**Type:** Any (must match `type`)

**Description:** Default value if variable not provided.

**Example:**
```yaml
default: "production"
```

**Constraints:**
- Type must match specified `type`
- Only used if `required: false`

---

#### `description` (optional)

**Type:** String

**Description:** Human-readable description of variable purpose.

**Example:**
```yaml
description: "Environment to deploy to (dev, staging, prod)"
```

---

### Complete Example

```yaml
inputs:
  environment:
    type: string
    required: true
    description: "Target deployment environment"

  replicas:
    type: number
    required: false
    default: 3
    description: "Number of replicas to deploy"

  enable_monitoring:
    type: boolean
    required: false
    default: true
    description: "Enable monitoring and alerting"

  config:
    type: object
    required: false
    description: "Additional configuration options"
```

---

## VariableOutput

Defines an output variable produced by a group.

### Fields

#### `source` (required)

**Type:** Object (VariableOutputSource)

**Description:** Source of the output variable value.

**Structure:**
```yaml
source:
  type: <source_type>
  # Additional fields based on type
```

---

### Source Types

#### File Source

Read variable value from file.

**Schema:**
```yaml
source:
  type: file
  path: <file_path>
```

**Fields:**
- `type`: Must be `"file"`
- `path`: Path to file (supports variable interpolation)

**Example:**
```yaml
outputs:
  build_artifact:
    source:
      type: file
      path: "./dist/app-${workflow.version}.zip"
```

**Behavior:**
- File is read when group completes
- File contents become variable value
- Supports text and JSON files
- Variable interpolation in path

---

#### State Source

Read variable value from workflow state.

**Schema:**
```yaml
source:
  type: state
  key: <state_key>
```

**Fields:**
- `type`: Must be `"state"`
- `key`: Key in workflow state (dot-notation for nested)

**Example:**
```yaml
outputs:
  test_coverage:
    source:
      type: state
      key: "test.coverage.percent"
```

**Behavior:**
- Reads from in-memory workflow state
- Supports nested keys with dot notation
- Must be set during task execution

---

#### Task Source

Read variable value from specific task output.

**Schema:**
```yaml
source:
  type: task
  task_id: <task_id>
  variable: <variable_name>
```

**Fields:**
- `type`: Must be `"task"`
- `task_id`: ID of task to read from
- `variable`: Name of task's output variable

**Example:**
```yaml
outputs:
  deployment_id:
    source:
      type: task
      task_id: "deploy_task"
      variable: "deployment_id"
```

**Behavior:**
- Reads from specific task's outputs
- Task must have completed
- Task must define the output variable

---

### Complete Example

```yaml
outputs:
  # File source
  build_artifact:
    source:
      type: file
      path: "./dist/app.zip"

  # State source
  build_number:
    source:
      type: state
      key: "build.number"

  # Nested state
  test_coverage:
    source:
      type: state
      key: "test.coverage.percent"

  # Task source
  deployment_url:
    source:
      type: task
      task_id: "deploy_prod"
      variable: "url"
```

---

## Complete Example

Full task group configuration demonstrating all features:

```yaml
task_groups:
  # Root group
  ci_cd_pipeline:
    description: "Complete CI/CD pipeline"
    execution_mode: "sequential"
    groups:
      - build_and_test
      - deploy

    timeout: 1800  # 30 minutes
    on_error: "stop"

    inputs:
      repo_url:
        type: string
        required: true
        description: "Repository URL"

      environment:
        type: string
        required: true
        description: "Target environment"

    outputs:
      deployment_url:
        source:
          type: state
          key: "deployment.url"

  # Child group 1
  build_and_test:
    description: "Build and test application"
    parent: "ci_cd_pipeline"
    execution_mode: "sequential"
    groups:
      - build
      - test

    timeout: 900  # 15 minutes

  # Grandchild group 1.1
  build:
    description: "Build application"
    parent: "build_and_test"
    execution_mode: "parallel"
    tasks:
      - compile_backend
      - compile_frontend
      - build_docker

    max_concurrency: 3
    on_error: "stop"

    outputs:
      docker_image:
        source:
          type: state
          key: "docker.image_tag"

  # Grandchild group 1.2
  test:
    description: "Run test suite"
    parent: "build_and_test"
    execution_mode: "parallel"
    tasks:
      - run_unit_tests
      - run_integration_tests
      - run_e2e_tests

    depends_on: [build]
    max_concurrency: 3
    on_error: "continue"  # Collect all test failures

    outputs:
      test_coverage:
        source:
          type: state
          key: "test.coverage"

  # Child group 2
  deploy:
    description: "Deploy to ${workflow.environment}"
    parent: "ci_cd_pipeline"
    execution_mode: "sequential"
    tasks:
      - backup_current
      - deploy_new
      - verify_deployment

    depends_on: [build_and_test]
    condition: "${group.test.test_coverage} >= 0.8"
    timeout: 600
    on_error: "rollback"

    inputs:
      image:
        type: string
        required: true
        default: "${group.build.docker_image}"

    outputs:
      deployment_url:
        source:
          type: task
          task_id: "deploy_new"
          variable: "url"
```

This example demonstrates:
- ✓ 3-level hierarchy (pipeline → phases → stages)
- ✓ Sequential and parallel execution modes
- ✓ Group dependencies
- ✓ Task dependencies (implicit via group ordering)
- ✓ Conditional execution based on test coverage
- ✓ Variable inputs and outputs
- ✓ Variable interpolation in descriptions
- ✓ Different error handling strategies
- ✓ Timeouts at multiple levels
- ✓ Concurrency limits

---

## Schema Validation Rules

### Group References

1. All group IDs in `depends_on` must exist
2. All group IDs in `groups` must exist
3. Parent group ID must exist
4. No circular dependencies allowed

### Hierarchy

1. Child groups must have `parent` field
2. Parent must list child in `groups` field
3. No cycles in parent-child relationships

### Tasks

1. All task IDs in `tasks` must exist
2. Tasks can only belong to one group
3. Task dependencies must be within same group or across groups

### Variables

1. Input variable types must be valid
2. Output source types must be valid
3. Variable references must use valid scopes
4. Referenced groups/tasks must exist

### Execution

1. `execution_mode` must be valid enum value
2. `on_error` must be valid enum value
3. `timeout` must be positive integer
4. `max_concurrency` must be positive integer

---

## See Also

- [Main Documentation]./README.md - High-level overview and concepts
- [Architecture]./architecture.md - Implementation details
- [Tutorial]./tutorial.md - Step-by-step guide
- [Examples]../../examples/task-groups/ - Working examples