Skip to content

API Reference parrot.bots.prompts.layers

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.bots.prompts.layers

View source

Composable prompt layer system.

Defines the core PromptLayer dataclass and all built-in layers that replace the monolithic prompt templates (BASIC_SYSTEM_PROMPT, AGENT_PROMPT, etc.).

Each layer is an immutable, composable unit with:

  • A priority that determines rendering order
  • A template using $variable placeholders (string.Template)
  • A phase (CONFIGURE or REQUEST) controlling when variables resolve
  • An optional condition for conditional inclusion

See spec: sdd/specs/composable-prompt-layer.spec.md (Sections 3.1, 3.2)

Attribute BEHAVIOR_LAYER

Attribute EXPERT_KNOWLEDGE_LAYER

Attribute EXPERT_RULES_LAYER

Attribute IDENTITY_LAYER

Attribute KNOWLEDGE_LAYER

Class LayerPriority

Execution order. Lower = rendered first in the prompt.

Attribute OUTPUT_LAYER

Attribute PRE_INSTRUCTIONS_LAYER

Class PromptLayer

Single composable prompt layer.

Parameter Type Default Description
name str
priority LayerPriority | int
template str
phase RenderPhase RenderPhase.REQUEST
condition Optional[Callable[[Dict[str, Any]], bool]] None
required_vars frozenset[str] frozenset()
cacheable Optional[bool] None
literal bool False

Fields:

Field Type Default Description
name str Unique identifier for this layer.
priority LayerPriority | int Rendering order (lower = earlier in prompt).
template str XML template with $variable placeholders.
phase RenderPhase RenderPhase.REQUEST When to resolve variables (CONFIGURE or REQUEST).
condition Optional[Callable[[Dict[str, Any]], bool]] None Optional callable; layer is skipped if it returns False.
required_vars frozenset[str] field(default_factory=frozenset) Set of variable names that must be present.
cacheable Optional[bool] field(default=None) Whether this layer is eligible for provider-side prompt caching (FEAT-181). Defaults to True for CONFIGURE-phase layers and False for REQUEST-phase layers. Can be explicitly overridden per-layer by passing cacheable=False (or True).
literal bool False When True the template is plain text, never substituted: render() / partial_render() return it verbatim. Use it for layers built from untrusted or user-authored text (e.g. skill descriptions) where a $name must not expand (FEAT-707).

Method PromptLayer.render

Render this layer with the given context.

render(context: Dict[str, Any]) -> Optional[str]

Parameter Type Default Description
context Dict[str, Any] Dictionary of variable values for substitution.

Returns: Optional[str] — Rendered string, or None if the condition fails.

Method PromptLayer.partial_render

Render only the variables present in context, return a new layer with remaining $placeholders intact for the next phase.

This is the key to two-phase rendering: CONFIGURE phase resolves static vars, leaving REQUEST vars as $placeholders.

Invariant (FEAT-181): after configure() calls this method, cacheable is the authoritative cache-eligibility flag for the returned layer and phase is always REQUEST (since the returned layer will be rendered at request time). The original cacheable value is propagated unchanged so build_segments() can correctly mark CONFIGURE-phase layers as cacheable even after phase normalisation.

partial_render(context: Dict[str, Any]) -> PromptLayer

Parameter Type Default Description
context Dict[str, Any] Dictionary of variable values for partial substitution.

Returns: PromptLayer — New PromptLayer with partially resolved template.

Class RenderPhase

When a layer's variables get resolved.

Attribute SECURITY_LAYER

Attribute TOOLS_LAYER

Attribute USER_SESSION_LAYER

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally