Overview
Fragment builders are functions that createContextFragment objects. They provide a type-safe, ergonomic way to construct context data.
Base Types
ContextFragment
FragmentData
FragmentType
Core Utilities
fragment()
Create a wrapper fragment with nested children.role()
Create a role/system instructions fragment.Domain Fragments
term()
Define business vocabulary.name- The term or acronymdefinition- What the term means
hint()
Define behavioral rules and constraints.text- The rule or constraint (imperative language)
guardrail()
Define safety rules and boundaries.rule- The guardrail or restriction to enforcereason- (Optional) Why this guardrail existsaction- (Optional) What to do when triggered
explain()
Define rich concept explanations.concept- The concept being explainedexplanation- Metaphor or detailed explanationtherefore- (Optional) Actionable instruction
example()
Define question-answer pairs for few-shot learning.question- Natural language questionanswer- The correct answer or querynote- (Optional) Additional context
clarification()
Define when to ask for more information.when- Trigger conditionask- Question to ask the userreason- Why clarification is needed
workflow()
Define multi-step processes.task- Name of the workflowsteps- Sequential steps to executetriggers- (Optional) Phrases that activate this workflownotes- (Optional) Additional guidance
quirk()
Document data edge cases and workarounds.issue- Description of the quirk or edge caseworkaround- How to handle it
styleGuide()
Define style preferences and standards.prefer- Preferred approachnever- (Optional) Anti-patterns to avoidalways- (Optional) Rules that must always apply
analogy()
Define concept comparisons.concepts- Array of related conceptsrelationship- Comparison using real-world analogyinsight- (Optional) Key insight revealedtherefore- (Optional) Actionable instructionpitfall- (Optional) Common mistake to avoid
glossary()
Map terms to expressions.entries- Record mapping terms to SQL expressions
principle()
Define guiding principles.title- Principle namedescription- What this principle meanspolicies- (Optional) Specific rules implementing the principle
policy()
Define prerequisite rules.rule- The policy rulebefore- (Optional) What action this is a prerequisite forreason- (Optional) Why this rule matterspolicies- (Optional) Nested sub-policies
User Fragments
identity()
Define user identity.name- (Optional) User’s namerole- (Optional) User’s role or position
persona()
Define AI assistant persona.name- Persona’s namerole- (Optional) Persona’s expertise/identityobjective- (Optional) What the persona should accomplishtone- (Optional) Communication style
alias()
Define user-specific vocabulary.term- User’s termmeaning- What the user means by it
preference()
Define output preferences.aspect- What aspect this preference applies tovalue- The user’s preference
userContext()
Define current working focus.description- What the user is working on
correction()
Record corrections to understanding.subject- What was misunderstoodclarification- The correct understanding
Message Fragments
user()
Create user message.content- Message text or UIMessage objectreminders- (Optional) System reminders
assistant()
Create assistant message.message- UIMessage object with role ‘assistant’
assistantText()
Convenience for text-only assistant messages.content- Message textoptions- (Optional) Message options
reminder()
Create reminder payload.text- Reminder text or functionoptions- (Optional) Reminder optionsasPart- If true, add as separate part instead of inline
Type Guards
isFragment()
Check if value is a ContextFragment.isFragmentObject()
Check if value is a plain object.isMessageFragment()
Check if fragment is a message.Next Steps
Renderers API
Complete renderer API reference
StreamStore API
Complete stream storage API reference
Domain Knowledge
Learn about domain fragments
User Context
Learn about user fragments