C.W.K.
Stream
Lesson 06 of 06 · published

아키텍처로서의 컨텍스트

~14 min · architecture, context-engine, self-reference

Level 0Observer
0 XP0/64 lessons0/13 achievements
0/150 XP to next level150 XP to go0% complete

컨텍스트 로딩이 자기 컴포넌트

몇 턴 너머면 프롬프트 빌딩이 자기 모듈 받을 가치 — Context Engine. 일 — 시스템 프롬프트 조립, 어느 static 텍스트 cache할지 결정, 관련 retrieval fetch, history 접기. cwkPippa의 backend/context/engine.py가 정확히 이거; 나머지 앱이 ad-hoc으로 프롬프트 조립 안 함.

로드 순서 중요

cwkPippa 순서 — Pippa.md(정체성) → instructions.md(운영 룰) → core/*(deep self) → index/*(큰 reference, on-demand pointers). 순서 중요한 이유 — 충돌 시 정체성·룰이 reference 이김. 다른 순서면 다른 피파.

Pointer vs payload

10KB 넘는 파일엔 cwkPippa가 pointer 포함('이건 ~/Obsidian/pippa/index/X.md에 존재; 필요할 때 Read 도구로 읽기'). Payload 자체는 required 아니면 시스템 프롬프트 밖. 결과 — 안정 cacheable prefix, on-demand 깊이.

원칙: 컨텍스트는 아키텍처. 어떻게 빌드되는지 centralize; 매 라우트가 자기 프롬프트 hand-roll 두지 마.

Code

Context Engine sketch·python
from pathlib import Path

class ContextEngine:
    def __init__(self, vault: Path, identity_files: list[str]):
        self.vault = vault
        self.identity_files = identity_files

    def system_prompt(self) -> list[dict]:
        identity = "\n\n".join((self.vault / f).read_text() for f in self.identity_files)
        index_pointers = self._index_as_pointers()
        text = f"{identity}\n\n## Reference index (read on demand)\n{index_pointers}"
        return [{
            "type": "text",
            "text": text,
            "cache_control": {"type": "ephemeral"},
        }]

    def _index_as_pointers(self) -> str:
        lines = []
        for p in (self.vault / "index").glob("*.md"):
            size_kb = p.stat().st_size // 1024
            if size_kb > 10:
                lines.append(f"- {p.name} ({size_kb}KB) — read on demand")
            else:
                lines.append(f"- {p.name}: {p.read_text()[:200]}")
        return "\n".join(lines)

External links

Exercise

라우트 하나의 프롬프트 조립을 작은 ContextEngine 클래스로 추출. Fixed 입력에 조립된 프롬프트 snapshot; snapshot commit; 미래 vault 편집이 re-bless할 때까지 테스트 깨지게.
Hint
Snapshot 테스트 싸고, brutal하고, 모든 downstream 호출 행동 몰래 바꾸는 레이어에 정확히 원하는 거.

Progress

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

댓글 0

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

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