Skip to content

prompt

prompt

PromptMessage dataclass

PromptMessage(
    *,
    system_text: str = "",
    contexts: tuple[tuple[str, str], ...] = (),
    ask_text: str = "",
)

Fluent builder for structured LLM prompts with system text, XML context sections, and a question.

Chain .system(), .context(tag, content), and .ask() to build prompts. str() renders the full prompt with XML-wrapped context blocks.

load classmethod
load(
    name: str,
    *,
    base: str | Path | None = None,
    **vars: object,
) -> PromptMessage

Load a prompt from a .md file and render it via :meth:from_template.

Resolution searches directories in order, returning the first existing file: the base directory if given (otherwise a prompts/ directory beside the calling module), then the framework's bundled captain_hook/prompts/. The file path is <dir>/<name>.md; name may contain / to nest.

Parameters:

Name Type Description Default
name str

Prompt name without the .md suffix; may include / for nesting.

required
base str | Path | None

Optional directory to search instead of the caller-relative prompts/.

None
**vars object

Template variables substituted into the file via str.format_map.

{}

Returns:

Name Type Description
A PromptMessage

class:PromptMessage whose system text is the rendered file contents.

Raises:

Type Description
FileNotFoundError

If no matching file exists in any searched directory.

KeyError

If the file references a placeholder not supplied in **vars.