UNPKG

agentfootprint

Version:

The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.

74 lines • 2.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.causeLimits = exports.CAUSE_TOOL_CAPS = void 0; /** Tool ceilings are deliberately smaller than the reader's absolute ceilings. */ exports.CAUSE_TOOL_CAPS = Object.freeze({ maxNodes: 100, maxDepth: 20, maxEdges: 1000, maxCalls: 1000, timeoutMs: 5000, maxChars: 16000, }); const DEFAULTS = { maxNodes: 25, maxDepth: 6, maxEdges: 100, maxCalls: 100, timeoutMs: 1000, maxChars: 8000, }; const WORK_KEYS = ['maxNodes', 'maxDepth', 'maxEdges', 'maxCalls']; function data(object, key) { const descriptor = Object.getOwnPropertyDescriptor(object, key); if (descriptor === undefined) return undefined; if (!('value' in descriptor)) throw new TypeError('cause tools: invalid limits'); return descriptor.value; } function integer(value, fallback, minimum, maximum) { const chosen = value ?? fallback; if (typeof chosen !== 'number' || !Number.isSafeInteger(chosen) || chosen < minimum || chosen > maximum) { throw new TypeError('cause tools: invalid limits'); } return chosen; } function direction(value, total) { if (value === undefined) return undefined; if (value === null || typeof value !== 'object' || Array.isArray(value)) throw new TypeError(); if (Object.keys(value).some((key) => !WORK_KEYS.includes(key))) throw new TypeError(); const result = {}; for (const key of WORK_KEYS) { const field = data(value, key); if (field !== undefined) result[key] = integer(field, total[key], key === 'maxDepth' ? 0 : 1, total[key]); } return result; } /** Resolve host policy only. Model arguments never enter this resource boundary. */ function causeLimits(options = {}) { const resolved = { ...DEFAULTS }; for (const key of Object.keys(DEFAULTS)) { resolved[key] = integer(data(options, key), DEFAULTS[key], key === 'maxDepth' ? 0 : key === 'maxChars' ? 512 : 1, exports.CAUSE_TOOL_CAPS[key]); } const backward = { maxNodes: Math.max(1, Math.floor(resolved.maxNodes * 0.8)), maxEdges: Math.max(1, Math.floor(resolved.maxEdges * 0.8)), maxCalls: Math.max(1, Math.floor(resolved.maxCalls * 0.8)), ...direction(data(options, 'backward'), resolved), }; return { ...resolved, backward, impact: direction(data(options, 'impact'), resolved), }; } exports.causeLimits = causeLimits; //# sourceMappingURL=causeLimits.js.map