Skip to main content

Xprompt Package Cheatsheet

Root namespace: Cognesy\Xprompt This file is a quick, code-aligned map of the package surface. For narrative guidance and design rationale, see packages/xprompt/concept.md.

1. Prompt (base class)

Properties

Static Constructors

Rendering

Override Point

Metadata & Introspection

Config

2. NodeSet (structured data prompt)

Properties

Methods

Default Node Format

3. PromptRegistry

Constructor

Registration & Retrieval

Introspection

4. AsPrompt Attribute

Usage:

5. PromptDiscovery

Discovery priority: #[AsPrompt] > $promptName property > FQCN convention.

6. flatten()

  • null -> ''
  • string -> pass through
  • Prompt -> $node->render(...$ctx)
  • array -> recurse, join with "\n\n", skip empties
  • Stringable -> (string) $node

Minimal Examples

Inline prompt

Template-backed prompt

Composition

Integration with StructuredOutput / Agents

Variant swap