Context Layers
Instructions
A read-only context layer that loads instructional content once at init and injects it into every recall, wrapped in an XML tag.
Overview
Instructions is the simplest way to put fixed instructional material — style guides, project conventions, persona text — in front of the model on every turn. The content is loaded once by an async load function at init, wrapped in an XML tag, and returned verbatim from recall.
- Default slot:
105(Slot.SCRATCHPAD + 5) - Default scope:
resource - Budget: none declared (treated as
'auto') - Placement:
'anchor'— the content is loaded once and never changes, so it belongs in the cache-stable prefix
Usage
import { instructions } from '@noetic-tools/core';
const conventions = instructions({
id: 'project-conventions',
tag: 'project_conventions',
load: async () => readFile('CONVENTIONS.md', 'utf-8'),
});The model then sees:
<project_conventions>
...file contents...
</project_conventions>Configuration
interface InstructionsOptions {
id?: string; // default 'instructions'
slot?: number; // default Slot.SCRATCHPAD + 5
scope?: ContextScope; // default 'resource'
load: () => Promise<string>;
tag?: string; // default 'instructions'
}| Field | Type | Default | Purpose |
|---|---|---|---|
id | string | 'instructions' | Layer id — set one per instance when stacking several instruction layers |
slot | number | 105 | Position in the assembled view |
scope | ContextScope | 'resource' | Persistence boundary |
load | () => Promise<string> | required | Loads the content once at init. An empty result yields an empty layer |
tag | string | 'instructions' | XML tag name wrapping the content |
Behavior
init— callsload()once and stores the content wrapped as<tag>...</tag>. An empty load result stores the empty string, andrecallthen contributes nothing.recall— returns the stored block as-is. When the content exceeds the allocated budget, it is trimmed to fit while keeping the XML well-formed: the text is cut to the budget (minus the closing tag) and the closing</tag>is re-appended.- Zero budget fails open — a
budgetof0(or negative) skips the trim entirely and returns the full content rather than silently dropping load-bearing instructions.