Mini Context Graph Skill
When to invoke
- "Ingest these documents into a persistent knowledge graph."
- "Query the mini context graph with evidence."
- "Write wiki pages from extracted entities and relations."
- "Lint the local wiki for broken wikilinks."
The Core Idea
Standard RAG re-discovers knowledge from scratch on every query. This skill is different:
- Wiki layer — The LLM writes and maintains persistent markdown pages (summaries, entity pages, topic syntheses). Cross-references are already there. The wiki gets richer with every ingest.
- Graph layer — Entities and relations are extracted once and stored as a navigable knowledge graph. BFS traversal answers structural queries without re-reading sources.
- Raw source layer — Original documents are stored immutably with chunks. Provenance links tie every graph node and edge back to the exact text that supports it.
The LLM writes; the Python tools handle all bookkeeping.
Three Layers
| Layer |
Where |
What the LLM does |
What Python does |
| Raw Sources |
data/documents.json |
Reads (never modifies) |
Stores chunks + metadata |
| Wiki |
wiki/ (markdown) |
Writes/updates pages |
Manages index.md + log.md |
| Graph |
data/graph.json |
Extracts entities + relations |
Persists, deduplicates, traverses |
Quick Start for Agents
A complete runnable version of this workflow is in scripts/template_agent_workflow.py — copy and adapt it.
from scripts.contextgraph import ContextGraphSkill
from scripts.tools import wiki_store
skill = ContextGraphSkill()
# ===== INGEST WITH FULL RAG + WIKI =====
# 1. Read references/ingestion.md and references/ontology.md first
# 2. Extract entities and relations (LLM reasoning step)
entities = [
{"name": "memory leak", "type": "issue", "supporting_text": "memory leaks cause crashes"},
{"name": "system crash", "type": "issue", "supporting_text": "system crashes due to memory leaks"},
]
relations = [
{"source": "memory leak", "target": "system crash", "type": "causes",
"confidence": 1.0, "supporting_text": "System crashes due to memory leaks."},
]
result = skill.ingest_with_content(
doc_id="doc_001",
title="System Crash Analysis",
source="/docs/incident_report.pdf",
raw_content="System crashes due to memory leaks. Memory leaks occur when objects are not released.",
entities=entities,
relations=relations,
)
# result = {"doc_id": "doc_001", "chunk_count": 1, "nodes_added": 2, "edges_added": 1}
# 3. Write a wiki summary page for this document
wiki_store.write_page(
category="summary",
title="System Crash Analysis Summary",
content="""---
title: System Crash Analysis
source_document: doc_001
tags: [summary, incident]
---
# System Crash Analysis
**Source:** incident_report.pdf
## Key Claims
- [[memory-leak]] causes [[system-crash]] (confidence: 1.0)
## Entities
- [[memory-leak]] (issue)
- [[system-crash]] (issue)
""",
summary="Incident report: memory leaks cause system crashes.",
)
# ===== QUERY WITH EVIDENCE =====
result = skill.query_with_evidence("Why does the system crash?")
# Returns: {"query": ..., "subgraph": ..., "supporting_documents": [...], "evidence_chain": ...}
# ===== WIKI SEARCH (read wiki before answering) =====
pages = wiki_store.search_wiki("memory leak")
# Returns: [{slug, category, path, snippet}, ...]
Operations
Ingest
When a user provides a new document:
- Read
references/ingestion.md — entity/relation extraction rules.
- Read
references/ontology.md — type normalization rules.
- Extract entities and relations using your LLM reasoning.
- Call
skill.ingest_with_content(...) — stores raw content + chunks + graph nodes + provenance.
- Write a wiki summary page using
wiki_store.write_page(category="summary", ...).
- Update entity pages — for each new/updated entity, write or update
wiki_store.write_page(category="entity", ...).
- Update topic pages if the document touches an existing synthesis topic.
- A single document ingest will typically touch 3–10 wiki pages.
Query
When a user asks a question:
- Check the wiki first —
wiki_store.search_wiki(query) to find relevant pages. Read them.
- If the wiki has a good answer, synthesize from wiki pages (fast path).
- If deeper graph traversal is needed, call
skill.query_with_evidence(query).
- Return the answer with evidence citations from
supporting_documents.
- If the answer is valuable, file it back as a new wiki topic page.
Lint
Periodically health-check the wiki:
from scripts.tools import wiki_store
issues = wiki_store.lint_wiki()
# Returns: {orphan_pages, missing_pages, broken_wikilinks, isolated_pages}
Ask the LLM to review and fix: broken links, orphan pages, stale claims, missing cross-references. See references/lint.md for full lint workflow.
Ingestion Constraints
- Do NOT hallucinate entities not present in the text
- Do NOT add relations without explicit textual evidence
- Do NOT add edges with confidence < 0.6
- Provide
supporting_text for every entity and relation — this enables provenance
- Write a wiki summary page for every ingested document
- Update existing entity pages when new information arrives
- Flag contradictions in wiki pages when new data conflicts with old claims
Retrieval Constraints
- Traversal depth MUST NOT exceed 2 (config: MAX_GRAPH_DEPTH)
- Only edges with confidence ≥ 0.6 (config: MIN_CONFIDENCE)
- Maximum 50 nodes returned (config: MAX_NODES)
- Do NOT fabricate nodes or edges not in the graph
Full Python API Reference
| Method |
Purpose |
When to Use |
skill.ingest_with_content(doc_id, title, source, raw_content, entities, relations) |
Full RAG ingest: raw docs + graph + provenance |
Every new document |
skill.add_node(name, node_type) |
Add single entity (no provenance) |
Quick additions without a source doc |
skill.add_edge(source_name, target_name, relation, confidence) |
Add single relation |
Quick additions without a source doc |
skill.query(query) |
Graph-only retrieval → subgraph |
Structural queries |
skill.query_with_evidence(query) |
Graph + provenance → subgraph + source chunks |
Queries requiring citations |
wiki_store.write_page(category, title, content, summary) |
Write/update a wiki page |
After every ingest; after answering queries |
wiki_store.read_page(category, title) |
Read a wiki page |
Before answering; for cross-referencing |
wiki_store.search_wiki(query) |
Keyword search across wiki |
Fast path before graph traversal |
wiki_store.list_pages(category) |
List all wiki pages |
Getting an overview |
wiki_store.get_log(last_n) |
Read recent operations |
Understanding wiki history |
wiki_store.lint_wiki() |
Health check |
Periodic maintenance |
documents_store.list_documents() |
List all ingested raw sources |
Audit / provenance checking |
documents_store.search_chunks(query) |
Chunk-level search |
Finding specific evidence |
Design Philosophy
"The wiki is a persistent, compounding artifact. The cross-references are already there. The synthesis already reflects everything you've read." — Karpathy
| Layer |
What Happens |
Who Owns It |
| LLM Reasoning |
Extraction, synthesis, writing wiki pages |
Agent (.md guidance files) |
| Wiki Persistence |
Index, log, file I/O |
wiki_store.py |
| Graph Persistence |
Dedup, index, BFS traverse |
graph_store.py, retrieval_engine.py |
| Raw Source Storage |
Immutable docs + chunks + provenance |
documents_store.py |
The human curates sources and asks questions. The LLM writes the wiki, extracts the graph, and answers with citations. Python handles all bookkeeping.
Progressive disclosure and bundled resources
At discovery time, only name and description are loaded. Read or execute bundled resources only when the current task needs them.
references/ingestion.md, references/ontology.md, references/retrieval.md, and references/lint.md: extraction, normalization, retrieval, and lint guidance.
scripts/template_agent_workflow.py, scripts/contextgraph.py, scripts/config.py, and scripts/tools/: runnable workflow and storage APIs.
Output template
## Mini context graph result
**Status:** ingested | answered | linted | blocked
**Operation:** <ingest | query | lint>
**Source/query:** `<doc_id, source path, or user question>`
### Evidence
- Documents: <supporting_documents or ingested sources>
- Entities: <entity names and types>
- Relations: <source -> relation -> target with confidence>
### Wiki updates
- `<wiki page>`: <created | updated | read | unchanged>
Quality gate
1---2name: mini-context-graph3description: A persistent, compounding knowledge base combining Karpathy's LLM Wiki pattern with a structured knowledge graph. Ingest documents once — the LLM writes wiki pages, extracts entities/relations into the graph, and stores raw content for evidence retrieval. Knowledge accumulates and cross-references; it is never re-derived from scratch. Use this skill when |--------|---------|-------------|; | `skill.ingest_with_content(doc_id, title, source, raw_content, entities, relations)` | Full RAG ingest: raw docs + graph + provenance |; | `skill.add_node(name, node_type)` | Add single entity (no provenance) | Quick additions without a source doc |.4---56<!-- Generated from harness/github-copilot/skills/mini-context-graph/SKILL.md by harness/claude-code/scripts/convert_from_copilot.py. Edit the source, not this file. -->78# Mini Context Graph Skill910## When to invoke1112- "Ingest these documents into a persistent knowledge graph."13- "Query the mini context graph with evidence."14- "Write wiki pages from extracted entities and relations."15- "Lint the local wiki for broken wikilinks."1617## The Core Idea1819Standard RAG re-discovers knowledge from scratch on every query. This skill is different:20211. **Wiki layer** — The LLM writes and maintains persistent markdown pages (summaries, entity pages, topic syntheses). Cross-references are already there. The wiki gets richer with every ingest.222. **Graph layer** — Entities and relations are extracted once and stored as a navigable knowledge graph. BFS traversal answers structural queries without re-reading sources.233. **Raw source layer** — Original documents are stored immutably with chunks. Provenance links tie every graph node and edge back to the exact text that supports it.2425> The LLM writes; the Python tools handle all bookkeeping.2627---2829## Three Layers3031| Layer | Where | What the LLM does | What Python does |32|-------|-------|-------------------|-----------------|33| **Raw Sources** | `data/documents.json` | Reads (never modifies) | Stores chunks + metadata |34| **Wiki** | `wiki/` (markdown) | Writes/updates pages | Manages index.md + log.md |35| **Graph** | `data/graph.json` | Extracts entities + relations | Persists, deduplicates, traverses |3637---3839## Quick Start for Agents4041A complete runnable version of this workflow is in `scripts/template_agent_workflow.py` — copy and adapt it.4243```python44from scripts.contextgraph import ContextGraphSkill45from scripts.tools import wiki_store4647skill = ContextGraphSkill()4849# ===== INGEST WITH FULL RAG + WIKI =====50# 1. Read references/ingestion.md and references/ontology.md first51# 2. Extract entities and relations (LLM reasoning step)52entities = [53 {"name": "memory leak", "type": "issue", "supporting_text": "memory leaks cause crashes"},54 {"name": "system crash", "type": "issue", "supporting_text": "system crashes due to memory leaks"},55]56relations = [57 {"source": "memory leak", "target": "system crash", "type": "causes",58 "confidence": 1.0, "supporting_text": "System crashes due to memory leaks."},59]6061result = skill.ingest_with_content(62 doc_id="doc_001",63 title="System Crash Analysis",64 source="/docs/incident_report.pdf",65 raw_content="System crashes due to memory leaks. Memory leaks occur when objects are not released.",66 entities=entities,67 relations=relations,68)69# result = {"doc_id": "doc_001", "chunk_count": 1, "nodes_added": 2, "edges_added": 1}7071# 3. Write a wiki summary page for this document72wiki_store.write_page(73 category="summary",74 title="System Crash Analysis Summary",75 content="""---76title: System Crash Analysis77source_document: doc_00178tags: [summary, incident]79---8081# System Crash Analysis8283**Source:** incident_report.pdf8485## Key Claims8687- [[memory-leak]] causes [[system-crash]] (confidence: 1.0)8889## Entities9091- [[memory-leak]] (issue)92- [[system-crash]] (issue)93""",94 summary="Incident report: memory leaks cause system crashes.",95)9697# ===== QUERY WITH EVIDENCE =====98result = skill.query_with_evidence("Why does the system crash?")99# Returns: {"query": ..., "subgraph": ..., "supporting_documents": [...], "evidence_chain": ...}100101# ===== WIKI SEARCH (read wiki before answering) =====102pages = wiki_store.search_wiki("memory leak")103# Returns: [{slug, category, path, snippet}, ...]104```105106---107108## Operations109110### Ingest111112When a user provides a new document:1131141. Read `references/ingestion.md` — entity/relation extraction rules.1152. Read `references/ontology.md` — type normalization rules.1163. Extract entities and relations using your LLM reasoning.1174. Call `skill.ingest_with_content(...)` — stores raw content + chunks + graph nodes + provenance.1185. **Write a wiki summary page** using `wiki_store.write_page(category="summary", ...)`.1196. **Update entity pages** — for each new/updated entity, write or update `wiki_store.write_page(category="entity", ...)`.1207. **Update topic pages** if the document touches an existing synthesis topic.1218. A single document ingest will typically touch 3–10 wiki pages.122123### Query124125When a user asks a question:1261271. **Check the wiki first** — `wiki_store.search_wiki(query)` to find relevant pages. Read them.1282. If the wiki has a good answer, synthesize from wiki pages (fast path).1293. If deeper graph traversal is needed, call `skill.query_with_evidence(query)`.1304. Return the answer with evidence citations from `supporting_documents`.1315. If the answer is valuable, file it back as a new wiki topic page.132133### Lint134135Periodically health-check the wiki:136137```python138from scripts.tools import wiki_store139issues = wiki_store.lint_wiki()140# Returns: {orphan_pages, missing_pages, broken_wikilinks, isolated_pages}141```142143Ask the LLM to review and fix: broken links, orphan pages, stale claims, missing cross-references. See `references/lint.md` for full lint workflow.144145---146147## Ingestion Constraints148149- Do NOT hallucinate entities not present in the text150- Do NOT add relations without explicit textual evidence151- Do NOT add edges with confidence < 0.6152- Provide `supporting_text` for every entity and relation — this enables provenance153- Write a wiki summary page for every ingested document154- Update existing entity pages when new information arrives155- Flag contradictions in wiki pages when new data conflicts with old claims156157---158159## Retrieval Constraints160161- Traversal depth MUST NOT exceed 2 (config: MAX_GRAPH_DEPTH)162- Only edges with confidence ≥ 0.6 (config: MIN_CONFIDENCE)163- Maximum 50 nodes returned (config: MAX_NODES)164- Do NOT fabricate nodes or edges not in the graph165166---167168## Full Python API Reference169170| Method | Purpose | When to Use |171|--------|---------|-------------|172| `skill.ingest_with_content(doc_id, title, source, raw_content, entities, relations)` | Full RAG ingest: raw docs + graph + provenance | Every new document |173| `skill.add_node(name, node_type)` | Add single entity (no provenance) | Quick additions without a source doc |174| `skill.add_edge(source_name, target_name, relation, confidence)` | Add single relation | Quick additions without a source doc |175| `skill.query(query)` | Graph-only retrieval → subgraph | Structural queries |176| `skill.query_with_evidence(query)` | Graph + provenance → subgraph + source chunks | Queries requiring citations |177| `wiki_store.write_page(category, title, content, summary)` | Write/update a wiki page | After every ingest; after answering queries |178| `wiki_store.read_page(category, title)` | Read a wiki page | Before answering; for cross-referencing |179| `wiki_store.search_wiki(query)` | Keyword search across wiki | Fast path before graph traversal |180| `wiki_store.list_pages(category)` | List all wiki pages | Getting an overview |181| `wiki_store.get_log(last_n)` | Read recent operations | Understanding wiki history |182| `wiki_store.lint_wiki()` | Health check | Periodic maintenance |183| `documents_store.list_documents()` | List all ingested raw sources | Audit / provenance checking |184| `documents_store.search_chunks(query)` | Chunk-level search | Finding specific evidence |185186---187188## Design Philosophy189190> "The wiki is a persistent, compounding artifact. The cross-references are already there. The synthesis already reflects everything you've read." — Karpathy191192| Layer | What Happens | Who Owns It |193|-------|-----------|-------------|194| **LLM Reasoning** | Extraction, synthesis, writing wiki pages | Agent (.md guidance files) |195| **Wiki Persistence** | Index, log, file I/O | `wiki_store.py` |196| **Graph Persistence** | Dedup, index, BFS traverse | `graph_store.py`, `retrieval_engine.py` |197| **Raw Source Storage** | Immutable docs + chunks + provenance | `documents_store.py` |198199The human curates sources and asks questions. The LLM writes the wiki, extracts the graph, and answers with citations. Python handles all bookkeeping.200201202## Progressive disclosure and bundled resources203204At discovery time, only `name` and `description` are loaded. Read or execute bundled resources only when the current task needs them.205206- `references/ingestion.md`, `references/ontology.md`, `references/retrieval.md`, and `references/lint.md`: extraction, normalization, retrieval, and lint guidance.207- `scripts/template_agent_workflow.py`, `scripts/contextgraph.py`, `scripts/config.py`, and `scripts/tools/`: runnable workflow and storage APIs.208209## Output template210211```markdown212## Mini context graph result213214**Status:** ingested | answered | linted | blocked215**Operation:** <ingest | query | lint>216**Source/query:** `<doc_id, source path, or user question>`217218### Evidence219- Documents: <supporting_documents or ingested sources>220- Entities: <entity names and types>221- Relations: <source -> relation -> target with confidence>222223### Wiki updates224- `<wiki page>`: <created | updated | read | unchanged>225```226227## Quality gate228229- [ ] Every entity and relation includes explicit `supporting_text`.230- [ ] No relation below `MIN_CONFIDENCE` or confidence 0.6 was added.231- [ ] Every new document called `skill.ingest_with_content(...)` and wrote a summary page.232- [ ] Query answers searched the wiki before graph traversal and cite evidence.