Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Cache the claude backend system prompt via Anthropic prompt caching

Abierto Apto para principiantes
#4,835 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@Jvxoq ya está trabajando en esto.

Desde el 29/10/2026.

  • #4855 de @Jvxoq — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
76/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
ai, performance

Línea de trabajo

Empieza en graphify/llm.py, en _call_claude(), y revisa cómo acepta el SDK de Anthropic bloques de contenido del sistema con cache_control. Aplica el almacenamiento en caché al prompt del sistema de extracción tal como se describe y, después, verifica que la llamada siga usando el mismo prompt y contenido del mensaje. El issue define como completado habilitar el almacenamiento en caché de prompts para el backend nativo de Claude sin cambiar la salida.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
124k
Forks
11.9k
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Graphify-Labs/graphify

Todos los issues de Graphify-Labs/graphify

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.