Patterns

Choose how to repeat work or start independent work without losing control of each run.

Choose fan-out when independent tasks need separate runs and retries. Choose a loop when one function must process a list or paginated source while saving progress.

  • Fan-out. See Fan-out. One event starts separate functions. Each function has its own run, retries, and history.
  • Working with loops. See Working with loops. One function processes a sequence or paginated source. Each iteration can save progress in a step. AI agents use the same building blocks. See Durable agents for tool loops, human approval, and sub-agent delegation.

For independent steps that belong to one run, use step.run with Promise.all() (group.Parallel in Go, ctx.group.parallel in Python).