Skip to content

Commit 5e90631

Browse files
committed
docs(providers): move prompt-cache inline comments into TSDoc
Drop the inline // comments in favor of TSDoc on the helper/gate. The gate-sizing and call-ordering rationale now lives in applyAnthropicPromptCache's TSDoc; no behavior change.
1 parent 38140c7 commit 5e90631

3 files changed

Lines changed: 12 additions & 15 deletions

File tree

apps/sim/providers/anthropic/core.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,6 @@ export async function executeAnthropicProviderRequest(
325325
}
326326
}
327327

328-
// Prompt caching: mark the static prefix (system + tools) with an ephemeral
329-
// cache breakpoint so repeated calls (agent tool-loops, multi-turn) reuse it.
330-
// Runs after the structured-output block above, which assumes `system` is still
331-
// a string. Mutates payload.system and the last tool in place.
332328
applyAnthropicPromptCache(payload, anthropicTools, request.systemPrompt)
333329

334330
// Add extended thinking configuration if supported and requested

apps/sim/providers/anthropic/utils.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,19 @@ interface AnthropicCacheablePayload {
2222
* Marks the static request prefix (system prompt + tools) with an ephemeral
2323
* cache breakpoint when {@link shouldCacheStaticPrefix} deems it worthwhile, so
2424
* repeated calls reuse the cached prefix. Mutates `payload.system` (string → a
25-
* single cached text block) and the last entry of `tools` in place.
25+
* single cached text block) and the last entry of `tools` in place; a no-op when
26+
* the prefix is too small or not present. Call after any structured-output
27+
* mutation of `payload.system`, since it may replace the string with a block array.
2628
*
27-
* `systemPrompt` is the ORIGINAL request system prompt, used only for the
28-
* worthiness gate: on the no-messages path the provider relocates the system
29-
* text into a user message and blanks `payload.system`, but the tools prefix is
30-
* still worth caching there.
29+
* The worthiness gate is sized on the LARGER of the final `payload.system`
30+
* (which may include appended structured-output schema text) and the original
31+
* `systemPrompt` (non-empty even when the no-messages path relocates the system
32+
* text into a user message and blanks `payload.system` — the tools prefix is
33+
* still worth caching there).
34+
*
35+
* @param payload - Anthropic request payload; `system` is mutated in place.
36+
* @param tools - Anthropic tool definitions; the last entry is mutated in place.
37+
* @param systemPrompt - The original request system prompt, used only for sizing.
3138
*/
3239
export function applyAnthropicPromptCache(
3340
payload: AnthropicCacheablePayload,
@@ -36,9 +43,6 @@ export function applyAnthropicPromptCache(
3643
): void {
3744
const payloadSystem = typeof payload.system === 'string' ? payload.system : ''
3845

39-
// Size the gate on the LARGER of the final payload.system (which may include
40-
// appended structured-output schema text) and the original request prompt
41-
// (non-empty even when the no-messages path relocates it out of payload.system).
4246
const gateSystem =
4347
payloadSystem.length >= (systemPrompt?.length ?? 0) ? payloadSystem : systemPrompt
4448

apps/sim/providers/prompt-cache.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,5 @@ export function shouldCacheStaticPrefix(params: {
4040
return false
4141
}
4242

43-
// Tools imply an agent loop (the prefix is re-read each iteration). Without
44-
// tools, only cache when the system prompt alone is large enough to be worth
45-
// the write on its own.
4643
return params.hasTools || systemTokens >= MIN_CACHEABLE_PREFIX_TOKENS
4744
}

0 commit comments

Comments
 (0)