Skip to content

LLMDescriptionScorer prompt puts the utterance before the descriptions, defeating provider prefix caching #355

Description

@voorhs

What happens

LLMDescriptionScorer._create_prompt (llm_encoder.py:155-200) lays the single user message out as

  1. two-line header,
  2. <text_sample>{utterance}</text_sample>,
  3. <possible_intent_descriptions> — all N descriptions, identical for every utterance of a run and the bulk of the tokens (77–150 descriptions on banking77/clinc150),
  4. <instructions>.

Provider prompt/prefix caching (OpenAI automatic prompt caching, Anthropic cache, OpenRouter pass-through) only matches the longest identical prefix, and here the prefix diverges at the utterance, so the descriptions block is re-billed at full input price on every call. Input tokens are essentially the whole cost of each call (the output is a short JSON of indices).

Proposed

Order the message header → descriptions → instructions → utterance (utterance last). The shared prefix then covers everything but the utterance, and cached input tokens are billed at the provider's discounted rate across different utterances, not just exact repeats. Darinochka/AutoIntent-experiments#43 saw the exact-repeat effect already: a byte-identical dry-run repeat cost $0.0054/call vs $0.0308 cold on OpenRouter.

Caveats: the prompt text is part of the StructuredOutputCache key, so existing caches miss once; and the change moves the question relative to the context, so quality should be re-checked on one dataset before switching the default.

Follow-up from #350.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions