본문 바로가기
C.W.K.
Stream
Lesson 01 of 05 · published

Stable Prefix, Variable Tail

~25 min · prompt-caching, prefix, structure

Level 0Window Watcher
0 XP0/50 lessons0/13 achievements
0/100 XP to next level100 XP to go0% complete

Cache는 똑같은 걸 좋아해

prompt caching은 stable prefix가 앞에, variable tail이 뒤에 있을 때 제일 잘 먹혀. 지시문, tool schema, 두고두고 쓰는 example, 잘 안 바뀌는 자료는 prefix 몫이야. 지금 들어온 질문, 방금 나온 diff, timestamp, 실행할 때마다 달라지는 ID는 tail 몫이고.

효과는 둘, 규칙은 하나

돈 아끼는 요령만은 아니야. context를 깨끗하게 쓰는 습관 자체를 밀어줘. 안 변하는 규칙은 안 변한 채로 두고, 살아 있는 입력은 딱 봐도 살아 있게 두는 거지. cache가 좋아하는 모양이랑 attention이 좋아하는 모양이 같은 건 우연이 아니야. API가 잘 설계된 덕이지.

다음 한 turn 말고 다음 백 turn을 보고 짜

cache가 좋아하는 prompt는 읽기도 쉽고, 뭐가 달라졌는지 비교하기도 쉽고, 동작이 바뀌었을 때 원인 찾기도 쉬워. 다음 한 turn만 보고 짜는 건 초보고, 다음 백 turn을 보고 짜는 게 비용 싸움에서 이기는 길이야.

Code

cache를 염두에 둔 prompt 모양 (stable prefix / variable tail)·yaml
prompt:
  stable_prefix:
    - system rules
    - tool definitions
    - style contract
    - reusable examples
    - corpus snippets re-read often
  variable_tail:
    - current user request
    - latest diff
    - latest tool result
    - timestamp if truly needed
Anthropic cache_control 예·python
messages = [{
    "role": "user",
    "content": [
        {"type": "text", "text": SYSTEM_RULES,
         "cache_control": {"type": "ephemeral"}},
        {"type": "text", "text": TOOL_SCHEMAS,
         "cache_control": {"type": "ephemeral"}},
        {"type": "text", "text": current_question},
    ],
}]

External links

Exercise

긴 prompt 하나를 stable prefix랑 variable tail로 갈라봐. 변덕스러운 건 prefix에서 전부 빼고. provider가 지원하면 그 경계에 cache_control breakpoint를 넣어.
Hint
요청마다 바뀌는 거면 prefix에 있을 자격이 없어.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.