PromptObjectModel

View as MarkdownOpen in Claude

PromptObjectModel is the low-level, serializable representation of a Prompt Object Model (POM) document — a tree of nested Section objects, each with a title, body text, bullet points, and arbitrarily nested subsections. It renders to Markdown or XML and round-trips through JSON and YAML.

Most agent code uses the higher-level PomBuilder wrapper, but PromptObjectModel is exposed directly so that callers can work with the same structure that agent.pom returns and load or save POMs as JSON/YAML.

1import { PromptObjectModel, Section } from '@signalwire/sdk';
2
3const pom = new PromptObjectModel();
4pom.addSection('Role', { body: 'You are a helpful assistant.' });
5pom.addSection('Rules', { bullets: ['Be concise', 'Be accurate'] });
6
7console.log(pom.renderMarkdown());

Constructor

debug
booleanDefaults to false

When true, print debug information to the console during renderMarkdown().

Properties

sections
Section[]

The top-level Section objects in the model.

debug
boolean

Whether debug output is printed during rendering.

Methods

See the Section page for the per-section methods (addBody, addBullets, addSubsection, toDict, renderMarkdown, renderXml).

SectionData

SectionData is the plain, serializable shape used by toDict(), toJson(), fromJson(), and fromYaml() for exchanging POM data.

title
string

Section heading. Omitted for the (optional) untitled first section.

body
string

Section body paragraph text.

bullets
string[]

List of bullet point strings.

subsections
SectionData[]

Nested child sections, same shape.

numbered
boolean

Whether this section is numbered when rendered.

numberedBullets
boolean

Whether bullet points are rendered as a numbered list.

Example

Round-trip through JSON

1import { PromptObjectModel } from '@signalwire/sdk';
2
3const pom = new PromptObjectModel();
4pom.addSection('Intro', { body: 'Welcome.' });
5pom.addSection('Rules', { bullets: ['Be nice.', 'Stay on topic.'] });
6
7const json = pom.toJson();
8const restored = PromptObjectModel.fromJson(json);
9console.log(restored.renderMarkdown());