/** * AgentStepGraph — directed graph of agent activations for KVFlow-aware * KV cache management. * * Models the multi-agent workflow as a dependency graph where each node * is an agent activation (step) and edges represent scheduling dependencies. * The KVFlow cache manager uses graph topology to compute "steps-to-execution" * (STE) for eviction and prefetch decisions. * * @module @holoscript/llm-provider/kvflow * @version 0.1.0 */ import type { AgentStep, StepNodeId } from './types'; /** * In-memory AgentStepGraph implementation. Constructed from HoloMesh team * board data (active agents, roles, priorities) and updated as agents * activate/deactivate during the workflow lifecycle. * * Lifecycle: * 1. Build initial graph from team board (which agents are active, their * dependencies and priorities). * 2. As agents execute, update `lastActivatedAt` and `stepIndex`. * 3. When an agent session ends, remove its steps. * 4. The cache manager calls `computeStepsToExecution()` to drive eviction * and `nextScheduled()` to drive prefetch. */ export declare class InMemoryAgentStepGraph { private readonly steps; /** Reverse index: stepId → set of steps that depend on it (forward edges). */ private readonly dependents; addStep(step: AgentStep): void; removeStep(stepId: StepNodeId): void; getStep(stepId: StepNodeId): AgentStep | undefined; allSteps(): AgentStep[]; stepCount(): number; /** * Compute the "steps-to-execution" (STE) value for every node. * * KVFlow's core insight: eviction should be workflow-aware, not just * recency-based. An entry with STE=0 is currently executing; higher STE * means more steps before this agent runs again, making it a better * eviction candidate. * * Algorithm: * 1. Active steps get STE = 0 (they're executing now). * 2. For every other step, STE = length of the shortest path from any * active step through the dependency graph, using BFS. * 3. Steps unreachable from any active step get STE = max topological * position (fairness fallback — they'll be needed eventually). * 4. Shared-prefix scope entries get STE reduced by 1 (they're reused * by multiple agents, so they're effectively "closer" to execution). * Minimum STE for shared-prefix is 0 (never evict currently-active * shared prefixes). */ computeStepsToExecution(activeStepIds: StepNodeId[]): Map; /** * Get the next N agents scheduled to execute after the given step. * Uses BFS from the step's dependents to find agents in execution order. */ nextScheduled(stepId: StepNodeId, count: number): AgentStep[]; /** * Topological sort of the dependency graph. Used as fallback for * computing STE when no active steps exist. */ private topologicalSort; /** * Serialize to a plain object for persistence, debugging, or telemetry. */ toJSON(): { steps: AgentStep[]; }; /** * Reconstruct from a serialized graph. */ static fromJSON(data: { steps: AgentStep[]; }): InMemoryAgentStepGraph; }