Files
HealthLog/src/lib/ai/coach/prompt-cache-key.ts
T
Marc-André Bombeck 316e52dee3 Widen the Coach turn budget and keep its rounds on the prompt cache
Own-plan turns get 165k tokens, 200 s and 16 rounds, operator turns 55k,
120 s and 8; the final-answer reserve, the concurrent-turn slot and the
step cap move with them.

Codex requests carry a per-conversation prompt_cache_key and a stable
session id, api.openai.com gets the same key, Anthropic usage counts
cache reads and writes in the gross, and local servers report cached
prompt tokens, so the turn budget discounts cached input on every
provider.
2026-10-07 22:48:48 +02:00

21 lines
856 B
TypeScript

/**
* v1.41.2 — the prompt-cache key of a Coach conversation.
*
* Every round of a turn resends the same system prompt and history, and the
* next turn of the conversation resends it again with one more exchange. A
* provider that routes requests to its prompt cache by key (Codex,
* `api.openai.com`) only finds the prefix an earlier call left there when the
* calls carry the same key. One key per conversation does that; a turn with
* no conversation yet gets a key of its own, still shared by its rounds.
*
* Hashed so the provider never sees the conversation id itself.
*/
import { createHash, randomUUID } from "node:crypto";
export function coachPromptCacheKey(conversationId?: string | null): string {
return createHash("sha256")
.update(`coach-prompt:${conversationId || randomUUID()}`)
.digest("hex")
.slice(0, 32);
}