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,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reliability — public types for the v2.11.1 rules-based reliability subsystem.
|
|
3
|
+
*
|
|
4
|
+
* Mental model: reliability is a SUBFLOW PATTERN expressed as `decide()`
|
|
5
|
+
* rules at PRE-call and POST-call boundaries around the LLM invocation.
|
|
6
|
+
* Each rule is `{when, then, kind, label?}`. The gate stage evaluates
|
|
7
|
+
* rules in order; the first match drives behaviour. Three channels carry
|
|
8
|
+
* the outcome:
|
|
9
|
+
*
|
|
10
|
+
* • SCOPE STATE — runtime data (`failKind`, `failPayload`) read by
|
|
11
|
+
* `Agent.run()` at the API boundary to construct `ReliabilityFailFastError`.
|
|
12
|
+
* • $emit — passive observability for external consumers
|
|
13
|
+
* (CloudWatch, X-Ray, OTel). NOT read by runtime logic.
|
|
14
|
+
* • $break(reason)— control flow + human-readable narrative reason.
|
|
15
|
+
*
|
|
16
|
+
* See `buildReliabilityGate.ts` for the gate stage that consumes these
|
|
17
|
+
* types and `Agent.create().reliability()` for the consumer-facing API.
|
|
18
|
+
*/
|
|
19
|
+
import type { LLMProvider, LLMRequest, LLMResponse } from '../adapters/types.js';
|
|
20
|
+
/**
|
|
21
|
+
* The set of verbs a `ReliabilityRule.then` can specify.
|
|
22
|
+
*
|
|
23
|
+
* • `continue` — pre-check only; no issues, proceed to the LLM call.
|
|
24
|
+
* • `ok` — post-decide only; call succeeded, exit the gate
|
|
25
|
+
* loop and let the agent's next stage run.
|
|
26
|
+
* • `retry` — post-decide only; bump attempt counter and re-run
|
|
27
|
+
* the same provider via the gate's `loopTo`.
|
|
28
|
+
* • `retry-other` — post-decide only; advance `providerIdx` to the
|
|
29
|
+
* next provider in the failover list, then loop.
|
|
30
|
+
* • `fallback` — post-decide only; invoke the configured
|
|
31
|
+
* `fallback(req, lastError)` to repair the response;
|
|
32
|
+
* exit on success.
|
|
33
|
+
* • `fail-fast` — both phases; write `failKind`/`failPayload` to
|
|
34
|
+
* scope, $emit observability event, $break(reason).
|
|
35
|
+
* `Agent.run()` translates the propagated break into
|
|
36
|
+
* a typed `ReliabilityFailFastError` at the API
|
|
37
|
+
* boundary.
|
|
38
|
+
*/
|
|
39
|
+
export type ReliabilityDecision = 'continue' | 'ok' | 'retry' | 'retry-other' | 'fallback' | 'fail-fast';
|
|
40
|
+
/**
|
|
41
|
+
* A single reliability rule. Evaluated by `decide()` from the gate
|
|
42
|
+
* stage; first-match-wins. Function-form `when` predicates are the
|
|
43
|
+
* common case; the filter-DSL form supported by `decide()` also works
|
|
44
|
+
* if your rule reads scope keys with simple comparisons.
|
|
45
|
+
*/
|
|
46
|
+
export interface ReliabilityRule {
|
|
47
|
+
/**
|
|
48
|
+
* Predicate over the gate's scope. Return `true` to fire this rule.
|
|
49
|
+
* Pure function — no side effects, no async. The gate evaluates
|
|
50
|
+
* predicates in sequence and stops on the first match.
|
|
51
|
+
*/
|
|
52
|
+
readonly when: (scope: ReliabilityScope) => boolean;
|
|
53
|
+
/** What to do when this rule matches. See `ReliabilityDecision`. */
|
|
54
|
+
readonly then: ReliabilityDecision;
|
|
55
|
+
/**
|
|
56
|
+
* Machine-readable label used to construct `ReliabilityFailFastError.kind`
|
|
57
|
+
* when `then === 'fail-fast'`. Also surfaces in narrative + emit payload.
|
|
58
|
+
* Must be a stable identifier — consumers branch on it programmatically.
|
|
59
|
+
* Example: `'cost-cap-exceeded'`, `'circuit-open-no-fallback'`,
|
|
60
|
+
* `'transient-5xx-retry'`.
|
|
61
|
+
*/
|
|
62
|
+
readonly kind: string;
|
|
63
|
+
/**
|
|
64
|
+
* Human-readable narrative reason. Falls back to `kind` if omitted.
|
|
65
|
+
* Surfaces in `$break(reason)` and the auto-narrative.
|
|
66
|
+
*/
|
|
67
|
+
readonly label?: string;
|
|
68
|
+
/**
|
|
69
|
+
* v2.13 — content delivered to the LLM as an EPHEMERAL user message
|
|
70
|
+
* before the next attempt, when this rule fires with `then: 'retry'`
|
|
71
|
+
* (or `then: 'retry-other'`). The agent appends `{ role: 'user',
|
|
72
|
+
* content: <feedback>, ephemeral: true }` to the next request's
|
|
73
|
+
* `messages` array — the LLM sees it for ONE call and it is NEVER
|
|
74
|
+
* persisted to `scope.history` or memory.
|
|
75
|
+
*
|
|
76
|
+
* Use case: Instructor-style schema retry. When schema validation
|
|
77
|
+
* fails, the rule's `feedbackForLLM` tells the model what to fix:
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* {
|
|
81
|
+
* when: (s) => s.validationError !== undefined && s.attempt < 3,
|
|
82
|
+
* then: 'retry',
|
|
83
|
+
* kind: 'schema-retry',
|
|
84
|
+
* feedbackForLLM: (s) =>
|
|
85
|
+
* `Previous output failed validation: ${s.validationError!.message}. ` +
|
|
86
|
+
* `Return valid JSON conforming to the schema.`,
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* String form: same content every retry. Function form: receives the
|
|
91
|
+
* current `ReliabilityScope` (so feedback can reference `attempt`,
|
|
92
|
+
* `validationError`, etc.). May return a Promise — async resolvers
|
|
93
|
+
* (template engines, LLM-judge) work; sync zero-overhead path stays
|
|
94
|
+
* sync.
|
|
95
|
+
*
|
|
96
|
+
* Ignored when `then` is anything other than `'retry'` / `'retry-other'`.
|
|
97
|
+
* If the rule doesn't set `feedbackForLLM`, the retry uses the same
|
|
98
|
+
* unchanged request (existing v2.11.5 behavior).
|
|
99
|
+
*/
|
|
100
|
+
readonly feedbackForLLM?: string | ((scope: ReliabilityScope) => string | Promise<string>);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* One entry in the optional provider failover list. The gate's
|
|
104
|
+
* `'retry-other'` decision advances through this array via `providerIdx`.
|
|
105
|
+
* If omitted, the gate operates against the agent's single configured
|
|
106
|
+
* provider with no failover.
|
|
107
|
+
*/
|
|
108
|
+
export interface ReliabilityProvider {
|
|
109
|
+
/** Display name — also the key used in `breakerStates` and
|
|
110
|
+
* `attemptsPerProvider` maps. Convention: lowercase vendor name. */
|
|
111
|
+
readonly name: string;
|
|
112
|
+
/** The actual provider instance to call. */
|
|
113
|
+
readonly provider: LLMProvider;
|
|
114
|
+
/** The model identifier passed to `provider.complete({ model, ... })`. */
|
|
115
|
+
readonly model: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Per-provider circuit breaker tuning. State is per-instance (per pod);
|
|
119
|
+
* see CHANGELOG note in v2.11.1 about distributed state limitations.
|
|
120
|
+
*/
|
|
121
|
+
export interface CircuitBreakerConfig {
|
|
122
|
+
/** Consecutive failures before the breaker OPENS. Default 5. */
|
|
123
|
+
readonly failureThreshold?: number;
|
|
124
|
+
/** How long the breaker stays OPEN before probing. Default 30_000 ms. */
|
|
125
|
+
readonly cooldownMs?: number;
|
|
126
|
+
/** Probe successes required in HALF-OPEN to fully CLOSE. Default 2. */
|
|
127
|
+
readonly halfOpenSuccessThreshold?: number;
|
|
128
|
+
/**
|
|
129
|
+
* Predicate — does this error count toward the failure threshold?
|
|
130
|
+
* Default: everything except AbortError counts. Override to ignore
|
|
131
|
+
* 4xx so a malformed request doesn't trip the breaker for everyone.
|
|
132
|
+
*/
|
|
133
|
+
readonly shouldCount?: (error: unknown) => boolean;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Consumer-supplied fallback that runs when a `'fallback'` rule fires.
|
|
137
|
+
* Receives the original request and the most recent error; returns a
|
|
138
|
+
* synthesized response that the gate writes back to scope. Throwing
|
|
139
|
+
* from the fallback re-enters the gate's post-decide rule set with
|
|
140
|
+
* the new error captured — typically the next rule routes to
|
|
141
|
+
* `'fail-fast'` (or a canned response if you've layered that pattern).
|
|
142
|
+
*/
|
|
143
|
+
export type ReliabilityFallbackFn = (request: LLMRequest, lastError: Error | undefined) => Promise<LLMResponse>;
|
|
144
|
+
/**
|
|
145
|
+
* The full reliability configuration passed to
|
|
146
|
+
* `Agent.create({...}).reliability(config)`. All fields optional — the
|
|
147
|
+
* gate stage is mounted only if at least one of `preCheck`/`postDecide`
|
|
148
|
+
* has rules OR `circuitBreaker` is configured. Otherwise the agent
|
|
149
|
+
* chart collapses to a plain `CallLLM` stage with no reliability
|
|
150
|
+
* overhead.
|
|
151
|
+
*/
|
|
152
|
+
export interface ReliabilityConfig {
|
|
153
|
+
/** Rules evaluated BEFORE the LLM call. Common uses: cost-cap pre-check,
|
|
154
|
+
* cumulative-budget gate, prompt-size guard. The gate routes on
|
|
155
|
+
* `'continue'` (proceed to call) or `'fail-fast'` (skip call, $break). */
|
|
156
|
+
readonly preCheck?: readonly ReliabilityRule[];
|
|
157
|
+
/** Rules evaluated AFTER the LLM call returns or throws. The gate
|
|
158
|
+
* routes on `'ok'` (success exit), `'retry'` (loop), `'retry-other'`
|
|
159
|
+
* (advance provider, loop), `'fallback'` (invoke fallback fn, exit),
|
|
160
|
+
* or `'fail-fast'` ($break with reason). */
|
|
161
|
+
readonly postDecide?: readonly ReliabilityRule[];
|
|
162
|
+
/** Optional ordered failover list. The first entry is the primary;
|
|
163
|
+
* `'retry-other'` decisions walk through this array. If omitted,
|
|
164
|
+
* reliability runs with no failover. */
|
|
165
|
+
readonly providers?: readonly ReliabilityProvider[];
|
|
166
|
+
/** Per-provider circuit-breaker config. Applied to every provider in
|
|
167
|
+
* `providers[]` (or to the agent's single provider if no failover
|
|
168
|
+
* list). Omit to disable circuit-breaking entirely. */
|
|
169
|
+
readonly circuitBreaker?: CircuitBreakerConfig;
|
|
170
|
+
/** Optional fallback function invoked on `'fallback'` decisions.
|
|
171
|
+
* Typical use: reformat a malformed schema response, repair JSON,
|
|
172
|
+
* or synthesize a safe default. Throwing re-enters the rule set. */
|
|
173
|
+
readonly fallback?: ReliabilityFallbackFn;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* The scope that reliability rules read. Populated by the gate stage
|
|
177
|
+
* each iteration. Consumer rules `(s: ReliabilityScope) => boolean`
|
|
178
|
+
* close over this shape; do NOT cast to `any` — the typed scope is the
|
|
179
|
+
* stable contract between gate state and rule predicates.
|
|
180
|
+
*
|
|
181
|
+
* Mutable scalars (attempt, providerIdx, error, errorKind, latencyMs,
|
|
182
|
+
* response) are OVERWRITTEN each iteration. Loop history is preserved
|
|
183
|
+
* by footprintjs's commitLog (one CommitBundle per stage execution),
|
|
184
|
+
* so time-travel scrubbing shows each attempt's snapshot independently.
|
|
185
|
+
*/
|
|
186
|
+
export interface ReliabilityScope {
|
|
187
|
+
/** The LLM request being processed by this gate execution. */
|
|
188
|
+
readonly request: LLMRequest;
|
|
189
|
+
/** Number of providers in the failover list — derived from the
|
|
190
|
+
* closure-held config; mirrored into scope so rules can compare
|
|
191
|
+
* against `providerIdx`. (Provider OBJECTS live in the gate chart's
|
|
192
|
+
* closure, not in scope, because functions can't structuredClone
|
|
193
|
+
* across subflow boundaries.) */
|
|
194
|
+
readonly providersCount: number;
|
|
195
|
+
/** True if a `fallback` function is configured. Lets rules check
|
|
196
|
+
* `s.hasFallback` to decide between `fallback` and `fail-fast`. */
|
|
197
|
+
readonly hasFallback: boolean;
|
|
198
|
+
/** 1-indexed attempt counter. Incremented after each LLM call,
|
|
199
|
+
* whether it succeeded or threw. Rules typically check
|
|
200
|
+
* `s.attempt < maxAttempts` before routing to `'retry'`. */
|
|
201
|
+
attempt: number;
|
|
202
|
+
/** Index into the gate's providers list (held in closure) for the
|
|
203
|
+
* currently-selected provider. */
|
|
204
|
+
providerIdx: number;
|
|
205
|
+
/** Convenience: `providers[providerIdx].name`. Updated alongside
|
|
206
|
+
* `providerIdx` on `'retry-other'`. */
|
|
207
|
+
currentProvider: string;
|
|
208
|
+
/** True if `providerIdx < providersCount - 1`. Lets rules check
|
|
209
|
+
* `s.canSwitchProvider` before routing to `'retry-other'`. */
|
|
210
|
+
canSwitchProvider: boolean;
|
|
211
|
+
/** The LLM response from the most recent successful call.
|
|
212
|
+
* `undefined` after a throw or before the first call completes. */
|
|
213
|
+
response?: LLMResponse;
|
|
214
|
+
/** The error from the most recent failed call. `undefined` after
|
|
215
|
+
* a successful call. */
|
|
216
|
+
error?: Error;
|
|
217
|
+
/** Coarse classification of `error` for rule matching. See
|
|
218
|
+
* `classifyError.ts` for the taxonomy. `'ok'` after success. */
|
|
219
|
+
errorKind: 'ok' | '5xx-transient' | 'rate-limit' | 'circuit-open' | 'schema-fail' | 'unknown';
|
|
220
|
+
/** Wall-clock latency of the most recent call attempt, in ms. */
|
|
221
|
+
latencyMs: number;
|
|
222
|
+
/**
|
|
223
|
+
* v2.13 — schema validation failure detail. Set when the response
|
|
224
|
+
* was structurally returned by the provider but failed
|
|
225
|
+
* `outputSchema` validation. Distinct from `error` (which is set by
|
|
226
|
+
* provider exceptions). Both can be set if the gate is in a state
|
|
227
|
+
* where validation comes after a separate provider failure.
|
|
228
|
+
*
|
|
229
|
+
* Use case: Instructor-style schema retry. Rules read this to fire
|
|
230
|
+
* `retry` with `feedbackForLLM` that names the validation message:
|
|
231
|
+
*
|
|
232
|
+
* ```ts
|
|
233
|
+
* { when: (s) => s.validationError !== undefined && s.attempt < 3, ... }
|
|
234
|
+
* ```
|
|
235
|
+
*
|
|
236
|
+
* `path` carries the failing field path when the parser exposes it
|
|
237
|
+
* (Zod `.issues[].path.join('.')`). `rawOutput` is the unparsed
|
|
238
|
+
* string the LLM returned — useful for narrative entries that show
|
|
239
|
+
* "what the model actually said."
|
|
240
|
+
*/
|
|
241
|
+
validationError?: {
|
|
242
|
+
readonly message: string;
|
|
243
|
+
readonly path?: string;
|
|
244
|
+
readonly rawOutput?: string;
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* v2.13 — chronological list of validation error MESSAGES across all
|
|
248
|
+
* attempts in this gate execution. Pushed once per `schema-fail`
|
|
249
|
+
* outcome. Empty until the first failure.
|
|
250
|
+
*
|
|
251
|
+
* Stuck-loop detection — pair with the `lastNValidationErrorsMatch`
|
|
252
|
+
* helper (or compare manually) to fail-fast when the model keeps
|
|
253
|
+
* making the same mistake instead of wasting more retries:
|
|
254
|
+
*
|
|
255
|
+
* ```ts
|
|
256
|
+
* { when: (s) => lastNValidationErrorsMatch(s, 2),
|
|
257
|
+
* then: 'fail-fast', kind: 'schema-stuck-loop' }
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
validationErrorHistory: readonly string[];
|
|
261
|
+
/** Per-provider attempt counts within this gate execution.
|
|
262
|
+
* Rules use this for "max-attempts-per-provider" semantics. */
|
|
263
|
+
attemptsPerProvider: Record<string, number>;
|
|
264
|
+
/** Per-provider breaker state. Full state record (counters,
|
|
265
|
+
* openedAt, lastErrorMessage) — NOT just the state enum — so the
|
|
266
|
+
* state machine round-trips across gate invocations via
|
|
267
|
+
* inputMapper/outputMapper. Rules typically check
|
|
268
|
+
* `s.breakerStates[provider]?.state === 'open'`. */
|
|
269
|
+
breakerStates: Record<string, import('./CircuitBreaker.js').BreakerState>;
|
|
270
|
+
/** Cumulative cost across the whole agent run, set by the agent
|
|
271
|
+
* via `inputMapper`. `undefined` if cost tracking is off.
|
|
272
|
+
* Kept here for `preCheck` rules like
|
|
273
|
+
* `s.cumulativeCostUsd >= s.costCapUsd → fail-fast`. */
|
|
274
|
+
cumulativeCostUsd?: number;
|
|
275
|
+
/** Cumulative input/output tokens, mirrored from agent state. */
|
|
276
|
+
cumulativeInputTokens?: number;
|
|
277
|
+
cumulativeOutputTokens?: number;
|
|
278
|
+
/** The matched rule's `kind` when a `'fail-fast'` rule fired.
|
|
279
|
+
* `Agent.run()` reads this to construct `ReliabilityFailFastError.kind`. */
|
|
280
|
+
failKind?: string;
|
|
281
|
+
/** Structured payload describing the fail-fast event. Shape:
|
|
282
|
+
* `{ phase, attempt, providerUsed, errorKind, errorMessage }`. */
|
|
283
|
+
failPayload?: {
|
|
284
|
+
readonly phase: 'pre-check' | 'post-decide';
|
|
285
|
+
readonly attempt: number;
|
|
286
|
+
readonly providerUsed: string;
|
|
287
|
+
readonly errorKind: ReliabilityScope['errorKind'];
|
|
288
|
+
readonly errorMessage?: string;
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Thrown by `Agent.run()` when a reliability rule routes to `'fail-fast'`
|
|
293
|
+
* and the gate $breaks with a reason. Carries:
|
|
294
|
+
*
|
|
295
|
+
* • `kind` — machine-readable identifier from the matched rule's
|
|
296
|
+
* `kind` field. Stable across versions; consumers
|
|
297
|
+
* branch on this.
|
|
298
|
+
* • `reason` — human-readable narrative string from `$break(reason)`.
|
|
299
|
+
* Format: `'reliability-{phase}: {label}'` (e.g.,
|
|
300
|
+
* `'reliability-post-decide: cost-cap-exceeded'`).
|
|
301
|
+
* • `cause` — the originating error from the LLM call, when one
|
|
302
|
+
* drove the fail-fast decision (e.g., the underlying
|
|
303
|
+
* HTTP error that tripped a circuit breaker).
|
|
304
|
+
* • `snapshot` — the full `executor.getSnapshot()` at fail-fast time
|
|
305
|
+
* for forensics. Consumers persist this for postmortem
|
|
306
|
+
* analysis (commitLog, narrative, scope state, etc.).
|
|
307
|
+
*
|
|
308
|
+
* Three-channel discipline: `kind`/`payload` came from scope state,
|
|
309
|
+
* `reason` came from $break, `snapshot` is the engine's own audit trail.
|
|
310
|
+
* Emit events flowed independently to any attached observability adapter
|
|
311
|
+
* (this error is the RUNTIME signal; emit is the OBSERVABILITY signal).
|
|
312
|
+
*/
|
|
313
|
+
export declare class ReliabilityFailFastError extends Error {
|
|
314
|
+
readonly code: "ERR_RELIABILITY_FAIL_FAST";
|
|
315
|
+
readonly kind: string;
|
|
316
|
+
readonly reason: string;
|
|
317
|
+
readonly cause?: Error;
|
|
318
|
+
readonly snapshot?: unknown;
|
|
319
|
+
readonly payload?: ReliabilityScope['failPayload'];
|
|
320
|
+
constructor(opts: {
|
|
321
|
+
kind: string;
|
|
322
|
+
reason: string;
|
|
323
|
+
cause?: Error;
|
|
324
|
+
snapshot?: unknown;
|
|
325
|
+
payload?: ReliabilityScope['failPayload'];
|
|
326
|
+
});
|
|
327
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fallbackProvider — convenience for chained fallbacks across N providers.
|
|
3
|
+
*
|
|
4
|
+
* Pattern: Chain of Responsibility (GoF) over `LLMProvider` instances.
|
|
5
|
+
* Role: Outer ring (Hexagonal). Sugar over repeated `withFallback`.
|
|
6
|
+
*
|
|
7
|
+
* `fallbackProvider(p1, p2, p3)` is equivalent to
|
|
8
|
+
* `withFallback(p1, withFallback(p2, p3))` — tries each provider in
|
|
9
|
+
* order, advancing on errors that match the (optional) shouldFallback
|
|
10
|
+
* predicate. The first success wins; if all fail, the last error throws.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { anthropic, openai, mock } from 'agentfootprint/llm-providers';
|
|
14
|
+
* import { fallbackProvider } from 'agentfootprint/resilience';
|
|
15
|
+
*
|
|
16
|
+
* const provider = fallbackProvider(
|
|
17
|
+
* anthropic({ apiKey: A }),
|
|
18
|
+
* openai({ apiKey: O }),
|
|
19
|
+
* mock({ reply: '[degraded] all upstream providers failed' }),
|
|
20
|
+
* );
|
|
21
|
+
*/
|
|
22
|
+
import type { LLMProvider } from '../adapters/types.js';
|
|
23
|
+
import { type WithFallbackOptions } from './withFallback.js';
|
|
24
|
+
export interface FallbackProviderOptions extends WithFallbackOptions {
|
|
25
|
+
/** Optional explicit name for the chained provider. */
|
|
26
|
+
readonly name?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Compose N providers into a single fallback chain. At least one
|
|
30
|
+
* provider is required; throws synchronously on empty input.
|
|
31
|
+
*/
|
|
32
|
+
export declare function fallbackProvider(...providers: readonly LLMProvider[]): LLMProvider;
|
|
33
|
+
export declare function fallbackProvider(options: FallbackProviderOptions, ...providers: readonly LLMProvider[]): LLMProvider;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agentfootprint/resilience — provider decorators for production reliability.
|
|
3
|
+
*
|
|
4
|
+
* Three composable wrappers around `LLMProvider`. Each preserves the
|
|
5
|
+
* `LLMProvider` interface (drop-in replacement) and stacks freely:
|
|
6
|
+
*
|
|
7
|
+
* const provider = withRetry(
|
|
8
|
+
* fallbackProvider(
|
|
9
|
+
* anthropic({ apiKey }),
|
|
10
|
+
* openai({ apiKey }),
|
|
11
|
+
* ),
|
|
12
|
+
* { maxAttempts: 5 },
|
|
13
|
+
* );
|
|
14
|
+
*
|
|
15
|
+
* Reads as: try anthropic; on failure fall back to openai; the whole
|
|
16
|
+
* chain is wrapped in retry with 5 attempts.
|
|
17
|
+
*/
|
|
18
|
+
export { withRetry, type WithRetryOptions } from './withRetry.js';
|
|
19
|
+
export { withFallback, type WithFallbackOptions } from './withFallback.js';
|
|
20
|
+
export { fallbackProvider, type FallbackProviderOptions } from './fallbackProvider.js';
|
|
21
|
+
export { withCircuitBreaker, CircuitOpenError, type WithCircuitBreakerOptions, type CircuitState, } from './withCircuitBreaker.js';
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* withCircuitBreaker — provider decorator that fails fast after N
|
|
3
|
+
* consecutive failures.
|
|
4
|
+
*
|
|
5
|
+
* Pattern: Circuit Breaker (Nygard, *Release It!*) — wraps an
|
|
6
|
+
* `LLMProvider` and tracks consecutive failures. After
|
|
7
|
+
* `failureThreshold` failures, the breaker OPENS and
|
|
8
|
+
* rejects all calls without invoking the wrapped provider.
|
|
9
|
+
* After `cooldownMs`, the breaker enters HALF-OPEN and
|
|
10
|
+
* allows probe calls; success closes the breaker, failure
|
|
11
|
+
* re-opens it.
|
|
12
|
+
*
|
|
13
|
+
* Role: Outer ring (Hexagonal). Composes with `withRetry` and
|
|
14
|
+
* `withFallback`:
|
|
15
|
+
*
|
|
16
|
+
* ```
|
|
17
|
+
* withFallback(
|
|
18
|
+
* withCircuitBreaker(anthropic(...)), // ← stop hammering on outage
|
|
19
|
+
* withCircuitBreaker(openai(...)),
|
|
20
|
+
* )
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* When Anthropic 503s for the 5th time, the breaker opens
|
|
24
|
+
* and `complete()` throws `CircuitOpenError` immediately —
|
|
25
|
+
* no network round-trip — which `withFallback` then
|
|
26
|
+
* catches and routes to OpenAI. After 30 seconds the
|
|
27
|
+
* breaker probes Anthropic with a single call; if it
|
|
28
|
+
* succeeds, normal operation resumes.
|
|
29
|
+
*
|
|
30
|
+
* Why a circuit breaker on top of `withRetry`?
|
|
31
|
+
* - `withRetry` keeps hammering one provider with exponential
|
|
32
|
+
* backoff — it doesn't know the vendor is down.
|
|
33
|
+
* - During a multi-minute Anthropic outage, every request still
|
|
34
|
+
* burns 3 retries + backoff = ~3 sec of latency before failing
|
|
35
|
+
* to the fallback. Multiplied by your QPS, that's a lot of
|
|
36
|
+
* wasted time + tokens (some retries DO get billed).
|
|
37
|
+
* - The breaker says: "we just saw 5 failures in a row; stop
|
|
38
|
+
* calling for 30 seconds." Subsequent requests fail in <1ms,
|
|
39
|
+
* `withFallback` routes immediately to OpenAI.
|
|
40
|
+
*
|
|
41
|
+
* Three states:
|
|
42
|
+
*
|
|
43
|
+
* CLOSED ──[ N consecutive failures ]──► OPEN
|
|
44
|
+
* ▲ │
|
|
45
|
+
* │ │ [cooldownMs elapsed]
|
|
46
|
+
* │ ▼
|
|
47
|
+
* └──[ M probe successes ]──── HALF-OPEN
|
|
48
|
+
*
|
|
49
|
+
* HALF-OPEN ──[ probe failure ]──► OPEN (cooldown restarts)
|
|
50
|
+
*
|
|
51
|
+
* `stream()` is decorated identically. `name`/`flush`/`stop` pass
|
|
52
|
+
* through unchanged (the consumer's existing observability hooks
|
|
53
|
+
* still see the underlying provider's identity).
|
|
54
|
+
*
|
|
55
|
+
* **Scope: per-instance, NOT distributed.** Each `withCircuitBreaker(...)`
|
|
56
|
+
* call holds its own breaker state in process memory. If you run 100
|
|
57
|
+
* server replicas, each has its own independent breaker — one
|
|
58
|
+
* instance can be CLOSED while another is OPEN. This is intentional
|
|
59
|
+
* (no shared state means no Redis dependency, no SPOF, no
|
|
60
|
+
* partial-cluster-blast-radius surprises) and matches Hystrix's
|
|
61
|
+
* default behavior. For cluster-wide coordination, layer your own
|
|
62
|
+
* Redis-backed counter on top via the `onStateChange` hook +
|
|
63
|
+
* `shouldCount` predicate.
|
|
64
|
+
*
|
|
65
|
+
* **Scope: PROVIDER-level, not per-tool — by design (B16).** The breaker
|
|
66
|
+
* wraps `LLMProvider` because a provider outage has unbounded blast
|
|
67
|
+
* radius: the LLM call is every run's heartbeat, fired once per
|
|
68
|
+
* iteration at your full QPS, and a failure aborts the call path. Tool
|
|
69
|
+
* failures don't share that shape — the agent's tool dispatch catches a
|
|
70
|
+
* tool throw and feeds the error message back to the model as the tool
|
|
71
|
+
* result (see `core/agent/stages/toolCalls.ts`), so the ReAct loop
|
|
72
|
+
* itself absorbs and adapts (retry, alternate tool, give up), serialized
|
|
73
|
+
* and bounded by the iteration budget. A flaky tool can't hammer
|
|
74
|
+
* anything the way provider QPS can. For the rare tool that needs a
|
|
75
|
+
* breaker today: its `execute` is a plain async function — wrap it with
|
|
76
|
+
* any breaker yourself, or hide it dynamically via a `gatedTools`
|
|
77
|
+
* predicate (the visible-tool list is recomputed every iteration).
|
|
78
|
+
* First-class per-tool breakers (state keyed by tool name; run-scoped
|
|
79
|
+
* vs process-scoped TBD) are a possible future enhancement.
|
|
80
|
+
*/
|
|
81
|
+
import type { LLMProvider } from '../adapters/types.js';
|
|
82
|
+
export interface WithCircuitBreakerOptions {
|
|
83
|
+
/** Consecutive failures before the breaker OPENS. Default 5. */
|
|
84
|
+
readonly failureThreshold?: number;
|
|
85
|
+
/** How long the breaker stays OPEN before probing. Default 30s. */
|
|
86
|
+
readonly cooldownMs?: number;
|
|
87
|
+
/** Successes required in HALF-OPEN to fully CLOSE. Default 2. */
|
|
88
|
+
readonly halfOpenSuccessThreshold?: number;
|
|
89
|
+
/**
|
|
90
|
+
* Predicate — does this error count toward the threshold? Default:
|
|
91
|
+
* everything except AbortError counts. Override to ignore client
|
|
92
|
+
* errors (e.g., 4xx) so a malformed request doesn't trip the
|
|
93
|
+
* breaker for everyone.
|
|
94
|
+
*/
|
|
95
|
+
readonly shouldCount?: (error: unknown) => boolean;
|
|
96
|
+
/** Hook invoked on every state transition. Useful for emitting
|
|
97
|
+
* `agentfootprint.resilience.circuit_state_changed`. */
|
|
98
|
+
readonly onStateChange?: (state: CircuitState, reason: string) => void;
|
|
99
|
+
}
|
|
100
|
+
export type CircuitState = 'closed' | 'open' | 'half-open';
|
|
101
|
+
/**
|
|
102
|
+
* Thrown by the wrapped provider when the breaker is OPEN. Carries
|
|
103
|
+
* the underlying root-cause error from the most recent failure so
|
|
104
|
+
* consumers can observe what tripped the breaker.
|
|
105
|
+
*/
|
|
106
|
+
export declare class CircuitOpenError extends Error {
|
|
107
|
+
readonly code: "ERR_CIRCUIT_OPEN";
|
|
108
|
+
/** The error that tripped the breaker (or the most recent failure
|
|
109
|
+
* during HALF-OPEN that re-opened it). */
|
|
110
|
+
readonly cause: unknown;
|
|
111
|
+
/** Wall-clock timestamp at which the breaker may next probe. */
|
|
112
|
+
readonly retryAfter: number;
|
|
113
|
+
constructor(providerName: string, cause: unknown, retryAfter: number);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Wrap a provider with a circuit breaker.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* import { anthropic, openai } from 'agentfootprint/llm-providers';
|
|
121
|
+
* import { withCircuitBreaker, withFallback } from 'agentfootprint/resilience';
|
|
122
|
+
*
|
|
123
|
+
* const provider = withFallback(
|
|
124
|
+
* withCircuitBreaker(anthropic({ apiKey }), { failureThreshold: 5, cooldownMs: 30_000 }),
|
|
125
|
+
* withCircuitBreaker(openai({ apiKey })),
|
|
126
|
+
* );
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export declare function withCircuitBreaker(inner: LLMProvider, options?: WithCircuitBreakerOptions): LLMProvider;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* withFallback — provider decorator that falls back to a secondary
|
|
3
|
+
* on error.
|
|
4
|
+
*
|
|
5
|
+
* Pattern: Decorator (GoF) — composes two `LLMProvider`s into one.
|
|
6
|
+
* Role: Outer ring (Hexagonal). Stacks with `withRetry`:
|
|
7
|
+
* `withRetry(withFallback(primary, fallback))` first retries
|
|
8
|
+
* the primary, then on exhaustion falls back to the secondary.
|
|
9
|
+
*
|
|
10
|
+
* Common pairings:
|
|
11
|
+
* • Anthropic primary, OpenAI fallback (vendor outage tolerance)
|
|
12
|
+
* • Real provider primary, Mock fallback (degrade gracefully in dev)
|
|
13
|
+
* • Premium model primary, cheaper model fallback (cost ceiling)
|
|
14
|
+
*
|
|
15
|
+
* `stream()` falls back too — if the primary's stream errors before
|
|
16
|
+
* yielding any chunks, we restart on the fallback. Once the primary
|
|
17
|
+
* has yielded chunks the stream is committed — fallback would
|
|
18
|
+
* duplicate the partial output.
|
|
19
|
+
*/
|
|
20
|
+
import type { LLMProvider } from '../adapters/types.js';
|
|
21
|
+
export interface WithFallbackOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Predicate to decide whether an error from the primary should
|
|
24
|
+
* trigger fallback. Default: every error except AbortError.
|
|
25
|
+
* Override to gate on specific status codes or error types.
|
|
26
|
+
*/
|
|
27
|
+
readonly shouldFallback?: (error: unknown) => boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Hook invoked when the primary fails and we're about to call the
|
|
30
|
+
* fallback. Useful for emitting `agentfootprint.resilience.fallback`.
|
|
31
|
+
*/
|
|
32
|
+
readonly onFallback?: (error: unknown) => void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Wrap a primary provider with a fallback. Tries primary first; on
|
|
36
|
+
* error matching the policy, calls the fallback.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* const provider = withFallback(
|
|
40
|
+
* anthropic({ apiKey: A }),
|
|
41
|
+
* openai({ apiKey: O }),
|
|
42
|
+
* { onFallback: (err) => console.warn('primary failed, falling back:', err) },
|
|
43
|
+
* );
|
|
44
|
+
*/
|
|
45
|
+
export declare function withFallback(primary: LLMProvider, fallback: LLMProvider, options?: WithFallbackOptions): LLMProvider;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* withRetry — provider decorator that retries failed calls.
|
|
3
|
+
*
|
|
4
|
+
* Pattern: Decorator (GoF) — wraps an `LLMProvider` and adds retry
|
|
5
|
+
* policy without changing its interface.
|
|
6
|
+
* Role: Outer ring (Hexagonal). Composable: `withRetry(withFallback(...))`.
|
|
7
|
+
*
|
|
8
|
+
* Retries `complete()` on transient failures with exponential backoff.
|
|
9
|
+
* `stream()` is delegated as-is — once tokens start flowing the
|
|
10
|
+
* pipeline is stateful and cannot safely be restarted. If you need
|
|
11
|
+
* retry semantics for streaming, fall back to `complete()` or
|
|
12
|
+
* implement custom resumability at the consumer.
|
|
13
|
+
*
|
|
14
|
+
* Default policy:
|
|
15
|
+
* • maxAttempts: 3 (initial + 2 retries)
|
|
16
|
+
* • backoff: exponential — 200ms, 400ms, 800ms
|
|
17
|
+
* • shouldRetry: rejects 4xx-class errors (client mistakes don't
|
|
18
|
+
* benefit from retry) and AbortError; retries 5xx,
|
|
19
|
+
* network errors, and unknown shapes.
|
|
20
|
+
*/
|
|
21
|
+
import type { LLMProvider } from '../adapters/types.js';
|
|
22
|
+
export interface WithRetryOptions {
|
|
23
|
+
/** Total attempts including the first. Default 3. Must be >= 1. */
|
|
24
|
+
readonly maxAttempts?: number;
|
|
25
|
+
/** Initial delay in ms before the first retry. Default 200. */
|
|
26
|
+
readonly initialDelayMs?: number;
|
|
27
|
+
/** Multiplier between attempts. Default 2 (200ms → 400ms → 800ms). */
|
|
28
|
+
readonly backoffFactor?: number;
|
|
29
|
+
/** Maximum delay cap in ms. Default 10_000. */
|
|
30
|
+
readonly maxDelayMs?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Predicate to decide whether an error is worth retrying. Default
|
|
33
|
+
* skips AbortError + HTTP 4xx; retries everything else. Override
|
|
34
|
+
* to add provider-specific signals (e.g., 429 with Retry-After).
|
|
35
|
+
*/
|
|
36
|
+
readonly shouldRetry?: (error: unknown, attempt: number) => boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Hook invoked before each retry. Useful for logging or an
|
|
39
|
+
* `agentfootprint.error.retried` emit (the event family reserved for
|
|
40
|
+
* the standalone provider decorators — see events/payloads.ts).
|
|
41
|
+
* Receives the attempt number that's about to start (so attempt 2 =
|
|
42
|
+
* first retry).
|
|
43
|
+
*/
|
|
44
|
+
readonly onRetry?: (error: unknown, attempt: number, delayMs: number) => void;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Wrap a provider so its `complete()` retries transient failures.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* import { withRetry } from 'agentfootprint/resilience';
|
|
51
|
+
* import { anthropic } from 'agentfootprint/llm-providers';
|
|
52
|
+
*
|
|
53
|
+
* const robust = withRetry(anthropic({ apiKey }), {
|
|
54
|
+
* maxAttempts: 5,
|
|
55
|
+
* onRetry: (err, attempt, ms) => console.warn(`retry ${attempt} in ${ms}ms`, err),
|
|
56
|
+
* });
|
|
57
|
+
*/
|
|
58
|
+
export declare function withRetry(provider: LLMProvider, options?: WithRetryOptions): LLMProvider;
|
|
59
|
+
/**
|
|
60
|
+
* Skip retry for AbortError + 4xx-class errors. Retry on everything
|
|
61
|
+
* else (network errors, 5xx, unknown shapes). Provider adapters that
|
|
62
|
+
* surface HTTP status should set `error.status` for this to work; the
|
|
63
|
+
* predicate falls back to retrying when status is unknown (better to
|
|
64
|
+
* retry once than to surface a flaky failure).
|
|
65
|
+
*
|
|
66
|
+
* Exported (module-level, NOT on the resilience barrel) as the single
|
|
67
|
+
* source of truth for the decorators' transience policy — shared by
|
|
68
|
+
* `withCredentialRetry` (identity) so "what counts as transient" never
|
|
69
|
+
* drifts between the LLM and credential retry wrappers.
|
|
70
|
+
*/
|
|
71
|
+
export declare function defaultShouldRetry(err: unknown, _attempt: number): boolean;
|