Skip to content

preamble

preamble

Dynamic, context-aware preamble building for Marianne-orchestrated agents.

Generates preambles that tell agents who they are, where they are in the concert, and what success looks like. Replaces the static 5-rule warning label that was previously hardcoded in the retired native CLI executor.

Functions:

build_preamble

build_preamble(sheet_num, total_sheets, workspace, retry_count=0, is_parallel=False, healing_context=None)

Build a context-aware preamble for a Marianne-orchestrated agent.

Parameters:

Name Type Description Default
sheet_num int

Current sheet number (1-indexed).

required
total_sheets int

Total number of sheets in the concert.

required
workspace Path

Workspace directory path.

required
retry_count int

Number of previous failed attempts (0 = first run).

0
is_parallel bool

Whether parallel execution is enabled.

False
healing_context dict[str, Any] | None

Failure signals from the prior attempt (#201). When present on a retry, rendered into a bounded UNTRUSTED-EVIDENCE block so the agent knows specifically what failed instead of retrying blind. Carries the raw SheetState fields (error_code, error_message, validation_details, grounding_guidance, stderr_tail, error_history); None keys degrade gracefully.

None

Returns:

Type Description
str

Preamble string wrapped in <marianne-preamble> tags.

Source code in src/marianne/prompts/preamble.py
def build_preamble(
    sheet_num: int,
    total_sheets: int,
    workspace: Path,
    retry_count: int = 0,
    is_parallel: bool = False,
    healing_context: dict[str, Any] | None = None,
) -> str:
    """Build a context-aware preamble for a Marianne-orchestrated agent.

    Args:
        sheet_num: Current sheet number (1-indexed).
        total_sheets: Total number of sheets in the concert.
        workspace: Workspace directory path.
        retry_count: Number of previous failed attempts (0 = first run).
        is_parallel: Whether parallel execution is enabled.
        healing_context: Failure signals from the prior attempt (#201). When
            present on a retry, rendered into a bounded UNTRUSTED-EVIDENCE block
            so the agent knows specifically what failed instead of retrying
            blind. Carries the raw ``SheetState`` fields (error_code,
            error_message, validation_details, grounding_guidance, stderr_tail,
            error_history); ``None`` keys degrade gracefully.

    Returns:
        Preamble string wrapped in ``<marianne-preamble>`` tags.
    """
    if retry_count > 0:
        evidence = _render_failure_evidence(healing_context)
        return _build_retry_preamble(
            sheet_num, total_sheets, workspace, retry_count,
            failure_evidence=evidence,
        )
    return _build_first_run_preamble(
        sheet_num, total_sheets, workspace, is_parallel,
    )