Skip to content

symfonic.agent.prompts.stratigraphic_layers

stratigraphic_layers

L1/L2 template rendering for prompt_layer_mode='stratigraphic'.

The legacy hms_system.txt template interleaves session-stable content (role, data sovereignty, domain directives, memory architecture, tool manifest, reasoning directives, extraction obligation, activation-log rules) with per-turn volatile content (timestamp, active tools, memory context, prospective tasks, hydrated/RAG context). That interleaving is fine for legacy single-string mode but fatal for prompt caching: any volatile token anywhere in the cached prefix invalidates the cache every turn.

Stratigraphic mode therefore renders two separate bundled templates:

  • hms_system_l1.txt -- session-stable only. Becomes the L1 cached layer. No timestamp, no memory context, no hydrated context, no active tools, no prospective tasks.
  • hms_system_l2.txt -- per-turn volatile only. Becomes the L2 uncached layer: timestamp, active tools, memory context, prospective tasks, hydrated/RAG context.

Legacy mode is untouched -- it still renders hms_system.txt via HMSSystemPromptSection byte-for-byte. These templates are additive and only loaded on the stratigraphic path.

Rendering reuses system_prompt._substitute so placeholder semantics (UPPER_SNAKE keys, lower_snake fallback, leave-unresolved-then-raise) match the legacy section exactly.

render_l1_body

render_l1_body(state: dict[str, object]) -> str

Render the session-stable L1 layer from hms_system_l1.txt.

Parameters:

Name Type Description Default
state dict[str, object]

The same placeholder mapping the legacy HMS section consumes. Only the stable keys are referenced here (TENANT_ID, NAMESPACE, DOMAIN_DESCRIPTION, TOOL_MANIFEST); volatile keys are ignored.

required

Returns:

Type Description
str

The fully substituted L1 body string.

Source code in src/symfonic/agent/prompts/stratigraphic_layers.py
def render_l1_body(state: dict[str, object]) -> str:
    """Render the session-stable L1 layer from ``hms_system_l1.txt``.

    Args:
        state: The same placeholder mapping the legacy HMS section
            consumes.  Only the stable keys are referenced here
            (``TENANT_ID``, ``NAMESPACE``, ``DOMAIN_DESCRIPTION``,
            ``TOOL_MANIFEST``); volatile keys are ignored.

    Returns:
        The fully substituted L1 body string.
    """
    return _render(_L1_TEMPLATE, state)

render_l2_body

render_l2_body(state: dict[str, object]) -> str

Render the per-turn volatile L2 layer from hms_system_l2.txt.

Parameters:

Name Type Description Default
state dict[str, object]

The same placeholder mapping the legacy HMS section consumes. Only the volatile keys are referenced here (ACTIVE_TOOLS, CURRENT_TIMESTAMP, MEMORY_CONTEXT, PROSPECTIVE_TASKS, HYDRATED_CONTEXT).

required

Returns:

Type Description
str

The fully substituted L2 body string.

Source code in src/symfonic/agent/prompts/stratigraphic_layers.py
def render_l2_body(state: dict[str, object]) -> str:
    """Render the per-turn volatile L2 layer from ``hms_system_l2.txt``.

    Args:
        state: The same placeholder mapping the legacy HMS section
            consumes.  Only the volatile keys are referenced here
            (``ACTIVE_TOOLS``, ``CURRENT_TIMESTAMP``, ``MEMORY_CONTEXT``,
            ``PROSPECTIVE_TASKS``, ``HYDRATED_CONTEXT``).

    Returns:
        The fully substituted L2 body string.
    """
    return _render(_L2_TEMPLATE, state)