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.
| Name | Type | Description |
|---|---|---|
load_workflow | function | Load and validate a YAML workflow file. |
execute | async function | Execute a workflow and return the full trace dict. |
execute_streaming | async generator function | Execute a workflow and yield typed events as each node completes. |
Workflow | class | Pydantic model representing a workflow. |
WorkflowRegistry | class | Registry mapping names to Workflow instances for nested workflow resolution. |
BudgetConfig | class | Pydantic model for the workflow-level budget: block (max_tokens, max_cost_usd, max_duration_s, on_exceeded). |
HumanNode | class | Pydantic model for type: human nodes. |
NodeCompleteEvent | dataclass | Event emitted once per node during streaming execution. |
SummaryEvent | dataclass | Event emitted once at the end of streaming execution. |
TokenUsage | dataclass | Prompt and completion token counts with a .total property. |
LLMProvider | Protocol | Implement this to add a custom LLM provider. |
Guardrail | ABC | Subclass this to write a custom per-node guardrail. |
WorkflowGuardrail | Protocol | Implement this to write a custom workflow-level guardrail. |
GuardrailSpec | class | Pydantic model for inline guardrail configuration (name + config). |
load_workflow
Load and validate a workflow file, returning a Workflow instance.
| Exception | When |
|---|---|
FileNotFoundError | The workflow file — or a declared env_file — does not exist. |
ValueError | YAML is malformed or fails schema validation. |
WorkflowLintError | The load-time linter found a blocking issue, such as a {{ working.<node_id>.* }} reference. |
execute
Execute a workflow asynchronously and return a structured trace dict.
| Parameter | Type | Description |
|---|---|---|
workflow | Workflow | Validated workflow instance from load_workflow. |
user_input | str | The initial user message passed to the first (root) node. |
registry | WorkflowRegistry | None | Registry of named sub-workflows for resolving workflow nodes by name. File-path refs (starting with . or /) are resolved from disk without a registry. |
human_input_fn | InputCoroutine | None | Async callable supplying operator responses for type: human nodes. Defaults to reading a single line from stdin. Inject a mock in tests or wire in a webhook bridge in production. |
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.
| Parameter | Type | Description |
|---|---|---|
workflow | Workflow | Validated workflow instance from load_workflow. |
user_input | str | The initial user message passed to the first (root) node. |
registry | WorkflowRegistry | None | Registry of named sub-workflows. Same semantics as execute. |
human_input_fn | InputCoroutine | None | Async callable supplying operator responses for type: human nodes. Same semantics as execute. |
-
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.
| Method | Description |
|---|---|
register(name, workflow) | Register a Workflow under name. |
get(name) | Return the workflow registered under name. Raises KeyError if not found. |
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:
| Field | Type | Description |
|---|---|---|
prompt_tokens | int | Tokens in the input. |
completion_tokens | int | Tokens in the output. |
| Name | Returns | Description |
|---|---|---|
.total | int | Sum of prompt and completion tokens. |
__add__(other) | TokenUsage | Combine two usages; returns a new instance. |