agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
52 lines (51 loc) • 2.29 kB
TypeScript
/**
* @internal — not part of the public agentfootprint API. Imported only
* by RunStepRecorder. Subject to change without notice.
*
* RootInferrer — small state machine deciding whether a run's root is
* a single leaf primitive (Agent / LLMCall) or a composition (Sequence
* / Parallel / Conditional / Loop).
*
* Extracted from RunStepRecorder per Convention 1.
*
* Inputs: subflow entries (with their depth + parsed primitiveKind),
* fork events (depth 0 → Parallel root), decision events (depth 0 →
* Conditional root), loop events (depth 0 → Loop root).
*
* Output: query `kind()` for the inferred root. Returns `undefined`
* until a signal arrives.
*
* Inference rules:
* - Decisive composition signals (fork / decide / loop AT DEPTH 0)
* lock the root and are never overridden.
* - Shallowest primitive boundary IS a composition kind → root is
* that composition.
* - Two+ leaf siblings at the shallowest depth → implicit Sequence
* root (Sequence-as-runner case where the Sequence itself doesn't
* fire its own subflow.entry).
* - Single leaf at the shallowest depth → root is "leaf".
*/
export type InferredRoot = 'leaf' | 'sequence' | 'parallel' | 'conditional' | 'loop' | undefined;
export declare class RootInferrer {
private inferred;
private shallowestDepth;
private shallowestSiblings;
/** Currently-inferred root kind, or undefined if no signal yet. */
kind(): InferredRoot;
/** True when the root is a single leaf primitive (or unknown,
* which should be treated as leaf for kind-filter purposes). */
isLeafRoot(): boolean;
/** Observe a subflow entry. */
observeSubflowEntry(depth: number, primitiveKind: string | undefined): void;
/** Observe a fork event. Locks root to Parallel if at depth 0 and
* no decisive root has been inferred yet. */
observeFork(depth: number): void;
/** Observe a decision event. Locks root to Conditional if at depth 0
* and no decisive root has been inferred yet. */
observeDecision(depth: number): void;
/** Observe a loop event. Locks root to Loop if at depth 0 and no
* decisive root has been inferred yet. */
observeLoop(depth: number): void;
clear(): void;
private tryInfer;
}