Skip to main content

Overview

A factory node generates its instances at runtime rather than at authoring time. Where a swrm node has a static, author-defined set of agents, a factory decides how many instances to spawn based on a list resolved during execution — one instance per item, or a fixed count. Every instance runs in parallel (bounded by concurrency), and all outputs are collected into a list written to a single context path.

Execution modes

A factory node has three mutually exclusive modes, determined by which fields you set.

Mode 1 — Agent + for_each

One call to a named agent for each element in a runtime list.

Mode 2 — Agent + swarm_size

N identical calls to the same agent on the same input — useful for sampling multiple candidate responses.
swarm_size accepts a static integer or a template expression (e.g. "{{ inputs.count }}").

Mode 3 — Swrm + for_each

One full swrm — parallel specialist agents with an optional synthesis step — per list item.

Node fields


Loop variables

Inside inputs: templates, agent prompts, and swrm agent/synthesis prompts, three special variables are available: Each key under inputs: is additionally available in the spawned agent’s system prompt as {{ inputs.<key> }} once resolved — so inputs: { task: "{{ item }}" } makes {{ inputs.task }} reference the current item inside the agent’s prompt.
When for_each points at an LLM output that may emit prose, an empty string, or a fenced ```json block instead of a clean array, wrap it with | json_or_default('[]') so a bad response falls back to an empty list rather than failing the run. See Interpolation.

Output shape

All instance outputs are collected, in list order, and written to the writes path:
In Swrm + for_each mode, each entry is that item’s swrm result — the synthesis output when synthesis is defined, otherwise the list of agent outputs. Reference the collected list downstream like any other context value:

Failure handling

FactoryNodeError is importable from sirenspec.exceptions:

When to use a factory

Use a factory when:
  • The number of work items is unknown until runtime (e.g. a planner agent emits a task list).
  • You want N independent samples of the same prompt (swarm_size).
  • Each item needs a full committee-of-experts review (Swrm + for_each).
Use something else when:
  • The set of agents is fixed and known up front — use swrm.
  • Items must share intermediate state or run in sequence — use ordinary nodes with edges.

Cookbook recipes

See the YAML Reference for the full field-by-field listing.