patterns
patterns
¶
Pattern expander — expands named patterns into sheet sequences.
Patterns from the Rosetta corpus (Cathedral Construction, Composting Cascade, Fan-out + Synthesis, etc.) are available as named patterns the compiler can compose into sheet sequences.
This is the extensibility point: a pattern library that the compiler draws from to produce sheets with the right cognitive structure for the task.
Two expansion modes
- Prompt extension —
expand()merges per-phase prompt additions into the agent cycle. Lightweight; enriches existing sheet structure. - Stage expansion —
expand_stages()returns a concrete stage sequence with purposes, instrument guidance, and validation shapes. Structural; defines what the sheet arrangement looks like.
Classes¶
PatternStage
dataclass
¶
A single stage within an expanded pattern.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Stage identifier (e.g. |
sheets |
int | str
|
Number of sheets — an |
purpose |
str
|
What this stage accomplishes. |
instrument_guidance |
str
|
Advice on which instrument fits the stage. |
fallback_friendly |
bool
|
Whether cheaper fallback instruments are viable. |
artifacts |
tuple[str, ...]
|
Tuple of expected output file paths/globs. |
PatternExpander
¶
Expands named patterns into sheet sequence modifiers.
Patterns inject additional prompt context and structural guidance into specific phases of the agent cycle. Two expansion modes:
expand()— prompt extensions (per-phase text additions).expand_stages()— concrete stage sequence with purposes, instrument guidance, and validation shapes.
Initialize with optional custom patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
custom_patterns
|
dict[str, dict[str, Any]] | None
|
Additional patterns to register beyond builtins. |
None
|
Source code in src/marianne/compose/patterns.py
Functions¶
expand
¶
Expand named patterns into per-phase prompt extensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern_names
|
list[str]
|
List of pattern names to apply. |
required |
agent_def
|
dict[str, Any]
|
Agent definition for context. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with keys:
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a pattern name is not recognised. |
Source code in src/marianne/compose/patterns.py
expand_stages
¶
Expand a pattern into a concrete stage sequence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern_name
|
str
|
Name of the pattern to expand. |
required |
params
|
dict[str, Any] | None
|
Optional parameters to customise expansion.
Supported keys:
|
None
|
Returns:
| Type | Description |
|---|---|
list[PatternStage]
|
Ordered list of :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the pattern is unknown or has no stage definition. |
Source code in src/marianne/compose/patterns.py
expand_stages_with_validations
¶
Expand a pattern into stages and generate validation shapes.
Validation shapes are derived from each stage's declared artifacts.
Each artifact produces a file_exists validation template.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern_name
|
str
|
Name of the pattern to expand. |
required |
params
|
dict[str, Any] | None
|
Optional expansion parameters (see :meth: |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with keys:
|
Source code in src/marianne/compose/patterns.py
list_patterns
¶
List all available patterns with descriptions.
Returns:
| Type | Description |
|---|---|
list[dict[str, str]]
|
List of dicts with |
Source code in src/marianne/compose/patterns.py
get_pattern
¶
Get a pattern definition by name.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
Pattern dict or |
load_rosetta_corpus
¶
Load patterns from a Rosetta corpus directory.
Reads *.md files in corpus_dir, parses YAML frontmatter,
and registers patterns that contain a stages field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
corpus_dir
|
str | Path
|
Directory containing pattern markdown files. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
Dict of loaded pattern slug → pattern data. Only patterns |
dict[str, dict[str, Any]]
|
with parseable frontmatter and a |