UNPKG

agentfootprint

Version:

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

42 lines (41 loc) • 2.03 kB
/** * BreakpointCacheStrategy — for a provider that caches a prefix only where * the request marks it (`promptCaching.mode: 'breakpoints'`; Anthropic's * `cache_control`). * * Chosen by CAPABILITY (`cacheStrategyFor`), never by provider name: built * from the provider's own declaration, so `withRetry(anthropic())` or an * application's routing wrapper caches exactly like the adapter it wraps. * * What it DOES: * - clamp the candidate markers to the declared `maxBreakpoints`, keeping * the first N in slot order (the most stable prefixes first); * - put them on `LLMRequest.cacheMarkers`, where the adapter reads them; * - read cache metrics off the PORT usage the adapter normalised — * `not applicable` when the declaration says the adapter reports none. * What it does NOT: touch the wire. The adapter owns `cache_control` * (`adapters/llm/anthropicCacheWire.ts`), and content is never edited. */ import type { CacheMarker, CacheMetrics, CacheStrategy, CacheStrategyContext, CacheUsage, PromptCaching } from '../types.js'; import { type Claim } from '../../lib/claim/claim.js'; import type { LLMRequest } from '../../provider-contract/types.js'; export declare class BreakpointCacheStrategy implements CacheStrategy { readonly name = "breakpoints"; private readonly maxBreakpoints; private readonly reportsUsage; private readonly who; private readonly fields?; /** * @param declared the provider's `promptCaching` declaration * @param who names the adapter in the meter's evidence sentences, * e.g. `"the 'anthropic' provider"` */ constructor(declared: Extract<PromptCaching, { mode: 'breakpoints'; }>, who?: string); prepareRequest(req: LLMRequest, candidates: readonly CacheMarker[], ctx: CacheStrategyContext): Promise<{ readonly request: LLMRequest; readonly markersApplied: readonly CacheMarker[]; }>; extractMetrics(usage: CacheUsage | undefined): Claim<CacheMetrics>; }