UNPKG

agentfootprint

Version:

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

97 lines • 4.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.traceCauseTools = exports.buildCauseTools = void 0; const tools_js_1 = require("../tools/tools.js"); const causeLimits_js_1 = require("./causeLimits.js"); const causeResponse_js_1 = require("./causeResponse.js"); const causeLoad_js_1 = require("./causeLoad.js"); const causeContext_js_1 = require("./causeContext.js"); const nodeId = { type: 'string', minLength: 1, maxLength: 2048, description: 'An opaque node ID returned by attention_list in THIS artifact scope, not an outer/inner stage ID.', }; const nodeQuestion = { type: 'object', properties: { nodeId }, required: ['nodeId'], additionalProperties: false, }; const CAUSE_OPERATIONS = { attention_list: { description: 'Find recorded abnormal nodes and proof IDs in this authorized graph, bounded and read-only. Start here; missing capture is unknown, never healthy.', inputSchema: { type: 'object', properties: { nodeIds: { type: 'array', items: nodeId, maxItems: 100 } }, additionalProperties: false, }, }, root_cause: { description: 'Explain one recorded node using public Foottrace cause analysis. Cite root/path/evidence IDs. Gaps mean not sure; alternatives are not proven roots. No provider internals are inferred.', inputSchema: nodeQuestion, }, impact: { description: 'Read the recorded forward impact of one node, with explicit gaps. Uses one bounded Foottrace query; it never reruns business work.', inputSchema: nodeQuestion, }, }; /** Model questions select IDs only. The host owns all resource controls. */ function buildCauseTools(artifacts, nodes, options) { return toolsForContext({ kind: 'snapshot', artifacts, nodes }, options); } exports.buildCauseTools = buildCauseTools; /** * Serve the three read-only cause questions over one host-authorized graph. * Saved evidence must be the exact object returned by `readStoredCauseArtifacts`; * copied display assessments do not grant saved-history authority. * No snapshot is indexed, no storage is fetched and no business work is rerun. */ function traceCauseTools(cause, options) { return toolsForContext({ kind: 'graph', cause }, options); } exports.traceCauseTools = traceCauseTools; function toolsForContext(context, options) { return Object.keys(CAUSE_OPERATIONS).map((operation) => (0, tools_js_1.defineTool)({ name: operation, ...CAUSE_OPERATIONS[operation], execute: async (question, execution) => { const assessed = (0, causeContext_js_1.causeContextAssessment)(context); if (assessed.kind === 'invalid') return (0, causeResponse_js_1.causeGap)(operation, 'invalid-data'); const capture = assessed.kind === 'stored' ? assessed.capture : context.kind === 'snapshot' && context.artifacts.cause === undefined ? true : undefined; const storage = assessed.kind === 'stored' ? assessed.admission.storage : undefined; if (execution.signal?.aborted && storage === undefined) return (0, causeResponse_js_1.causeGap)(operation, 'cancelled', capture); let limits; try { limits = (0, causeLimits_js_1.causeLimits)(options); } catch { return (0, causeResponse_js_1.causeGap)(operation, 'invalid-data', capture, storage, 512); } if (execution.signal?.aborted) return (0, causeResponse_js_1.causeGap)(operation, 'cancelled', capture, storage, limits.maxChars); const deadline = performance.now() + limits.timeoutMs; try { const loaded = await (0, causeLoad_js_1.loadCauseReader)(deadline, execution.signal); if ('gap' in loaded) return (0, causeResponse_js_1.causeGap)(operation, loaded.gap, capture, storage, limits.maxChars); return await loaded.reader.readCause(operation, context, question, limits, deadline, execution.signal); } catch { // Includes bounded loader refusals. Never echo an exception or disclose a private path. return (0, causeResponse_js_1.causeGap)(operation, execution.signal?.aborted ? 'cancelled' : performance.now() >= deadline ? 'timeout' : 'unavailable', capture, storage, limits.maxChars); } }, })); } //# sourceMappingURL=causeTools.js.map