agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
43 lines • 2.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.runRestorationProbe = void 0;
/**
* restoration — RFC-003 Part B: the causal tier for the missing-context finder
* (interface #3), the MIRROR of ablation (D8's restoration half).
*
* Ablation confirms a PRESENT culprit by removing it and watching the outcome
* flip. Restoration confirms an ABSENT culprit (a unit `findDroppedContext`
* surfaced) by adding it BACK and watching the outcome flip. Same seeded-rerun
* discipline, same verdict rule (`verdictFor(..., 'restoring')`), same honest
* baseline check — only the intervention is inverted.
*
* The re-run is consumer-owned (the library doesn't own your agent loop), just
* like `AblationRunner`. `RestorationRunner` receives the units to add back
* (`[]` = the un-restored baseline) plus a seed, and returns the run's output.
*/
const cosine_js_1 = require("../memory/embedding/cosine.js");
const ablation_js_1 = require("./ablation.js");
const types_js_1 = require("./types.js");
/**
* Run ONE restoration probe: call the consumer's runner with `units` restored
* once per seed, measure each output's similarity to the original, count flips.
* `[]` units = the un-restored baseline. Mirror of `runAblationProbe`.
*/
async function runRestorationProbe(config, units) {
const samples = (0, ablation_js_1.resolveSamples)(config.rerun.samples);
const flipThreshold = config.rerun.flipThreshold ?? types_js_1.CONTEXT_BISECT_DEFAULTS.flipThreshold;
const outcomeChanged = config.rerun.outcomeChanged ?? (0, ablation_js_1.defaultOutcomeComparator)(config.embedder, flipThreshold);
const similarities = [];
let flips = 0;
const originalVec = await config.embedder.embed({ text: config.rerun.originalOutput });
for (let seed = 0; seed < samples; seed++) {
const output = await config.rerun.runner(units, { seed });
const outputVec = await config.embedder.embed({ text: output });
similarities.push((0, cosine_js_1.cosineSimilarity)(originalVec, outputVec));
if (await outcomeChanged(config.rerun.originalOutput, output))
flips++;
}
return { samples, flips, similarity: (0, ablation_js_1.similarityStats)(similarities) };
}
exports.runRestorationProbe = runRestorationProbe;
//# sourceMappingURL=restoration.js.map