Skip to content

builder

builder

Classes

PromptSection dataclass

PromptSection(name: str, content: str, source: str, cache_segment: PromptCacheSegment)

Inspectable prompt section emitted by SystemPromptBuilder.

SystemPromptBuilder

SystemPromptBuilder(agent_template: str, memory_files_config: Optional[MemoryFilesConfig] = None, system_prompt_config: Optional[SystemPromptConfig] = None, skill_index: Optional[List[Tuple[str, str]]] = None, session_context: Optional[str] = None, previous_state: Optional[str] = None, skill_catalog_xml: Optional[str] = None, skill_few_shot: Optional[List[str]] = None, skill_few_shot_examples: Optional[List[str]] = None)

Assembles system prompts with frozen prefix for cache stability.

Source code in src/openjarvis/prompt/builder.py
def __init__(
    self,
    agent_template: str,
    memory_files_config: Optional[MemoryFilesConfig] = None,
    system_prompt_config: Optional[SystemPromptConfig] = None,
    skill_index: Optional[List[Tuple[str, str]]] = None,
    session_context: Optional[str] = None,
    previous_state: Optional[str] = None,
    skill_catalog_xml: Optional[str] = None,
    skill_few_shot: Optional[List[str]] = None,
    skill_few_shot_examples: Optional[List[str]] = None,
) -> None:
    self._agent_template = agent_template
    self._mf_config = memory_files_config or MemoryFilesConfig()
    self._sp_config = system_prompt_config or SystemPromptConfig()
    self._skill_index = skill_index or []
    self._session_context = session_context
    self._previous_state = previous_state
    self._skill_catalog_xml = skill_catalog_xml
    # Allow either name; skill_few_shot_examples is the Plan 2A canonical name.
    if skill_few_shot_examples is not None:
        self._skill_few_shot = list(skill_few_shot_examples)
    else:
        self._skill_few_shot = list(skill_few_shot or [])
    self._frozen_prefix: Optional[str] = None
    self._frozen_sections: Optional[list[PromptSection]] = None
Functions
sections
sections() -> list[PromptSection]

Return prompt sections with lightweight cache/debug metadata.

Source code in src/openjarvis/prompt/builder.py
def sections(self) -> list[PromptSection]:
    """Return prompt sections with lightweight cache/debug metadata."""
    sections = [*self._get_frozen_sections()]
    if self._session_context:
        sections.append(
            PromptSection(
                name="session_context",
                content=f"## Session Context\n\n{self._session_context}",
                source="session_context",
                cache_segment="dynamic_suffix",
            )
        )
    if self._previous_state:
        sections.append(
            PromptSection(
                name="previous_state",
                content=f"## Previous State\n\n{self._previous_state}",
                source="previous_state",
                cache_segment="dynamic_suffix",
            )
        )
    return sections
persona_sections
persona_sections() -> str

Just the SOUL / MEMORY / USER persona, joined.

For agents that assemble their own system prompt (monitor_operative, operative) and want to append persona without letting the builder replace their specialized instructions (#376). Returns "" when no persona files are present.

Source code in src/openjarvis/prompt/builder.py
def persona_sections(self) -> str:
    """Just the SOUL / MEMORY / USER persona, joined.

    For agents that assemble their own system prompt (monitor_operative,
    operative) and want to *append* persona without letting the builder
    replace their specialized instructions (#376). Returns "" when no
    persona files are present.
    """
    return "\n\n".join(self._persona_sections())