# Evolving Workflow

> Templates for building parallel AI agent workflows in MoonBit. Includes patterns for simple fan-out processing and multi-phase orchestration with automatic retry and validation. Use when this capability is needed.

- Skill: `tomevault-io/evolving-workflow` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/evolving-workflow`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/evolving-workflow/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/evolving-workflow

---


# Evolving Workflow

Templates for building parallel AI agent workflows using the Codex SDK.

## Templates

| Template | Pattern | Description |
|----------|---------|-------------|
| [parallel_tasks](assets/parallel_tasks) | Fan-out | Process items in parallel with bounded concurrency |
| [multi_phase](assets/multi_phase) | Fan-out → Sequential → Fan-out | Three-phase workflow with intermediate planning |

## Project Structure

```
your_workflow/
├── main.mbt           # Orchestration (usually unchanged)
├── moon.pkg.json
└── app/
    ├── job.mbt        # TaskHandle lifecycle (customize this)
    ├── args.mbt       # CLI parsing
    └── moon.pkg.json
```

## main.mbt: Orchestration

The main file orchestrates: initialize → spawn parallel agents → summarize results.

```moonbit
async fn main {
  let config = @app.initialize() catch { ... }
  let codex = @codex.Codex::new()

  let results = @shared.for_all_tasks(
    config.items,
    async fn(idx, _) {
      let handle = config.task_start(idx)
      try {
        let thread = codex.start_thread(...)
        @async.retry(@async.RetryMethod::Immediate, fn() {
          let prompt = handle.prompt()
          let response = thread.run(prompt)
          handle.validate(response.final_response)
          handle.finish()
        }, max_retry=3)
      } catch { e => handle.error(e) }
    },
    parallelism=config.parallelism,
  )
  config.summarize(results)
}
```

For multi-phase, the pattern chains three phases: summarize (fan-out) → plan (sequential) → process (fan-out).

## Customization

Edit `app/job.mbt` to customize:

| Function | What to change |
|----------|----------------|
| `discover_items()` | How to find targets to process |
| `read_item_content()` | What data to load for prompts |
| `prompt()` | Your task instructions |
| `validate()` | Success criteria (raise to retry) |
| `finish()` | How to save results |

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/moonbit-community) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-13 -->

