Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Cache the claude backend system prompt via Anthropic prompt caching

Đang mở Phù hợp với người mới
#4,835 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@Jvxoq đang làm issue này rồi.

Từ ngày 29/10/2026.

  • #4855 của @Jvxoq — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
76/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
ai, performance

Hướng nghiên cứu

Bắt đầu tại graphify/llm.py, ở _call_claude(), và xem Anthropic SDK chấp nhận các khối nội dung hệ thống có cache_control như thế nào. Áp dụng bộ nhớ đệm cho prompt hệ thống trích xuất như mô tả, sau đó xác minh rằng lời gọi vẫn sử dụng cùng prompt và nội dung thông điệp. Issue xác định hoàn thành là bật bộ nhớ đệm prompt cho backend Claude gốc mà không thay đổi đầu ra.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Summary

extract --backend claude issues one messages.create call per file, and each call re-sends the fixed _extraction_system prompt at full input price. Marking the system block with Anthropic prompt caching (cache_control: ephemeral) bills that shared prefix at ~0.1× on reads after the first call. Output is unchanged — this is a billing/latency optimization only.

Where

graphify/llm.py, _call_claude() — system= is passed as a plain string, so the extraction system prompt is re-ingested on every per-file call.

Proposed change
diff
resp = client.messages.create(
model=model,
max_tokens=max_tokens,

  •    system=_extraction_system(deep=deep_mode),
    
  •    system=[{
    
  •        "type": "text",
    
  •        "text": _extraction_system(deep=deep_mode),
    
  •        "cache_control": {"type": "ephemeral"},
    
  •    }],
       messages=[{"role": "user", "content": _anthropic_content(user_message, images or [])}],
    
    )

The anthropic SDK already in use supports the content-block form of system with cache_control.

Why it helps

_extraction_system is identical across all per-file calls (only deep toggles). On a repo with N files the system prefix is paid N× at 1×; with caching it’s one write (1.25×) + (N−1) reads (0.1×) → ~90% off the system portion of input.

Caveats (for reviewers)
Only the system block is cacheable here; per-file user content isn’t reused.
Needs the system prompt ≥ the model’s min cacheable length (e.g. 512 tokens on recent Sonnet/Opus); below that it silently no-ops (cache_*_input_tokens = 0), no error.
With --max-concurrency > 1 the first wave of parallel calls misses (a cache entry is only available after the first response begins) — still a net win on multi-file runs.
5-min ephemeral TTL refreshes on each hit, so it stays warm through an active extraction.
Scoped to the native claude backend; the Bedrock path (system=[{"text": ...}]) uses a different caching mechanism and could be a follow-up.
Impact

Billing/latency only. No behavior change.

Ngôn ngữ chính
Python
Star
124k
Fork
11.9k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Graphify-Labs/graphify

Tất cả issue của Graphify-Labs/graphify

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.