Installation
Public API
Everything you need is exported at the top level:PIIDetectedError, InterpolationError, and FactoryNodeError are not re-exported at the top level — import them from sirenspec.exceptions when needed.
load_workflow
Load and validate a workflow file, returning a Workflow instance.
execute
Execute a workflow asynchronously and return a structured trace dict.
Returns:
A dict with the same structure as the
sirenspec run JSON output. See the CLI Reference for field descriptions.
execute_streaming
Execute a workflow and yield typed events as each node completes. Ideal for building interactive CLI tools, web dashboards, or any integration that needs real-time progress.
Yields:
The generator yields two types of events:
-
NodeCompleteEvent— Emitted once per node (active or skipped):node_id: str— The identifier of the completed node.node_type: str— One of"agent","tool","swrm","factory", or"workflow".status: Literal["success", "skipped", "failed"]— The node’s execution result.output: Any— The node’s output value (string, dict, list, or None).writes: str— The context path written by this node (only for successful agent nodes).error: str | None— Error message whenstatus="failed".tokens: int— Total tokens consumed by this node (0 for tool and skipped nodes).agents: list[dict[str, Any]] | None— Per-agent execution traces (swrm nodes only). Each dict containsid,prompt_sent,response_received,tokens,duration_ms, anderror.Nonefor all non-swrm node types.duration_ms: float | None— Wall-clock execution time in milliseconds for swrm nodes.Nonefor all other node types.
-
SummaryEvent— Emitted once at the end of execution:total_nodes: int— Number of nodes that ran (active nodes only, excluding skipped).total_tokens: int— Aggregate token count across all active nodes.status: Literal["success", "failed"]— Overall workflow status.duration_ms: float— Wall-clock execution time in milliseconds.
WorkflowRegistry
A registry that maps string names to Workflow instances. Pass a populated registry to execute or execute_streaming when your workflow uses workflow nodes with named ref values.
File-path refs (starting with . or /) are resolved directly from disk — no registry needed for those.
Error Handling
All SirenSpec exceptions inherit fromSirenSpecError:
Extending SirenSpec
Custom LLM Provider
Implement theLLMProvider Protocol to add support for a new backend:
Custom Guardrail
SubclassGuardrail to add a new per-node policy:
Token Usage
TokenUsage is a frozen dataclass for tracking prompt and completion tokens:
Properties / Methods: