Skip to content

StablePrefix ​

Manages the immutable prefix (system prompt + tools + few-shots) with SHA-256 fingerprinting.

Import ​

ts
import { StablePrefix } from "@halo-ai/core";

Constructor ​

ts
new StablePrefix(opts: {
  system: string;
  tools: ToolSpec[];
  fewShots?: ChatMessage[];
  hashFn?: (input: string) => string;
})

Properties ​

PropertyTypeDescription
fingerprintstringSHA-256[:16] hex. Changes on any mutation to system, tools, or few-shots
diagnosticsobject{ systemHash, toolSpecsHash, fewShotsHash, toolCount, toolNames }

Methods ​

MethodReturnsDescription
toMessages()ChatMessage[][system, ...fewShots] — immutable copies
tools()ToolSpec[]Frozen shallow copy of tool specs
addTool(spec)booleanAdd tool. false if name exists. Invalidates fingerprint
removeTool(name)booleanRemove tool. Invalidates fingerprint
addFewShot(msg)voidAdd few-shot example. Invalidates fingerprint
removeFewShot(index)booleanRemove few-shot by index. Invalidates fingerprint

Released under the MIT License.