agentfootprint 6.44.0 → 6.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ai-instructions/setup.sh +0 -0
- package/dist/core/agent/buildAgentChart.js +2 -1
- package/dist/core/agent/buildAgentChart.js.map +1 -1
- package/dist/core/agent/buildDynamicAgentChart.js +3 -1
- package/dist/core/agent/buildDynamicAgentChart.js.map +1 -1
- package/dist/core/agent/stages/pickEntry.js +3 -1
- package/dist/core/agent/stages/pickEntry.js.map +1 -1
- package/dist/esm/adapters/identity/agentcore.d.ts +100 -0
- package/dist/esm/adapters/llm/AnthropicProvider.d.ts +130 -0
- package/dist/esm/adapters/llm/BedrockProvider.d.ts +100 -0
- package/dist/esm/adapters/llm/BrowserAnthropicProvider.d.ts +41 -0
- package/dist/esm/adapters/llm/BrowserOpenAIProvider.d.ts +95 -0
- package/dist/esm/adapters/llm/MockProvider.d.ts +153 -0
- package/dist/esm/adapters/llm/OpenAIProvider.d.ts +220 -0
- package/dist/esm/adapters/llm/createProvider.d.ts +85 -0
- package/dist/esm/adapters/memory/agentcore.d.ts +146 -0
- package/dist/esm/adapters/memory/bedrockAgentMemory.d.ts +95 -0
- package/dist/esm/adapters/memory/redis.d.ts +127 -0
- package/dist/esm/adapters/observability/agentcore.d.ts +67 -0
- package/dist/esm/adapters/observability/audit.d.ts +254 -0
- package/dist/esm/adapters/observability/cloudwatch.d.ts +96 -0
- package/dist/esm/adapters/observability/otel.d.ts +237 -0
- package/dist/esm/adapters/observability/xray.d.ts +88 -0
- package/dist/esm/adapters/types.d.ts +378 -0
- package/dist/esm/bridge/eventMeta.d.ts +59 -0
- package/dist/esm/cache/CacheDecisionSubflow.d.ts +85 -0
- package/dist/esm/cache/CacheGateDecider.d.ts +127 -0
- package/dist/esm/cache/applyCachePolicy.d.ts +37 -0
- package/dist/esm/cache/cacheRecorder.d.ts +85 -0
- package/dist/esm/cache/index.d.ts +33 -0
- package/dist/esm/cache/strategies/AnthropicCacheStrategy.d.ts +38 -0
- package/dist/esm/cache/strategies/BedrockCacheStrategy.d.ts +33 -0
- package/dist/esm/cache/strategies/NoOpCacheStrategy.d.ts +29 -0
- package/dist/esm/cache/strategies/OpenAICacheStrategy.d.ts +36 -0
- package/dist/esm/cache/strategyRegistry.d.ts +45 -0
- package/dist/esm/cache/types.d.ts +243 -0
- package/dist/esm/conventions.d.ts +203 -0
- package/dist/esm/core/Agent.d.ts +355 -0
- package/dist/esm/core/LLMCall.d.ts +139 -0
- package/dist/esm/core/RunnerBase.d.ts +267 -0
- package/dist/esm/core/agent/AgentBuilder.d.ts +565 -0
- package/dist/esm/core/agent/buildAgentChart.d.ts +109 -0
- package/dist/esm/core/agent/buildAgentChart.js +2 -1
- package/dist/esm/core/agent/buildAgentChart.js.map +1 -1
- package/dist/esm/core/agent/buildAgentMessageApiChart.d.ts +40 -0
- package/dist/esm/core/agent/buildCacheSubflow.d.ts +35 -0
- package/dist/esm/core/agent/buildDynamicAgentChart.d.ts +56 -0
- package/dist/esm/core/agent/buildDynamicAgentChart.js +3 -1
- package/dist/esm/core/agent/buildDynamicAgentChart.js.map +1 -1
- package/dist/esm/core/agent/buildMessageApiChart.d.ts +47 -0
- package/dist/esm/core/agent/buildToolRegistry.d.ts +61 -0
- package/dist/esm/core/agent/memoryRecallInjections.d.ts +8 -0
- package/dist/esm/core/agent/stages/breakFinal.d.ts +22 -0
- package/dist/esm/core/agent/stages/callLLM.d.ts +74 -0
- package/dist/esm/core/agent/stages/pickEntry.d.ts +19 -0
- package/dist/esm/core/agent/stages/pickEntry.js +3 -1
- package/dist/esm/core/agent/stages/pickEntry.js.map +1 -1
- package/dist/esm/core/agent/stages/prepareFinal.d.ts +19 -0
- package/dist/esm/core/agent/stages/reliabilityExecution.d.ts +135 -0
- package/dist/esm/core/agent/stages/route.d.ts +18 -0
- package/dist/esm/core/agent/stages/seed.d.ts +53 -0
- package/dist/esm/core/agent/stages/toolCalls.d.ts +76 -0
- package/dist/esm/core/agent/toolArgsValidation.d.ts +62 -0
- package/dist/esm/core/agent/types.d.ts +382 -0
- package/dist/esm/core/agent/validators.d.ts +52 -0
- package/dist/esm/core/cost.d.ts +38 -0
- package/dist/esm/core/flowchartAsTool.d.ts +200 -0
- package/dist/esm/core/humanizeLLMError.d.ts +23 -0
- package/dist/esm/core/outputFallback.d.ts +139 -0
- package/dist/esm/core/outputSchema.d.ts +127 -0
- package/dist/esm/core/pause.d.ts +74 -0
- package/dist/esm/core/runCheckpoint.d.ts +179 -0
- package/dist/esm/core/runner.d.ts +203 -0
- package/dist/esm/core/slots/buildMessagesSlot.d.ts +40 -0
- package/dist/esm/core/slots/buildSystemPromptSlot.d.ts +41 -0
- package/dist/esm/core/slots/buildThinkingSubflow.d.ts +40 -0
- package/dist/esm/core/slots/buildToolsSlot.d.ts +60 -0
- package/dist/esm/core/slots/helpers.d.ts +27 -0
- package/dist/esm/core/toolContract.d.ts +43 -0
- package/dist/esm/core/tools.d.ts +90 -0
- package/dist/esm/core/translator.d.ts +94 -0
- package/dist/esm/core-flow/Conditional.d.ts +119 -0
- package/dist/esm/core-flow/Loop.d.ts +160 -0
- package/dist/esm/core-flow/Parallel.d.ts +360 -0
- package/dist/esm/core-flow/Sequence.d.ts +133 -0
- package/dist/esm/events/dispatcher.d.ts +134 -0
- package/dist/esm/events/payloads.d.ts +761 -0
- package/dist/esm/events/registry.d.ts +198 -0
- package/dist/esm/events/types.d.ts +70 -0
- package/dist/esm/identity/kinds.d.ts +36 -0
- package/dist/esm/identity/staticTokens.d.ts +28 -0
- package/dist/esm/identity/types.d.ts +113 -0
- package/dist/esm/identity/withCredentialRetry.d.ts +64 -0
- package/dist/esm/identity.d.ts +31 -0
- package/dist/esm/index.d.ts +64 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/injection-engine.d.ts +4 -0
- package/dist/esm/lib/canonicalJson.d.ts +56 -0
- package/dist/esm/lib/context-bisect/ablation.d.ts +109 -0
- package/dist/esm/lib/context-bisect/bisect.d.ts +75 -0
- package/dist/esm/lib/context-bisect/cost.d.ts +37 -0
- package/dist/esm/lib/context-bisect/index.d.ts +31 -0
- package/dist/esm/lib/context-bisect/index.js +3 -0
- package/dist/esm/lib/context-bisect/index.js.map +1 -1
- package/dist/esm/lib/context-bisect/llmEdgeWeigher.d.ts +124 -0
- package/dist/esm/lib/context-bisect/localize.d.ts +152 -0
- package/dist/esm/lib/context-bisect/localize.js +2 -0
- package/dist/esm/lib/context-bisect/localize.js.map +1 -1
- package/dist/esm/lib/context-bisect/loop-recall.d.ts +97 -0
- package/dist/esm/lib/context-bisect/missingContext.d.ts +71 -0
- package/dist/esm/lib/context-bisect/restoration.d.ts +39 -0
- package/dist/esm/lib/context-bisect/toBacktrackTrace.d.ts +138 -0
- package/dist/esm/lib/context-bisect/trajectory.d.ts +168 -0
- package/dist/esm/lib/context-bisect/types.d.ts +448 -0
- package/dist/esm/lib/context-bisect/walk-to-root.d.ts +103 -0
- package/dist/esm/lib/influence-core/attributability.d.ts +72 -0
- package/dist/esm/lib/influence-core/cache.d.ts +94 -0
- package/dist/esm/lib/influence-core/contrastive.d.ts +26 -0
- package/dist/esm/lib/influence-core/index.d.ts +34 -0
- package/dist/esm/lib/influence-core/margin.d.ts +33 -0
- package/dist/esm/lib/influence-core/signals.d.ts +128 -0
- package/dist/esm/lib/influence-core/similarity.d.ts +25 -0
- package/dist/esm/lib/influence-core/types.d.ts +252 -0
- package/dist/esm/lib/injection-engine/SkillRegistry.d.ts +147 -0
- package/dist/esm/lib/injection-engine/buildInjectionEngineSubflow.d.ts +110 -0
- package/dist/esm/lib/injection-engine/buildInjectionEngineSubflow.js +1 -0
- package/dist/esm/lib/injection-engine/buildInjectionEngineSubflow.js.map +1 -1
- package/dist/esm/lib/injection-engine/entryScorer.d.ts +93 -0
- package/dist/esm/lib/injection-engine/entryScorer.js +172 -0
- package/dist/esm/lib/injection-engine/entryScorer.js.map +1 -0
- package/dist/esm/lib/injection-engine/evaluator.d.ts +24 -0
- package/dist/esm/lib/injection-engine/factories/defineFact.d.ts +60 -0
- package/dist/esm/lib/injection-engine/factories/defineInjection.d.ts +41 -0
- package/dist/esm/lib/injection-engine/factories/defineInstruction.d.ts +78 -0
- package/dist/esm/lib/injection-engine/factories/defineRelevanceHint.d.ts +26 -0
- package/dist/esm/lib/injection-engine/factories/defineSkill.d.ts +160 -0
- package/dist/esm/lib/injection-engine/factories/defineSteering.d.ts +39 -0
- package/dist/esm/lib/injection-engine/index.d.ts +22 -0
- package/dist/esm/lib/injection-engine/index.js +1 -0
- package/dist/esm/lib/injection-engine/index.js.map +1 -1
- package/dist/esm/lib/injection-engine/skillContract.d.ts +29 -0
- package/dist/esm/lib/injection-engine/skillGraph.d.ts +289 -0
- package/dist/esm/lib/injection-engine/skillGraph.js +35 -41
- package/dist/esm/lib/injection-engine/skillGraph.js.map +1 -1
- package/dist/esm/lib/injection-engine/skillGraphCheckup.d.ts +49 -0
- package/dist/esm/lib/injection-engine/skillTools.d.ts +72 -0
- package/dist/esm/lib/injection-engine/softmax.d.ts +11 -0
- package/dist/esm/lib/injection-engine/types.d.ts +229 -0
- package/dist/esm/lib/injection-engine/types.js.map +1 -1
- package/dist/esm/lib/lazyRequire.d.ts +29 -0
- package/dist/esm/lib/mcp/index.d.ts +9 -0
- package/dist/esm/lib/mcp/mcpClient.d.ts +46 -0
- package/dist/esm/lib/mcp/mockMcpClient.d.ts +65 -0
- package/dist/esm/lib/mcp/types.d.ts +133 -0
- package/dist/esm/lib/rag/defineRAG.d.ts +139 -0
- package/dist/esm/lib/rag/index.d.ts +7 -0
- package/dist/esm/lib/rag/indexDocuments.d.ts +105 -0
- package/dist/esm/lib/tool-lint/analyze.d.ts +83 -0
- package/dist/esm/lib/tool-lint/cli.d.ts +43 -0
- package/dist/esm/lib/tool-lint/format.d.ts +18 -0
- package/dist/esm/lib/tool-lint/index.d.ts +23 -0
- package/dist/esm/lib/tool-lint/rules.d.ts +85 -0
- package/dist/esm/lib/tool-lint/types.d.ts +155 -0
- package/dist/esm/lib/trace-toolpack/bounded.d.ts +47 -0
- package/dist/esm/lib/trace-toolpack/debugPrompt.d.ts +19 -0
- package/dist/esm/lib/trace-toolpack/index.d.ts +20 -0
- package/dist/esm/lib/trace-toolpack/lazyToolpack.d.ts +35 -0
- package/dist/esm/lib/trace-toolpack/selfExplain.d.ts +100 -0
- package/dist/esm/lib/trace-toolpack/traceDebugAgent.d.ts +42 -0
- package/dist/esm/lib/trace-toolpack/traceToolpack.d.ts +69 -0
- package/dist/esm/lib/trace-toolpack/types.d.ts +59 -0
- package/dist/esm/llm-providers.d.ts +26 -0
- package/dist/esm/locales/index.d.ts +132 -0
- package/dist/esm/memory/beats/extractBeats.d.ts +61 -0
- package/dist/esm/memory/beats/extractor.d.ts +47 -0
- package/dist/esm/memory/beats/formatAsNarrative.d.ts +62 -0
- package/dist/esm/memory/beats/heuristicExtractor.d.ts +37 -0
- package/dist/esm/memory/beats/index.d.ts +12 -0
- package/dist/esm/memory/beats/llmExtractor.d.ts +56 -0
- package/dist/esm/memory/beats/types.d.ts +60 -0
- package/dist/esm/memory/beats/writeBeats.d.ts +22 -0
- package/dist/esm/memory/causal/evidenceRecorder.d.ts +66 -0
- package/dist/esm/memory/causal/index.d.ts +6 -0
- package/dist/esm/memory/causal/loadSnapshot.d.ts +51 -0
- package/dist/esm/memory/causal/snapshotPipeline.d.ts +35 -0
- package/dist/esm/memory/causal/types.d.ts +130 -0
- package/dist/esm/memory/causal/writeSnapshot.d.ts +73 -0
- package/dist/esm/memory/define.d.ts +63 -0
- package/dist/esm/memory/define.types.d.ts +276 -0
- package/dist/esm/memory/define.types.js +1 -1
- package/dist/esm/memory/embedding/cosine.d.ts +18 -0
- package/dist/esm/memory/embedding/embedMessages.d.ts +58 -0
- package/dist/esm/memory/embedding/index.d.ts +8 -0
- package/dist/esm/memory/embedding/loadRelevant.d.ts +51 -0
- package/dist/esm/memory/embedding/mockEmbedder.d.ts +22 -0
- package/dist/esm/memory/embedding/types.d.ts +46 -0
- package/dist/esm/memory/entry/decay.d.ts +36 -0
- package/dist/esm/memory/entry/index.d.ts +2 -0
- package/dist/esm/memory/entry/types.d.ts +140 -0
- package/dist/esm/memory/facts/extractFacts.d.ts +50 -0
- package/dist/esm/memory/facts/extractor.d.ts +33 -0
- package/dist/esm/memory/facts/formatFacts.d.ts +60 -0
- package/dist/esm/memory/facts/index.d.ts +14 -0
- package/dist/esm/memory/facts/llmFactExtractor.d.ts +64 -0
- package/dist/esm/memory/facts/loadFacts.d.ts +43 -0
- package/dist/esm/memory/facts/patternFactExtractor.d.ts +2 -0
- package/dist/esm/memory/facts/types.d.ts +68 -0
- package/dist/esm/memory/facts/writeFacts.d.ts +19 -0
- package/dist/esm/memory/identity/index.d.ts +2 -0
- package/dist/esm/memory/identity/types.d.ts +49 -0
- package/dist/esm/memory/index.d.ts +19 -0
- package/dist/esm/memory/pipeline/auto.d.ts +59 -0
- package/dist/esm/memory/pipeline/default.d.ts +49 -0
- package/dist/esm/memory/pipeline/ephemeral.d.ts +28 -0
- package/dist/esm/memory/pipeline/fact.d.ts +26 -0
- package/dist/esm/memory/pipeline/index.d.ts +13 -0
- package/dist/esm/memory/pipeline/narrative.d.ts +35 -0
- package/dist/esm/memory/pipeline/semantic.d.ts +37 -0
- package/dist/esm/memory/pipeline/types.d.ts +31 -0
- package/dist/esm/memory/stages/formatDefault.d.ts +64 -0
- package/dist/esm/memory/stages/index.d.ts +13 -0
- package/dist/esm/memory/stages/loadRecent.d.ts +49 -0
- package/dist/esm/memory/stages/pickByBudget.d.ts +63 -0
- package/dist/esm/memory/stages/summarize.d.ts +87 -0
- package/dist/esm/memory/stages/tokenize.d.ts +43 -0
- package/dist/esm/memory/stages/types.d.ts +75 -0
- package/dist/esm/memory/stages/writeMessages.d.ts +71 -0
- package/dist/esm/memory/store/InMemoryStore.d.ts +62 -0
- package/dist/esm/memory/store/index.d.ts +2 -0
- package/dist/esm/memory/store/types.d.ts +223 -0
- package/dist/esm/memory/wire/index.d.ts +2 -0
- package/dist/esm/memory/wire/mountMemoryPipeline.d.ts +108 -0
- package/dist/esm/memory-providers.d.ts +37 -0
- package/dist/esm/observability/contextError/finders/compareFinders.d.ts +19 -0
- package/dist/esm/observability/contextError/finders/index.d.ts +22 -0
- package/dist/esm/observability/contextError/finders/rankSuspects.d.ts +2 -0
- package/dist/esm/observability/contextError/finders/removeAndRetry.d.ts +11 -0
- package/dist/esm/observability/contextError/finders/shrinkToCause.d.ts +11 -0
- package/dist/esm/observability/contextError/finders/testManyCombos.d.ts +11 -0
- package/dist/esm/observability/contextError/finders/traceSteps.d.ts +2 -0
- package/dist/esm/observability/contextError/finders/types.d.ts +88 -0
- package/dist/esm/observability-providers.d.ts +46 -0
- package/dist/esm/observe.d.ts +62 -0
- package/dist/esm/patterns/Debate.d.ts +39 -0
- package/dist/esm/patterns/MapReduce.d.ts +66 -0
- package/dist/esm/patterns/Reflection.d.ts +51 -0
- package/dist/esm/patterns/SelfConsistency.d.ts +43 -0
- package/dist/esm/patterns/Swarm.d.ts +60 -0
- package/dist/esm/patterns/ToT.d.ts +53 -0
- package/dist/esm/patterns/index.d.ts +22 -0
- package/dist/esm/providers.d.ts +33 -0
- package/dist/esm/recorders/core/AgentRecorder.d.ts +15 -0
- package/dist/esm/recorders/core/CompositionRecorder.d.ts +17 -0
- package/dist/esm/recorders/core/ContextEvaluatedRecorder.d.ts +23 -0
- package/dist/esm/recorders/core/ContextRecorder.d.ts +47 -0
- package/dist/esm/recorders/core/CostRecorder.d.ts +14 -0
- package/dist/esm/recorders/core/EmitBridge.d.ts +30 -0
- package/dist/esm/recorders/core/ErrorBridge.d.ts +38 -0
- package/dist/esm/recorders/core/EvalRecorder.d.ts +16 -0
- package/dist/esm/recorders/core/MemoryRecorder.d.ts +17 -0
- package/dist/esm/recorders/core/PermissionRecorder.d.ts +16 -0
- package/dist/esm/recorders/core/ReliabilityRecorder.d.ts +24 -0
- package/dist/esm/recorders/core/SkillRecorder.d.ts +14 -0
- package/dist/esm/recorders/core/StreamRecorder.d.ts +15 -0
- package/dist/esm/recorders/core/ToolsRecorder.d.ts +18 -0
- package/dist/esm/recorders/core/ValidationRecorder.d.ts +16 -0
- package/dist/esm/recorders/core/contextEngineering.d.ts +136 -0
- package/dist/esm/recorders/core/typedEmit.d.ts +34 -0
- package/dist/esm/recorders/core/types.d.ts +97 -0
- package/dist/esm/recorders/observability/AgentThinkingTraceRecorder.d.ts +117 -0
- package/dist/esm/recorders/observability/BoundaryRecorder.d.ts +546 -0
- package/dist/esm/recorders/observability/FlowchartRecorder.d.ts +220 -0
- package/dist/esm/recorders/observability/LiveStateRecorder.d.ts +250 -0
- package/dist/esm/recorders/observability/LoggingRecorder.d.ts +91 -0
- package/dist/esm/recorders/observability/RouteRecorder.d.ts +83 -0
- package/dist/esm/recorders/observability/RunStepRecorder.d.ts +231 -0
- package/dist/esm/recorders/observability/StatusRecorder.d.ts +36 -0
- package/dist/esm/recorders/observability/ToolChoiceRecorder.d.ts +164 -0
- package/dist/esm/recorders/observability/ToolLineageRecorder.d.ts +71 -0
- package/dist/esm/recorders/observability/commentary/commentaryTemplates.d.ts +105 -0
- package/dist/esm/recorders/observability/internal/ActorArrowClassifier.d.ts +25 -0
- package/dist/esm/recorders/observability/internal/CandidateAnswerBuffer.d.ts +28 -0
- package/dist/esm/recorders/observability/internal/ForkTracker.d.ts +60 -0
- package/dist/esm/recorders/observability/internal/RootInferrer.d.ts +51 -0
- package/dist/esm/recorders/observability/internal/SequenceSiblingTracker.d.ts +24 -0
- package/dist/esm/recorders/observability/localObservability.d.ts +48 -0
- package/dist/esm/recorders/observability/observeRunId.d.ts +36 -0
- package/dist/esm/recorders/observability/status/statusTemplates.d.ts +106 -0
- package/dist/esm/recorders/observability/trace.d.ts +119 -0
- package/dist/esm/reliability/CircuitBreaker.d.ts +75 -0
- package/dist/esm/reliability/buildReliabilityGateChart.d.ts +53 -0
- package/dist/esm/reliability/classifyError.d.ts +28 -0
- package/dist/esm/reliability/index.d.ts +35 -0
- package/dist/esm/reliability/types.d.ts +327 -0
- package/dist/esm/resilience/fallbackProvider.d.ts +33 -0
- package/dist/esm/resilience/index.d.ts +21 -0
- package/dist/esm/resilience/withCircuitBreaker.d.ts +129 -0
- package/dist/esm/resilience/withFallback.d.ts +45 -0
- package/dist/esm/resilience/withRetry.d.ts +71 -0
- package/dist/esm/security/PermissionPolicy.d.ts +124 -0
- package/dist/esm/security/PolicyHaltError.d.ts +72 -0
- package/dist/esm/security/extractSequence.d.ts +46 -0
- package/dist/esm/security/index.d.ts +44 -0
- package/dist/esm/security/thinkingRedaction.d.ts +50 -0
- package/dist/esm/status.d.ts +48 -0
- package/dist/esm/strategies/attach.d.ts +47 -0
- package/dist/esm/strategies/compose.d.ts +48 -0
- package/dist/esm/strategies/defaults/chatBubbleLiveStatus.d.ts +36 -0
- package/dist/esm/strategies/defaults/consoleObservability.d.ts +42 -0
- package/dist/esm/strategies/defaults/inMemorySinkCost.d.ts +50 -0
- package/dist/esm/strategies/defaults/index.d.ts +30 -0
- package/dist/esm/strategies/defaults/noopLens.d.ts +28 -0
- package/dist/esm/strategies/index.d.ts +36 -0
- package/dist/esm/strategies/registry.d.ts +70 -0
- package/dist/esm/strategies/types.d.ts +303 -0
- package/dist/esm/stream.d.ts +82 -0
- package/dist/esm/thinking/AnthropicThinkingHandler.d.ts +42 -0
- package/dist/esm/thinking/MockThinkingHandler.d.ts +50 -0
- package/dist/esm/thinking/OpenAIThinkingHandler.d.ts +37 -0
- package/dist/esm/thinking/index.d.ts +51 -0
- package/dist/esm/thinking/registry.d.ts +33 -0
- package/dist/esm/thinking/types.d.ts +162 -0
- package/dist/esm/tool-providers/gatedTools.d.ts +36 -0
- package/dist/esm/tool-providers/index.d.ts +41 -0
- package/dist/esm/tool-providers/skillScopedTools.d.ts +45 -0
- package/dist/esm/tool-providers/staticTools.d.ts +21 -0
- package/dist/esm/tool-providers/types.d.ts +138 -0
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/context-bisect/index.js +3 -0
- package/dist/lib/context-bisect/index.js.map +1 -1
- package/dist/lib/context-bisect/localize.js +2 -0
- package/dist/lib/context-bisect/localize.js.map +1 -1
- package/dist/lib/injection-engine/buildInjectionEngineSubflow.js +1 -0
- package/dist/lib/injection-engine/buildInjectionEngineSubflow.js.map +1 -1
- package/dist/lib/injection-engine/entryScorer.js +178 -0
- package/dist/lib/injection-engine/entryScorer.js.map +1 -0
- package/dist/lib/injection-engine/index.js +5 -1
- package/dist/lib/injection-engine/index.js.map +1 -1
- package/dist/lib/injection-engine/skillGraph.js +35 -41
- package/dist/lib/injection-engine/skillGraph.js.map +1 -1
- package/dist/lib/injection-engine/types.js.map +1 -1
- package/dist/memory/define.types.js +1 -1
- package/dist/types/core/agent/buildAgentChart.d.ts.map +1 -1
- package/dist/types/core/agent/buildDynamicAgentChart.d.ts.map +1 -1
- package/dist/types/core/agent/stages/pickEntry.d.ts.map +1 -1
- package/dist/types/core/agent/types.d.ts +8 -4
- package/dist/types/core/agent/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/context-bisect/index.d.ts +3 -0
- package/dist/types/lib/context-bisect/index.d.ts.map +1 -1
- package/dist/types/lib/context-bisect/localize.d.ts +2 -0
- package/dist/types/lib/context-bisect/localize.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/buildInjectionEngineSubflow.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/entryScorer.d.ts +94 -0
- package/dist/types/lib/injection-engine/entryScorer.d.ts.map +1 -0
- package/dist/types/lib/injection-engine/index.d.ts +1 -0
- package/dist/types/lib/injection-engine/index.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/skillGraph.d.ts +21 -24
- package/dist/types/lib/injection-engine/skillGraph.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/types.d.ts +9 -4
- package/dist/types/lib/injection-engine/types.d.ts.map +1 -1
- package/dist/types/memory/define.types.d.ts +1 -1
- package/package.json +203 -56
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* applyCachePolicy — internal helper for injection factories.
|
|
3
|
+
*
|
|
4
|
+
* Each factory (`defineSkill`, `defineSteering`, `defineFact`,
|
|
5
|
+
* `defineInstruction`, `defineMemory`) calls this to merge the
|
|
6
|
+
* consumer-supplied `cache` option with the flavor-specific default.
|
|
7
|
+
* The merged policy lands in `Injection.metadata.cache` for the
|
|
8
|
+
* CacheDecision subflow (Phase 4) to read back.
|
|
9
|
+
*
|
|
10
|
+
* Why it lives in src/cache/ (not co-located with each factory):
|
|
11
|
+
* - Single source of truth for per-flavor defaults
|
|
12
|
+
* - Tests for the defaults live in one place (test/cache/)
|
|
13
|
+
* - Adding a new factory means adding one entry to the map below;
|
|
14
|
+
* not duplicating the default-resolution logic five times
|
|
15
|
+
*/
|
|
16
|
+
import type { CachePolicy } from './types.js';
|
|
17
|
+
/**
|
|
18
|
+
* Per-flavor default `cache` values when consumer doesn't specify.
|
|
19
|
+
* These match the documentation in `CachePolicy`'s JSDoc — keep
|
|
20
|
+
* synchronized.
|
|
21
|
+
*/
|
|
22
|
+
declare const FLAVOR_DEFAULTS: Readonly<Record<string, CachePolicy>>;
|
|
23
|
+
/**
|
|
24
|
+
* Resolve the effective `cache` policy for an injection.
|
|
25
|
+
*
|
|
26
|
+
* @param flavor - The injection flavor (drives the default if `consumerValue` undefined)
|
|
27
|
+
* @param consumerValue - What the consumer wrote in `cache:` (or undefined)
|
|
28
|
+
* @returns The effective CachePolicy. Always defined.
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolveCachePolicy(flavor: keyof typeof FLAVOR_DEFAULTS | string, consumerValue: CachePolicy | undefined): CachePolicy;
|
|
31
|
+
/**
|
|
32
|
+
* Read-only access to the per-flavor default table. Exported for
|
|
33
|
+
* tests asserting the documented defaults are wired correctly. Not
|
|
34
|
+
* intended for runtime use — callers should use `resolveCachePolicy`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function getFlavorDefault(flavor: string): CachePolicy;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cacheRecorder() — observability for the v2.6 cache layer.
|
|
3
|
+
*
|
|
4
|
+
* Subscribes to:
|
|
5
|
+
* - `FlowRecorder.onDecision` — captures CacheGate routing decisions
|
|
6
|
+
* (apply-markers / no-markers + the rule that fired + evidence
|
|
7
|
+
* from `decide()`). Read directly from `event.evidence.rules[matched]`
|
|
8
|
+
* since footprintjs already auto-captures predicate `inputs[]`.
|
|
9
|
+
* - `agentfootprint.stream.llm_end` events — read provider's `usage`
|
|
10
|
+
* and call the agent's CacheStrategy.extractMetrics() to normalize
|
|
11
|
+
* into CacheMetrics (cacheReadTokens / cacheWriteTokens / fresh).
|
|
12
|
+
*
|
|
13
|
+
* Produces:
|
|
14
|
+
* - per-iteration `agentfootprint.cache.applied` events (markers
|
|
15
|
+
* applied this iter or empty if skipped) — for Lens trace
|
|
16
|
+
* - per-iteration `agentfootprint.cache.metrics` events (hit/write
|
|
17
|
+
* token counts + estimated dollars via PricingTable) — for
|
|
18
|
+
* dashboards
|
|
19
|
+
* - a turn-end summary printable via `recorder.report()` —
|
|
20
|
+
* numeric tally plus dollars saved
|
|
21
|
+
*
|
|
22
|
+
* v2.6 LIMITATION: doesn't yet write `scope.recentHitRate` back into
|
|
23
|
+
* agent state. CacheGate's hit-rate-floor rule won't fire automatically;
|
|
24
|
+
* consumers can manually wire feedback via `Agent.create(...).attach(rec)`.
|
|
25
|
+
* Full feedback loop deferred to v2.7 (needs an agent-side accessor
|
|
26
|
+
* convention since recorders don't normally write to scope).
|
|
27
|
+
*/
|
|
28
|
+
import type { CombinedRecorder } from 'footprintjs';
|
|
29
|
+
import type { CacheMetrics, CacheStrategy } from './types.js';
|
|
30
|
+
import type { PricingTable } from '../adapters/types.js';
|
|
31
|
+
interface PerIterEntry {
|
|
32
|
+
readonly iteration: number;
|
|
33
|
+
readonly branch: 'apply-markers' | 'no-markers';
|
|
34
|
+
readonly rule?: string;
|
|
35
|
+
readonly metrics?: CacheMetrics;
|
|
36
|
+
readonly dollarsSpent: number;
|
|
37
|
+
readonly dollarsSavedVsNoCache: number;
|
|
38
|
+
}
|
|
39
|
+
interface CacheReportSummary {
|
|
40
|
+
readonly totalIterations: number;
|
|
41
|
+
readonly applyMarkersIterations: number;
|
|
42
|
+
readonly noMarkersIterations: number;
|
|
43
|
+
readonly cacheReadTokensTotal: number;
|
|
44
|
+
readonly cacheWriteTokensTotal: number;
|
|
45
|
+
readonly freshInputTokensTotal: number;
|
|
46
|
+
readonly hitRate: number;
|
|
47
|
+
readonly estimatedDollarsSpent: number;
|
|
48
|
+
readonly estimatedDollarsSavedVsNoCache: number;
|
|
49
|
+
readonly perIter: readonly PerIterEntry[];
|
|
50
|
+
}
|
|
51
|
+
export interface CacheRecorderOptions {
|
|
52
|
+
/**
|
|
53
|
+
* The agent's CacheStrategy. Required for `extractMetrics` —
|
|
54
|
+
* normalizes provider-specific `usage` shapes into CacheMetrics.
|
|
55
|
+
* If not provided, recorder logs the raw usage and skips dollar math.
|
|
56
|
+
*/
|
|
57
|
+
readonly strategy?: CacheStrategy;
|
|
58
|
+
/**
|
|
59
|
+
* PricingTable for dollar estimates. Falls back to token-count-only
|
|
60
|
+
* reporting when omitted. Looks up `'input'` / `'cacheRead'` /
|
|
61
|
+
* `'cacheWrite'` token kinds (PricingTable already supports these
|
|
62
|
+
* as of v2.5).
|
|
63
|
+
*/
|
|
64
|
+
readonly pricing?: PricingTable;
|
|
65
|
+
/**
|
|
66
|
+
* Model id for pricing lookup. Defaults to a placeholder; set to
|
|
67
|
+
* the actual model the agent is using for accurate dollar math.
|
|
68
|
+
*/
|
|
69
|
+
readonly model?: string;
|
|
70
|
+
}
|
|
71
|
+
export interface CacheRecorderHandle extends CombinedRecorder {
|
|
72
|
+
/**
|
|
73
|
+
* Build a per-turn report. Call after `agent.run()` completes.
|
|
74
|
+
* Returns a frozen snapshot — recorder keeps accumulating but the
|
|
75
|
+
* report you held is stable.
|
|
76
|
+
*/
|
|
77
|
+
report(): CacheReportSummary;
|
|
78
|
+
/**
|
|
79
|
+
* Reset accumulated state. Call between turns if you want
|
|
80
|
+
* per-turn rather than per-session reporting.
|
|
81
|
+
*/
|
|
82
|
+
reset(): void;
|
|
83
|
+
}
|
|
84
|
+
export declare function cacheRecorder(options?: CacheRecorderOptions): CacheRecorderHandle;
|
|
85
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agentfootprint/cache — public surface for the cache layer (v2.6+).
|
|
3
|
+
*
|
|
4
|
+
* Importing this module side-effect-registers every built-in cache
|
|
5
|
+
* strategy in the registry. The agentfootprint main barrel imports
|
|
6
|
+
* from here so consumers get the registered strategies without
|
|
7
|
+
* needing to know they exist.
|
|
8
|
+
*
|
|
9
|
+
* Strategies registered as of v2.6:
|
|
10
|
+
* - NoOp (wildcard '*' fallback) — always available, registered by
|
|
11
|
+
* the registry module itself
|
|
12
|
+
* - AnthropicCacheStrategy ('anthropic', 'browser-anthropic')
|
|
13
|
+
*
|
|
14
|
+
* Future strategies (Phase 8+):
|
|
15
|
+
* - OpenAICacheStrategy
|
|
16
|
+
* - BedrockCacheStrategy
|
|
17
|
+
* - GeminiCacheStrategy (v2.7+, async handle-based)
|
|
18
|
+
*
|
|
19
|
+
* Public types (re-exported for consumers):
|
|
20
|
+
* - CachePolicy, CacheMarker, CacheStrategy, CacheCapabilities,
|
|
21
|
+
* CacheMetrics, CachePolicyContext, CacheStrategyContext
|
|
22
|
+
*/
|
|
23
|
+
import './strategies/AnthropicCacheStrategy.js';
|
|
24
|
+
import './strategies/OpenAICacheStrategy.js';
|
|
25
|
+
import './strategies/BedrockCacheStrategy.js';
|
|
26
|
+
export type { CachePolicy, CachePolicyContext, CacheMarker, CacheStrategy, CacheStrategyContext, CacheCapabilities, CacheMetrics, } from './types.js';
|
|
27
|
+
export { getDefaultCacheStrategy, registerCacheStrategy, listRegisteredStrategies, } from './strategyRegistry.js';
|
|
28
|
+
export { NoOpCacheStrategy } from './strategies/NoOpCacheStrategy.js';
|
|
29
|
+
export { AnthropicCacheStrategy } from './strategies/AnthropicCacheStrategy.js';
|
|
30
|
+
export { OpenAICacheStrategy } from './strategies/OpenAICacheStrategy.js';
|
|
31
|
+
export { BedrockCacheStrategy } from './strategies/BedrockCacheStrategy.js';
|
|
32
|
+
export { cacheRecorder } from './cacheRecorder.js';
|
|
33
|
+
export type { CacheRecorderOptions, CacheRecorderHandle } from './cacheRecorder.js';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AnthropicCacheStrategy — translates agnostic CacheMarker[] to
|
|
3
|
+
* Anthropic API's `cache_control: { type: 'ephemeral' }` markers.
|
|
4
|
+
*
|
|
5
|
+
* Anthropic-specific behaviors honored:
|
|
6
|
+
* - **4-marker limit**: Anthropic allows ≤4 cache breakpoints per
|
|
7
|
+
* request. Strategy clamps oversize candidate sets, keeping the
|
|
8
|
+
* first 4 in slot order.
|
|
9
|
+
* - **TTL mapping**: 'short' → default 5min ephemeral; 'long' →
|
|
10
|
+
* `ttl: '1h'` (1-hour beta).
|
|
11
|
+
* - **Provider-side hashing**: this strategy doesn't hash — Anthropic
|
|
12
|
+
* keys cache by exact byte prefix server-side. We don't need
|
|
13
|
+
* content hashes for the v2.6 surface; reserved for v2.7+ if a
|
|
14
|
+
* pre-flight cache-warm-check API ships.
|
|
15
|
+
*
|
|
16
|
+
* What this strategy DOES vs DOESN'T do:
|
|
17
|
+
* - DOES: clamp markers, attach to LLMRequest.cacheMarkers,
|
|
18
|
+
* extract metrics from response.usage
|
|
19
|
+
* - DOES NOT: rewrite the wire body. The provider
|
|
20
|
+
* (BrowserAnthropicProvider) reads `cacheMarkers` and applies
|
|
21
|
+
* `cache_control` blocks during body construction. Separation of
|
|
22
|
+
* concerns: strategy decides WHAT to cache; provider knows HOW
|
|
23
|
+
* to encode on its specific wire.
|
|
24
|
+
*
|
|
25
|
+
* Auto-registers in the strategy registry on module import for
|
|
26
|
+
* provider names: 'anthropic', 'browser-anthropic'.
|
|
27
|
+
*/
|
|
28
|
+
import type { CacheCapabilities, CacheMarker, CacheMetrics, CacheStrategy, CacheStrategyContext } from '../types.js';
|
|
29
|
+
import type { LLMRequest } from '../../adapters/types.js';
|
|
30
|
+
export declare class AnthropicCacheStrategy implements CacheStrategy {
|
|
31
|
+
readonly providerName = "anthropic";
|
|
32
|
+
readonly capabilities: CacheCapabilities;
|
|
33
|
+
prepareRequest(req: LLMRequest, candidates: readonly CacheMarker[], ctx: CacheStrategyContext): Promise<{
|
|
34
|
+
readonly request: LLMRequest;
|
|
35
|
+
readonly markersApplied: readonly CacheMarker[];
|
|
36
|
+
}>;
|
|
37
|
+
extractMetrics(usage: unknown): CacheMetrics | undefined;
|
|
38
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BedrockCacheStrategy — model-aware strategy for AWS Bedrock.
|
|
3
|
+
*
|
|
4
|
+
* Bedrock hosts multiple model families. Cache support varies:
|
|
5
|
+
* - Claude on Bedrock → identical mechanics to direct Anthropic
|
|
6
|
+
* (`cache_control: { type: 'ephemeral' }` markers, 4-marker
|
|
7
|
+
* limit). Strategy delegates to Anthropic-shaped behavior.
|
|
8
|
+
* - Llama / Mistral / Cohere on Bedrock → no cache support today
|
|
9
|
+
* (as of 2026-04-30). Strategy passes through, returns no metrics.
|
|
10
|
+
*
|
|
11
|
+
* Auto-detection: inspects `req.model` to decide. Claude model IDs
|
|
12
|
+
* start with `'anthropic.claude'` on Bedrock (e.g.,
|
|
13
|
+
* `anthropic.claude-3-5-sonnet-20240620-v1:0`).
|
|
14
|
+
*
|
|
15
|
+
* Auto-registers under provider name `'bedrock'`.
|
|
16
|
+
*
|
|
17
|
+
* Per the Phase 1 review (Reviewer 6 — Provider SDK expert): for
|
|
18
|
+
* non-Claude Bedrock models the strategy reports `enabled: false` in
|
|
19
|
+
* its capabilities so the CacheDecision subflow can short-circuit
|
|
20
|
+
* marker emission (potential v2.7 optimization). Today markers still
|
|
21
|
+
* emit and we drop them silently in prepareRequest.
|
|
22
|
+
*/
|
|
23
|
+
import type { CacheCapabilities, CacheMarker, CacheMetrics, CacheStrategy, CacheStrategyContext } from '../types.js';
|
|
24
|
+
import type { LLMRequest } from '../../adapters/types.js';
|
|
25
|
+
export declare class BedrockCacheStrategy implements CacheStrategy {
|
|
26
|
+
readonly providerName = "bedrock";
|
|
27
|
+
readonly capabilities: CacheCapabilities;
|
|
28
|
+
prepareRequest(req: LLMRequest, candidates: readonly CacheMarker[], ctx: CacheStrategyContext): Promise<{
|
|
29
|
+
readonly request: LLMRequest;
|
|
30
|
+
readonly markersApplied: readonly CacheMarker[];
|
|
31
|
+
}>;
|
|
32
|
+
extractMetrics(usage: unknown): CacheMetrics | undefined;
|
|
33
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NoOpCacheStrategy — fallback strategy for providers without cache
|
|
3
|
+
* support (Mock, unknown providers, intentional opt-out).
|
|
4
|
+
*
|
|
5
|
+
* Returns the request unchanged; reports no metrics. The
|
|
6
|
+
* `capabilities.enabled` flag is `false` so the CacheDecision subflow
|
|
7
|
+
* could choose to skip emitting markers entirely (potential v2.7
|
|
8
|
+
* optimization), though current Phase 4+5 always emit markers and
|
|
9
|
+
* let the strategy decide what to do with them.
|
|
10
|
+
*
|
|
11
|
+
* Always-available default. Registered against the special wildcard
|
|
12
|
+
* `'*'` so any unrecognized provider name falls back to NoOp.
|
|
13
|
+
*/
|
|
14
|
+
import type { CacheCapabilities, CacheMarker, CacheMetrics, CacheStrategy, CacheStrategyContext } from '../types.js';
|
|
15
|
+
import type { LLMRequest } from '../../adapters/types.js';
|
|
16
|
+
export declare class NoOpCacheStrategy implements CacheStrategy {
|
|
17
|
+
/**
|
|
18
|
+
* Wildcard provider name. The strategy registry treats this as the
|
|
19
|
+
* fallback for any provider that doesn't have a specific strategy
|
|
20
|
+
* registered.
|
|
21
|
+
*/
|
|
22
|
+
readonly providerName = "*";
|
|
23
|
+
readonly capabilities: CacheCapabilities;
|
|
24
|
+
prepareRequest(req: LLMRequest, _candidates: readonly CacheMarker[], _ctx: CacheStrategyContext): Promise<{
|
|
25
|
+
readonly request: LLMRequest;
|
|
26
|
+
readonly markersApplied: readonly CacheMarker[];
|
|
27
|
+
}>;
|
|
28
|
+
extractMetrics(_usage: unknown): CacheMetrics | undefined;
|
|
29
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAICacheStrategy — metrics-only strategy for OpenAI providers.
|
|
3
|
+
*
|
|
4
|
+
* OpenAI auto-caches request prefixes ≥1024 tokens at 50% off.
|
|
5
|
+
* No client-side opt-in markers needed (and no way to influence
|
|
6
|
+
* cache behavior from the client). The strategy:
|
|
7
|
+
*
|
|
8
|
+
* - **prepareRequest**: pass-through. We can't tell OpenAI what
|
|
9
|
+
* to cache; they decide automatically. Markers are silently
|
|
10
|
+
* dropped (the 80% case for OpenAI consumers is "I declared
|
|
11
|
+
* cache: 'always' for my injections" — that's still meaningful
|
|
12
|
+
* because (a) it's portable across providers, (b) for OpenAI
|
|
13
|
+
* the auto-cache may still hit on stable prefixes regardless).
|
|
14
|
+
* - **extractMetrics**: reads `prompt_tokens_details.cached_tokens`
|
|
15
|
+
* from OpenAI's usage response so cacheRecorder can surface
|
|
16
|
+
* hit rates / dollar savings.
|
|
17
|
+
*
|
|
18
|
+
* Auto-registers on module import for: 'openai', 'browser-openai'.
|
|
19
|
+
*
|
|
20
|
+
* Documentation note for consumers (Phase 12 docs): the `cache:`
|
|
21
|
+
* directive on injection definitions is portable but has NO LOCAL
|
|
22
|
+
* EFFECT on OpenAI runs — the provider auto-caches based on prefix
|
|
23
|
+
* length. The directive still ships correctly with the agent and
|
|
24
|
+
* lights up automatically when you swap to Anthropic / Bedrock.
|
|
25
|
+
*/
|
|
26
|
+
import type { CacheCapabilities, CacheMarker, CacheMetrics, CacheStrategy, CacheStrategyContext } from '../types.js';
|
|
27
|
+
import type { LLMRequest } from '../../adapters/types.js';
|
|
28
|
+
export declare class OpenAICacheStrategy implements CacheStrategy {
|
|
29
|
+
readonly providerName = "openai";
|
|
30
|
+
readonly capabilities: CacheCapabilities;
|
|
31
|
+
prepareRequest(req: LLMRequest, _candidates: readonly CacheMarker[], _ctx: CacheStrategyContext): Promise<{
|
|
32
|
+
readonly request: LLMRequest;
|
|
33
|
+
readonly markersApplied: readonly CacheMarker[];
|
|
34
|
+
}>;
|
|
35
|
+
extractMetrics(usage: unknown): CacheMetrics | undefined;
|
|
36
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strategy registry — maps provider name → CacheStrategy.
|
|
3
|
+
*
|
|
4
|
+
* Auto-resolution at agent build time: agentfootprint inspects
|
|
5
|
+
* `provider.name` and looks up the registered strategy for that
|
|
6
|
+
* name. Falls back to `NoOpCacheStrategy` (registered under wildcard
|
|
7
|
+
* `'*'`) when the provider isn't recognized.
|
|
8
|
+
*
|
|
9
|
+
* Phases shipping registered strategies:
|
|
10
|
+
* - v2.6 Phase 6 (this phase): NoOp
|
|
11
|
+
* - v2.6 Phase 7: AnthropicCacheStrategy ('anthropic',
|
|
12
|
+
* 'browser-anthropic')
|
|
13
|
+
* - v2.6 Phase 8: OpenAICacheStrategy ('openai', 'browser-openai'),
|
|
14
|
+
* BedrockCacheStrategy ('bedrock')
|
|
15
|
+
* - v2.7+ : GeminiCacheStrategy (handle-based, async, deferred)
|
|
16
|
+
*
|
|
17
|
+
* Consumers can register their own strategy via
|
|
18
|
+
* `registerCacheStrategy(strategy)`. Useful for in-house LLM proxies
|
|
19
|
+
* or test mocks.
|
|
20
|
+
*/
|
|
21
|
+
import type { CacheStrategy } from './types.js';
|
|
22
|
+
/**
|
|
23
|
+
* Look up a CacheStrategy by provider name. Falls back to the
|
|
24
|
+
* wildcard NoOp strategy if no match.
|
|
25
|
+
*
|
|
26
|
+
* Lookup is case-insensitive on the provider name.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getDefaultCacheStrategy(providerName: string): CacheStrategy;
|
|
29
|
+
/**
|
|
30
|
+
* Register (or replace) a strategy for a provider name. Called by
|
|
31
|
+
* strategy modules (v2.6 Phase 7+) at module load OR by consumers
|
|
32
|
+
* needing a custom backend. Replacing an existing strategy is allowed
|
|
33
|
+
* — the most-recent registration wins.
|
|
34
|
+
*/
|
|
35
|
+
export declare function registerCacheStrategy(strategy: CacheStrategy): void;
|
|
36
|
+
/**
|
|
37
|
+
* Read-only view of registered strategy names. Useful for diagnostics
|
|
38
|
+
* (e.g., logging "we have strategies for: anthropic, openai, *").
|
|
39
|
+
*/
|
|
40
|
+
export declare function listRegisteredStrategies(): readonly string[];
|
|
41
|
+
/**
|
|
42
|
+
* Internal helper for tests: reset the registry to the default
|
|
43
|
+
* (wildcard → NoOp only). Not exported from the public barrel.
|
|
44
|
+
*/
|
|
45
|
+
export declare function _resetRegistryForTests(): void;
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache layer — public types.
|
|
3
|
+
*
|
|
4
|
+
* Three layers, each with one responsibility:
|
|
5
|
+
*
|
|
6
|
+
* 1. CONSUMER DSL — `CachePolicy` field on every injection factory.
|
|
7
|
+
* Declarative, like GraphQL schema input. Says WHAT should be
|
|
8
|
+
* cacheable. Examples: `cache: 'always'`, `cache: 'while-active'`.
|
|
9
|
+
*
|
|
10
|
+
* 2. AGNOSTIC MARKERS — `CacheMarker[]` produced by the
|
|
11
|
+
* `CacheDecision` subflow at runtime. Provider-independent
|
|
12
|
+
* identification of "cacheable prefix in field X up to index Y".
|
|
13
|
+
*
|
|
14
|
+
* 3. PROVIDER STRATEGY — one `CacheStrategy` implementation per
|
|
15
|
+
* provider (Anthropic / OpenAI / Bedrock / NoOp). Translates
|
|
16
|
+
* agnostic markers to provider-specific wire format AND extracts
|
|
17
|
+
* cache metrics from the provider's response.
|
|
18
|
+
*
|
|
19
|
+
* The interfaces are read-only / immutable by convention. Strategies
|
|
20
|
+
* MUST be stateless across runs; per-run state lives in the
|
|
21
|
+
* `CacheStrategyContext` passed into `prepareRequest`.
|
|
22
|
+
*/
|
|
23
|
+
import type { LLMRequest } from '../adapters/types.js';
|
|
24
|
+
/**
|
|
25
|
+
* `cache:` field shape on every injection factory.
|
|
26
|
+
*
|
|
27
|
+
* Defaults per factory (chosen so `cache:` is rarely written explicitly):
|
|
28
|
+
* - `defineSteering` → `'always'`
|
|
29
|
+
* - `defineFact` → `'always'`
|
|
30
|
+
* - `defineSkill` → `'while-active'`
|
|
31
|
+
* - `defineInstruction` → `'never'`
|
|
32
|
+
* - `defineMemory` → `'while-active'`
|
|
33
|
+
*
|
|
34
|
+
* Variants:
|
|
35
|
+
* - `'always'` — cache whenever this injection is in `activeInjections`.
|
|
36
|
+
* Sugar for `{ until: () => false }`. The most aggressive form.
|
|
37
|
+
* - `'never'` — never cache. Use for volatile content (rule predicates,
|
|
38
|
+
* on-tool-return injections, content with timestamps or per-request IDs).
|
|
39
|
+
* Sugar for `{ until: () => true }` — i.e., always-invalidated.
|
|
40
|
+
* - `'while-active'` — cache while this injection appears in
|
|
41
|
+
* `activeInjections[]` for the current iteration. The cache invalidates
|
|
42
|
+
* the moment the injection becomes inactive (predicate returns `false`,
|
|
43
|
+
* skill deactivates, fact gets removed). Skill default; intuitive
|
|
44
|
+
* meaning regardless of factory.
|
|
45
|
+
* - `{ until: ctx => ... }` — conditional invalidation; cached UNTIL
|
|
46
|
+
* the predicate returns `true`. The predicate runs every iteration;
|
|
47
|
+
* if it flips to `true`, the cache prefix is rebuilt.
|
|
48
|
+
*
|
|
49
|
+
* **Composition**: the four sentinel forms cover most cases. For
|
|
50
|
+
* complex composition (e.g., "cache always EXCEPT after iter 5"), use
|
|
51
|
+
* the `{ until: ... }` form directly:
|
|
52
|
+
*
|
|
53
|
+
* ```ts
|
|
54
|
+
* // Stable for the first 5 iters, then flush:
|
|
55
|
+
* cache: { until: ctx => ctx.iteration > 5 }
|
|
56
|
+
*
|
|
57
|
+
* // Cache while iter > 1 (skip caching on the very first call):
|
|
58
|
+
* cache: { until: ctx => ctx.iteration <= 1 }
|
|
59
|
+
*
|
|
60
|
+
* // Invalidate when cumulative spend exceeds budget:
|
|
61
|
+
* cache: { until: ctx => ctx.cumulativeInputTokens > 50_000 }
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* The predicate is the DSL's escape hatch — Turing-complete by design.
|
|
65
|
+
* 80% of consumers stick with the three sentinel strings; power users
|
|
66
|
+
* compose freely via `{ until }`.
|
|
67
|
+
*/
|
|
68
|
+
export type CachePolicy = 'always' | 'never' | 'while-active' | {
|
|
69
|
+
readonly until: (ctx: CachePolicyContext) => boolean;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Context passed to a `CachePolicy.until` predicate. Read-only
|
|
73
|
+
* snapshot; predicates must be pure.
|
|
74
|
+
*
|
|
75
|
+
* Mirrors `InjectionContext` but trimmed to the fields a cache
|
|
76
|
+
* predicate would meaningfully inspect.
|
|
77
|
+
*/
|
|
78
|
+
export interface CachePolicyContext {
|
|
79
|
+
/** Current ReAct iteration (1-based). */
|
|
80
|
+
readonly iteration: number;
|
|
81
|
+
/** Number of iterations remaining (= maxIterations - iteration). */
|
|
82
|
+
readonly iterationsRemaining: number;
|
|
83
|
+
/** The current user message that started this turn. */
|
|
84
|
+
readonly userMessage: string;
|
|
85
|
+
/** Last tool that returned, if any. */
|
|
86
|
+
readonly lastToolName?: string;
|
|
87
|
+
/** Cumulative input tokens so far this run. */
|
|
88
|
+
readonly cumulativeInputTokens: number;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Provider-independent identification of a cacheable prefix.
|
|
92
|
+
*
|
|
93
|
+
* The CacheDecision subflow walks `activeInjections` and emits one
|
|
94
|
+
* marker per slot whose entries from index 0..boundaryIndex form a
|
|
95
|
+
* stable, contiguous, cacheable prefix.
|
|
96
|
+
*
|
|
97
|
+
* `field` is the request field this marker targets. Each provider
|
|
98
|
+
* strategy translates it differently:
|
|
99
|
+
* - `'system'` → Anthropic puts `cache_control` on a system block
|
|
100
|
+
* - `'tools'` → Anthropic puts `cache_control` on a tools array entry
|
|
101
|
+
* - `'messages'` → Anthropic puts `cache_control` on the LAST content
|
|
102
|
+
* block of the LAST message (Anthropic-specific positional rule)
|
|
103
|
+
*/
|
|
104
|
+
export interface CacheMarker {
|
|
105
|
+
readonly field: 'system' | 'tools' | 'messages';
|
|
106
|
+
/**
|
|
107
|
+
* 0-based index of the LAST element in `field` to include in the
|
|
108
|
+
* cached prefix. Everything from index 0..boundaryIndex (inclusive)
|
|
109
|
+
* is cacheable.
|
|
110
|
+
*
|
|
111
|
+
* **Provider note for `field: 'messages'`**: Anthropic's `cache_control`
|
|
112
|
+
* on `messages` is positional — it only takes effect on the LAST
|
|
113
|
+
* content block of the LAST message in the cacheable prefix. The
|
|
114
|
+
* AnthropicCacheStrategy translates `boundaryIndex` to the right
|
|
115
|
+
* positional placement; consumers and CacheDecision subflow don't
|
|
116
|
+
* see this complexity.
|
|
117
|
+
*/
|
|
118
|
+
readonly boundaryIndex: number;
|
|
119
|
+
/**
|
|
120
|
+
* Suggested TTL for this marker. Strategies map to provider-specific
|
|
121
|
+
* values (Anthropic: `'short'` → 5min ephemeral, `'long'` → 1h beta).
|
|
122
|
+
*/
|
|
123
|
+
readonly ttl: 'short' | 'long';
|
|
124
|
+
/**
|
|
125
|
+
* Diagnostic string surfaced in cacheRecorder events. Helps consumers
|
|
126
|
+
* understand WHY this marker fired. Examples: `'always-on injections'`,
|
|
127
|
+
* `'skill body (port-error-triage)'`.
|
|
128
|
+
*/
|
|
129
|
+
readonly reason: string;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Per-provider cache implementation. One strategy per provider name;
|
|
133
|
+
* registered in a default map keyed by `LLMProvider.name`.
|
|
134
|
+
*
|
|
135
|
+
* Strategies MUST be stateless across runs. Any per-run state (handle
|
|
136
|
+
* cache, hit-rate tracking) lives inside the strategy instance.
|
|
137
|
+
*/
|
|
138
|
+
export interface CacheStrategy {
|
|
139
|
+
/** Provider name match. e.g. `'anthropic'`, `'openai'`, `'bedrock'`. */
|
|
140
|
+
readonly providerName: string;
|
|
141
|
+
/**
|
|
142
|
+
* Static description of what this strategy can do. Read by the
|
|
143
|
+
* CacheDecision subflow to know whether to bother emitting markers,
|
|
144
|
+
* and how many to emit before clamping to provider limits.
|
|
145
|
+
*/
|
|
146
|
+
readonly capabilities: CacheCapabilities;
|
|
147
|
+
/**
|
|
148
|
+
* Translate agnostic markers to provider-specific wire format.
|
|
149
|
+
*
|
|
150
|
+
* Async to support handle-based caching (Gemini does
|
|
151
|
+
* `createCachedContent` and references handles; not in v2.6 but
|
|
152
|
+
* the interface is async-ready for v2.7+).
|
|
153
|
+
*
|
|
154
|
+
* Returns the modified request AND the markers actually applied
|
|
155
|
+
* (after capability-clamping). `markersApplied` flows into the
|
|
156
|
+
* cacheRecorder for diagnostic surfacing.
|
|
157
|
+
*/
|
|
158
|
+
prepareRequest(req: LLMRequest, candidates: readonly CacheMarker[], ctx: CacheStrategyContext): Promise<{
|
|
159
|
+
readonly request: LLMRequest;
|
|
160
|
+
readonly markersApplied: readonly CacheMarker[];
|
|
161
|
+
}>;
|
|
162
|
+
/**
|
|
163
|
+
* Extract cache hit/miss metrics from the provider's `usage` field.
|
|
164
|
+
* Each provider names its cache fields differently:
|
|
165
|
+
* - Anthropic: `cache_creation_input_tokens` + `cache_read_input_tokens`
|
|
166
|
+
* - OpenAI: `prompt_tokens_details.cached_tokens`
|
|
167
|
+
*
|
|
168
|
+
* Returns `undefined` for providers without cache reporting (Mock, NoOp).
|
|
169
|
+
*/
|
|
170
|
+
extractMetrics(usage: unknown): CacheMetrics | undefined;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Static description of a strategy's capabilities. The CacheDecision
|
|
174
|
+
* subflow reads this BEFORE calling `prepareRequest` so it can clamp
|
|
175
|
+
* candidates to a count the strategy can actually use.
|
|
176
|
+
*/
|
|
177
|
+
export interface CacheCapabilities {
|
|
178
|
+
/**
|
|
179
|
+
* `true` if this strategy actually does anything. `false` for NoOp,
|
|
180
|
+
* Mock, or providers we haven't built yet. CacheDecision subflow
|
|
181
|
+
* skips entirely when `enabled` is `false`.
|
|
182
|
+
*/
|
|
183
|
+
readonly enabled: boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Maximum number of cache markers per request. Anthropic enforces 4
|
|
186
|
+
* cache breakpoints per request; OpenAI is automatic (∞); Gemini
|
|
187
|
+
* is per-handle (∞ effectively). Strategies clamp internally.
|
|
188
|
+
*/
|
|
189
|
+
readonly maxMarkers: number;
|
|
190
|
+
/**
|
|
191
|
+
* TTL values this strategy can map to. Anthropic supports both;
|
|
192
|
+
* OpenAI is fixed (~5min); some providers may only support one.
|
|
193
|
+
*/
|
|
194
|
+
readonly ttls: ReadonlyArray<'short' | 'long'>;
|
|
195
|
+
/**
|
|
196
|
+
* Which request fields this strategy can mark. Most providers support
|
|
197
|
+
* all three (system / tools / messages); some are field-restricted.
|
|
198
|
+
*/
|
|
199
|
+
readonly fields: ReadonlyArray<'system' | 'tools' | 'messages'>;
|
|
200
|
+
/**
|
|
201
|
+
* `true` if the provider auto-caches without explicit markers (OpenAI).
|
|
202
|
+
* In that case `prepareRequest` is a pass-through; only
|
|
203
|
+
* `extractMetrics` does meaningful work. Surfaced for documentation
|
|
204
|
+
* (so consumers know `cache: 'never'` may not actually disable caching
|
|
205
|
+
* on auto-caching providers).
|
|
206
|
+
*/
|
|
207
|
+
readonly automatic: boolean;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Per-run state passed into `prepareRequest`. Strategies use this to
|
|
211
|
+
* make per-iteration decisions (rate of cache invalidation, current
|
|
212
|
+
* iteration index, etc.) without leaking state into module scope.
|
|
213
|
+
*/
|
|
214
|
+
export interface CacheStrategyContext {
|
|
215
|
+
readonly iteration: number;
|
|
216
|
+
readonly iterationsRemaining: number;
|
|
217
|
+
/**
|
|
218
|
+
* Hit rate across previous iterations of this run (0..1). Strategies
|
|
219
|
+
* use this for self-disable behaviors (e.g., AnthropicCacheStrategy
|
|
220
|
+
* auto-skips markers when hit rate < 30% to avoid the cache-write
|
|
221
|
+
* penalty without recoup).
|
|
222
|
+
*/
|
|
223
|
+
readonly recentHitRate: number | undefined;
|
|
224
|
+
/**
|
|
225
|
+
* `true` when `Agent.create({ caching: 'off' })` is set OR a
|
|
226
|
+
* higher-level kill switch fires. Strategy MUST honor this and
|
|
227
|
+
* return the request unchanged.
|
|
228
|
+
*/
|
|
229
|
+
readonly cachingDisabled: boolean;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Normalized cache metrics extracted from a provider's `usage`
|
|
233
|
+
* response. cacheRecorder consumes these for hit-rate tracking,
|
|
234
|
+
* cost estimation (via PricingTable), and diagnostic events.
|
|
235
|
+
*/
|
|
236
|
+
export interface CacheMetrics {
|
|
237
|
+
/** Tokens served from cache (10% / 50% / 25% off depending on provider). */
|
|
238
|
+
readonly cacheReadTokens: number;
|
|
239
|
+
/** Tokens written to cache this call (premium varies by provider). */
|
|
240
|
+
readonly cacheWriteTokens: number;
|
|
241
|
+
/** New input tokens not from cache — full price. */
|
|
242
|
+
readonly freshInputTokens: number;
|
|
243
|
+
}
|