selfware 0.6.1

Your personal AI workshop — software you own, software that lasts
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
# SWL Runtime Documentation

Selfware Workflow Language (SWL) is a declarative-imperative hybrid language for agent orchestration with first-class observability.

## Table of Contents

- [Overview]#overview
- [Creating Workflows]#creating-workflows
- [Agent Definition Format]#agent-definition-format
- [Workflow Types]#workflow-types
- [Validating Workflows]#validating-workflows
- [Running Workflows]#running-workflows
- [Examples]#examples

## Overview

SWL treats agent orchestration as **infrastructure-as-code** with **first-class observability**. Every construct emits telemetry automatically.

```yaml
# example.swl - Minimal workflow
version: "1.0"
name: hello_world

agents:
  greeter:
    model: claude-sonnet-4
    role: A friendly greeting agent
    instruction: Generate a warm welcome message

workflows:
  say_hello:
    type: sequential
    steps:
      - delegate: greeter
```

## Creating Workflows

### File Structure

SWL files use the `.swl` extension and are written in YAML format:

```yaml
version: "1.0"                    # SWL version
name: my_workflow                 # Workflow name
description: Optional description

agents:
  # Agent definitions

workflows:
  # Workflow definitions

guardrails:
  # Safety guardrails

telemetry:
  # Observability configuration

state:
  # State schema definition
```

### Basic Components

| Component | Description | Required |
|-----------|-------------|----------|
| `version` | SWL version string | Yes |
| `name` | Workflow identifier | Yes |
| `agents` | Map of agent definitions | Yes |
| `workflows` | Map of workflow definitions | Yes |
| `guardrails` | List of safety constraints | No |
| `telemetry` | Metrics and tracing config | No |
| `state` | State schema definition | No |

## Agent Definition Format

### Simple Agent

```yaml
agents:
  my_agent:
    model: claude-sonnet-4
    role: Brief role description
    instruction: What the agent should do
```

### Detailed Agent Configuration

```yaml
agents:
  code_reviewer:
    model:
      provider: openai
      name: txn545/Qwen3.5-122B-A10B-NVFP4
      temperature: 0.1
      max_tokens: 8192
    role: |
      You are a staff engineer doing code review.
      You catch bugs that pass CI.
    instruction: |
      Review the code diff thoroughly.
      Check for: logic errors, edge cases, security issues.
    tools:
      - file_read
      - file_diff
      - git_log
    output_key: review_output
    sub_agents: []
```

### Agent Fields

| Field | Type | Description | Required |
|-------|------|-------------|----------|
| `model` | string or object | Model specification | Yes |
| `role` | string | Agent's persona/identity | No |
| `instruction` | string | Task instructions | No |
| `tools` | list | Available tool names | No |
| `output_key` | string | Key for storing output | No |
| `sub_agents` | list | Nested agent names | No |

### Model Specification

**Simple format:**
```yaml
model: claude-sonnet-4
```

**Detailed format:**
```yaml
model:
  provider: openai              # API provider
  name: model-name              # Model identifier
  temperature: 0.1              # Sampling temperature (0-1)
  max_tokens: 8192              # Maximum output tokens
```

## Workflow Types

### Sequential

Execute agents one after another:

```yaml
workflows:
  pipeline:
    type: sequential
    description: "Step-by-step processing"
    steps:
      - delegate: data_loader
      - delegate: processor
        input:
          mode: "strict"
      - delegate: validator
```

### Parallel

Execute agents concurrently:

```yaml
workflows:
  multi_review:
    type: parallel
    description: "Run all reviewers at once"
    steps:
      - delegate: security_reviewer
      - delegate: performance_reviewer
      - delegate: test_reviewer
    
    # Optional merge phase
    merge:
      agent: aggregator
      instruction: "Consolidate all reviews"
```

### Map-Reduce

Distribute work across agents, then aggregate:

```yaml
workflows:
  distributed_analysis:
    type: map_reduce
    description: "Parallel analysis with aggregation"
    
    map:
      targets: [backend_specialist, frontend_specialist, devops_specialist]
      input:
        scope: "full"
      parallel:
        branches:
          - delegate: backend_specialist
          - delegate: frontend_specialist
          - delegate: devops_specialist
    
    reduce:
      agent: consensus_aggregator
      inputs:
        - backend_analysis
        - frontend_analysis
        - devops_analysis
```

### Conditional

Branch based on conditions:

```yaml
workflows:
  smart_pipeline:
    type: conditional
    steps:
      - delegate: condition_checker
      - guard:
          condition:
            language: rust
            content: |
              args.previous_output.contains("proceed")
          on_violation: block
      - delegate: next_step
```

### Workflow Step Types

| Step Type | Description |
|-----------|-------------|
| `delegate` | Execute an agent |
| `parallel` | Execute branches concurrently |
| `guard` | Conditional execution with guardrails |


## Validating Workflows

Validate SWL files before running:

```bash
# Validate an SWL file
selfware workflow validate workflows/my_workflow.swl

# Validate with detailed output
selfware workflow validate workflows/product_build.yml
```

Validation checks:
- Required fields (version, name, agents, workflows)
- Agent references exist
- Model specifications are valid
- Workflow type compatibility
- Guardrail conditions
- State schema definitions

### Validation Example Output

```
⚙ Workflow Validation

   📝 File: workflows/code_review.swl

   ✓ SWL file is valid!
   Name: comprehensive_code_review
   Version: 1.0
   Agents: 4
   Workflows: 3
```

## Running Workflows

### Dry-Run Mode

Test workflows without executing LLM calls:

```bash
# Dry-run to verify workflow structure
selfware workflow run workflows/product_build.yml --dry-run \
  --input idea="Daily briefing app" \
  --input target_user="Busy founders"
```

Dry-run mode:
- Parses and validates the workflow
- Logs intended actions
- Does not make API calls
- Useful for testing and debugging

### Live Execution

Run workflows with actual LLM calls:

```bash
# Run with inputs
selfware workflow run workflows/product_build.yml \
  --input idea="Daily briefing app for founders" \
  --input target_user="Busy founders" \
  --input constraints="Rust backend, web frontend" \
  --input verification_command="cargo test --quiet"

# Run without inputs (uses defaults)
selfware workflow run workflows/code_review.swl
```

### Listing Workflows

```bash
# List SWL workflows in current directory
selfware workflow list

# List all workflows including YAML
selfware workflow list --all

# List workflows in specific directory
selfware workflow list --dir ./workflows
```


## Examples

### Example 1: Code Review Workflow

```yaml
# code_review.swl
version: "1.0"
name: comprehensive_code_review
description: Multi-layer code review

agents:
  staff_engineer:
    model:
      provider: openai
      name: txn545/Qwen3.5-122B-A10B-NVFP4
      temperature: 0.1
    role: Staff engineer reviewing code
    instruction: Review for logic errors, edge cases, and design
    tools:
      - file_read
      - file_diff
    output_key: staff_review

  security_reviewer:
    model:
      provider: openai
      name: txn545/Qwen3.5-122B-A10B-NVFP4
      temperature: 0.1
    role: Security engineer
    instruction: Focus on OWASP Top 10 and security issues
    tools:
      - file_read
    output_key: security_review

workflows:
  full_review:
    type: parallel
    steps:
      - delegate: staff_engineer
      - delegate: security_reviewer
    merge:
      agent: staff_engineer
      instruction: Consolidate all findings

guardrails:
  - name: block_if_critical
    type: post_agent
    condition:
      language: rust
      content: |
        !args.agent_outputs.security_review.contains("[CRITICAL]")
    on_violation: block
```

### Example 2: Multi-Agent Swarm

```yaml
# multi_agent_swarm.swl
version: "1.0"
name: multi_agent_swarm
description: Parallel specialists with consensus

agents:
  backend_specialist:
    model:
      provider: openai
      name: txn545/Qwen3.5-122B-A10B-NVFP4
      temperature: 0.3
    role: Backend architecture specialist
    instruction: Analyze from backend perspective
    output_key: backend_analysis

  frontend_specialist:
    model:
      provider: openai
      name: txn545/Qwen3.5-122B-A10B-NVFP4
      temperature: 0.3
    role: Frontend architecture specialist
    instruction: Analyze from frontend perspective
    output_key: frontend_analysis

  consensus_aggregator:
    model:
      provider: openai
      name: txn545/Qwen3.5-122B-A10B-NVFP4
      temperature: 0.2
    role: Synthesize expert opinions
    instruction: Create integrated implementation plan
    output_key: consensus_spec

workflows:
  swarm_with_consensus:
    type: map_reduce
    map:
      parallel:
        branches:
          - delegate: backend_specialist
          - delegate: frontend_specialist
    reduce:
      agent: consensus_aggregator
      inputs:
        - backend_analysis
        - frontend_analysis
```

### Example 3: Product Build Workflow

```yaml
# product_build.yml (YAML workflow format)
name: product_build
description: End-to-end product build workflow
version: "1.0.0"

inputs:
  - name: idea
    description: Product idea
    required: true
  - name: target_user
    description: Primary user persona
    required: false
    default: "Technical teams"

outputs:
  - name: discovery_brief
    description: Product discovery brief
    from: discovery_brief

steps:
  - id: kickoff
    name: Kickoff
    type: log
    message: "Building: ${idea}"
    level: info

  - id: discovery_brief
    name: Discovery
    type: llm
    prompt: |
      Analyze this product idea: ${idea}
      Target user: ${target_user}
      Create a discovery brief.
    timeout_secs: 180
```

### Example 4: Simple Test Workflow

```yaml
# test_simple.swl
version: "1.0"
name: test_workflow

agents:
  test_agent:
    model: claude-sonnet-4
    role: tester
    instruction: Run tests

workflows:
  test_flow:
    type: sequential

guardrails:
  - name: test_guard
    type: block
    condition: "true"
    on_violation: warn

telemetry:
  traces:
    - inference
```

## Guardrails

Guardrails provide safety constraints:

```yaml
guardrails:
  - name: rate_limiter
    type: before_model
    condition: |
      rate(requests_per_minute) < 60
    on_violation: queue_and_retry
    
  - name: cost_cap
    type: global
    condition:
      language: rust
      content: |
        total_cost < budget.limit
    on_violation: pause_and_notify
```

### Guardrail Types

| Type | Description |
|------|-------------|
| `before_model` | Check before LLM call |
| `before_tool` | Check before tool execution |
| `post_agent` | Check after agent completes |
| `post_workflow` | Check after workflow completes |
| `global` | Always active |

### Violation Actions

| Action | Description |
|--------|-------------|
| `block` | Stop execution |
| `warn` | Log warning and continue |
| `queue_and_retry` | Queue for later retry |
| `pause_and_notify` | Pause and notify user |

## Telemetry

Configure observability:

```yaml
telemetry:
  enabled: true
  metrics:
    - parallel_agent_count
    - consensus_time_ms
    - agreement_percentage
  traces:
    - workflow_execution
    - agent_delegation
    - tool_invocation
  export:
    type: file
    path: "./logs/telemetry.jsonl"
```

## State Management

Define workflow state schema:

```yaml
state:
  fields:
    - name: task_description
      type: string
      description: The task being analyzed
    
    - name: specialist_count
      type: integer
      description: Number of specialists
      default: 4
    
    - name: consensus_reached
      type: boolean
      description: Whether consensus was achieved
      default: false
    
    - name: conflict_areas
      type: array
      element_type: string
      description: Areas of disagreement
      default: []
```

## CLI Commands Reference

| Command | Description |
|---------|-------------|
| `selfware workflow validate <file>` | Validate workflow file |
| `selfware workflow run <file>` | Execute workflow |
| `selfware workflow run <file> --dry-run` | Test without execution |
| `selfware workflow list` | List available workflows |
| `selfware workflow list --all` | List all formats |

## File Formats

SWL supports two workflow formats:

| Format | Extension | Use Case |
|--------|-----------|----------|
| SWL | `.swl` | Agent orchestration |
| YAML | `.yml`, `.yaml` | Step-based workflows |

## Further Reading

- See example workflows in this directory


---

## Product Workflow Set

The product workflow set is inspired by `garrytan/gstack` and `alirezarezvani/claude-skills`.

### Files

- `product_discovery.yml`: Discovery brief plus assumption risk register
- `product_delivery.yml`: Architecture, sprint plan, and review gate
- `product_release.yml`: Release checklist, docs plan, and launch note
- `product_build.yml`: Orchestrates the three workflows above

### Product Workflow Example

```bash
# Validate the product workflow
selfware workflow validate workflows/product_build.yml

# Run in dry-run mode
selfware workflow run workflows/product_build.yml \
  --input idea="Daily briefing app for founders" \
  --input target_user="Busy founders" \
  --input constraints="Rust backend, web frontend, ship in one week" \
  --input repo_context="Selfware repo with workflow and agent runtime" \
  --input verification_command="cargo test --quiet" \
  --input smoke_test_command="cargo test --quiet" \
  --dry-run
```

For a configuration starting point, see the checked-in `selfware.example.toml`.