Overview
Afactory 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
Insideinputs: 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.
Output shape
All instance outputs are collected, in list order, and written to thewrites path:
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).
- 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
- Changelog Annotator — agent +
for_each - GitHub Issues Triage — agent +
for_each - Grading Factory — swrm +
for_each