agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
54 lines • 2.14 kB
JavaScript
;
/**
* Narrative beats — the unit of narrative memory.
*
* A `NarrativeBeat` is a self-contained summary extracted from one or
* more messages during a turn. Instead of persisting raw conversation
* forever, a narrative pipeline compresses each turn into beats and
* recalls them by composing beats back into a coherent story.
*
* Core properties:
* - **Summary**: a single sentence describing what happened.
* - **Importance**: 0..1 score the picker uses to prefer salient
* beats when the context-token budget is tight.
* - **Refs**: ids of the source messages the beat was extracted
* from. Lets consumers walk backwards from a recalled beat to
* the raw source — the explainability story.
* - **Category**: optional free-form tag (e.g. `"identity"`,
* `"preference"`, `"fact"`). Extractors / consumers pick their
* own taxonomy.
*
* Beats are persisted via the ordinary `MemoryStore` interface —
* `MemoryEntry<NarrativeBeat>` slots in unchanged. No storage changes
* needed to support narrative memory.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.isNarrativeBeat = exports.asImportance = void 0;
/**
* Clamp a value to the valid [0, 1] importance range. Non-finite
* inputs collapse to 0.5 (neutral) so extractors that produce NaN
* / ±Infinity don't poison the picker's comparisons.
*/
function asImportance(value) {
if (typeof value !== 'number' || !Number.isFinite(value))
return 0.5;
if (value < 0)
return 0;
if (value > 1)
return 1;
return value;
}
exports.asImportance = asImportance;
/**
* Duck-typed guard — true iff `value` has the shape of a
* `NarrativeBeat`. Used by pipelines that handle mixed-payload stores
* (raw messages + beats) to route entries correctly.
*/
function isNarrativeBeat(value) {
if (!value || typeof value !== 'object')
return false;
const v = value;
return typeof v.summary === 'string' && typeof v.importance === 'number' && Array.isArray(v.refs);
}
exports.isNarrativeBeat = isNarrativeBeat;
//# sourceMappingURL=types.js.map