agent-rt

Local-first, agent-native developer tools.

View My GitHub Profile

Recipe: LLM-maintained wiki

A personal wiki where you curate raw sources and the LLM maintains the pages — summaries, entity pages, concept pages, and an auto-generated index. Inspired by Karpathy’s LLM Wiki design, but instead of loose markdown files this lives in a single Synap app with hybrid search and structured queries built in.

The core separation is by entity type within one app:

All six live in the same wiki app. Karpathy’s index.md becomes a query against wiki. No file to keep in sync; the catalog is always live.

1. Design the schema — one app, many types

{"tool": "init_app", "args": {
  "app": "wiki",
  "types": {
    "source": [
      {"name": "title",       "value_type": "string", "indexed": true, "required": true},
      {"name": "kind",        "value_type": "enum",
       "enum_values": ["article", "paper", "transcript", "note", "image"],
       "indexed": true, "required": true},
      {"name": "url",         "value_type": "string"},
      {"name": "body",        "value_type": "string", "vectorized": true},
      {"name": "captured_at", "value_type": "date",   "indexed": true, "default": "now"}
    ],
    "summary": [
      {"name": "slug",     "value_type": "string", "indexed": true, "required": true},
      {"name": "title",    "value_type": "string", "indexed": true, "vectorized": true, "required": true},
      {"name": "body",     "value_type": "string", "vectorized": true},
      {"name": "sources",  "value_type": "ref"},
      {"name": "tags",     "value_type": "array"},
      {"name": "updated",  "value_type": "date",   "indexed": true, "default": "now"}
    ],
    "entity": [
      {"name": "slug",     "value_type": "string", "indexed": true, "required": true},
      {"name": "title",    "value_type": "string", "indexed": true, "vectorized": true, "required": true},
      {"name": "body",     "value_type": "string", "vectorized": true},
      {"name": "related",  "value_type": "ref"},
      {"name": "tags",     "value_type": "array"},
      {"name": "updated",  "value_type": "date",   "indexed": true, "default": "now"}
    ],
    "concept": [
      {"name": "slug",     "value_type": "string", "indexed": true, "required": true},
      {"name": "title",    "value_type": "string", "indexed": true, "vectorized": true, "required": true},
      {"name": "body",     "value_type": "string", "vectorized": true},
      {"name": "related",  "value_type": "ref"},
      {"name": "tags",     "value_type": "array"},
      {"name": "updated",  "value_type": "date",   "indexed": true, "default": "now"}
    ],
    "comparison": [
      {"name": "slug",     "value_type": "string", "indexed": true, "required": true},
      {"name": "title",    "value_type": "string", "indexed": true, "vectorized": true, "required": true},
      {"name": "body",     "value_type": "string", "vectorized": true},
      {"name": "subjects", "value_type": "ref",    "required": true},
      {"name": "updated",  "value_type": "date",   "indexed": true, "default": "now"}
    ],
    "log": [
      {"name": "when",   "value_type": "date",   "indexed": true, "default": "now"},
      {"name": "action", "value_type": "enum",
       "enum_values": ["ingest", "summarize", "link", "update", "rename"],
       "indexed": true, "required": true},
      {"name": "target", "value_type": "ref"},
      {"name": "note",   "value_type": "string", "vectorized": true, "required": true}
    ]
  }
}}

Why one app:

ref fields (sources, related, subjects, target) are arrays under the hood — a summary can cite multiple sources, a concept can relate to multiple others. expand_refs follows them in one query.

2. Ingest flow

User drops a paper in.

I just read this paper. Add it and summarize. [paper contents]

{"tool": "write", "args": {
  "app": "wiki",
  "ops": [
    {"op": "create", "type": "source",
     "data": {"title": "Attention Is All You Need",
              "kind":  "paper",
              "url":   "https://arxiv.org/abs/1706.03762",
              "body":  "…full paper text…"},
     "returning": ["entity_id"]},
    {"op": "create", "type": "entity",
     "data": {"slug":  "entity/vaswani-ashish",
              "title": "Ashish Vaswani",
              "body":  "Co-author of …"}},
    {"op": "create", "type": "concept",
     "data": {"slug":  "concept/self-attention",
              "title": "Self-attention",
              "body":  "A mechanism where each token …"}}
  ]
}}
// → source_id = src_abc, entity_id = ent_v1, concept_id = cpt_sa

Then wire the summary (it needs the source_id) + log entry atomically:

{"tool": "write", "args": {
  "app": "wiki",
  "ops": [
    {"op": "create", "type": "summary",
     "data": {"slug":    "summary/attention-is-all-you-need",
              "title":   "Summary: Attention Is All You Need",
              "body":    "Introduces the Transformer architecture…",
              "sources": ["wiki/src_abc"],
              "tags":    ["transformers", "architecture"]}},
    {"op": "create", "type": "log",
     "data": {"action": "ingest",
              "target": "wiki/src_abc",
              "note":   "Ingested Attention paper; created 1 summary, 1 entity, 1 concept page."}}
  ]
}}

returning: ["entity_id"] on the source create avoids a follow-up query just to get the id. The log entry carries a ref to the source because the ingest is about the source; downstream refinements can log their own entries pointing at the specific summary or concept they edit.

3. The live index (replaces index.md)

By category

{"tool": "query", "args": {
  "app":      "wiki",
  "filters":  [{"field": "entity_type", "op": "in",
                "value": ["summary", "entity", "concept", "comparison"]}],
  "select":   ["slug", "title", "entity_type", "updated"],
  "order_by": [{"field": "entity_type", "direction": "asc"},
               {"field": "updated",     "direction": "desc"}],
  "limit":    200
}}

(Excluding source and log from the page index — those are their own views below.)

Page counts per type

{"tool": "query", "args": {
  "app":       "wiki",
  "aggregate": [{"fn": "count", "as": "n"}],
  "group_by":  "entity_type"
}}
// TSV: key         n
//      source      27
//      summary     14
//      entity      31
//      concept     22
//      comparison  3
//      log         98

Recent activity

{"tool": "query", "args": {
  "app":      "wiki",
  "type":     "log",
  "order_by": [{"field": "when", "direction": "desc"}],
  "limit":    20,
  "select":   ["when", "action", "note"]
}}

4. Search — meaning, not just filename

Cross-type search over the whole wiki:

{"tool": "search", "args": {
  "app":        "wiki",
  "query_text": "attention mechanism",
  "rank":       "relevance",
  "limit":      10
}}

“What did I add recently about transformers?”

Hybrid freshness + similarity:

{"tool": "search", "args": {
  "app":        "wiki",
  "query_text": "transformers",
  "rank":       "time_decay",
  "limit":      10
}}

Scope to one type

{"tool": "search", "args": {
  "app":        "wiki",
  "type":       "concept",
  "query_text": "positional encoding",
  "rank":       "relevance"
}}

“Show me the sources behind this summary page”

{"tool": "query", "args": {
  "app":         "wiki",
  "type":        "summary",
  "filters":     [{"field": "slug", "op": "eq", "value": "summary/attention-is-all-you-need"}],
  "expand_refs": 1,
  "select":      ["title", "sources.title", "sources.url"]
}}

One call returns the page title plus the title + URL of every cited source. The _ref / _entity_id sentinels that expand_refs adds by default are dropped when you project dot-paths, so the response stays lean.

{"tool": "query", "args": {
  "app":     "wiki",
  "filters": [{"field": "sources", "op": "ref_to", "value": "src_abc"}],
  "select":  ["slug", "title", "entity_type"]
}}

No type filter — any page whose sources points at src_abc comes back, regardless of whether it’s a summary or a comparison.

Orphaned pages (no incoming cross-references)

{"tool": "query", "args": {
  "app":     "wiki",
  "filters": [
    {"field": "entity_type", "op": "in", "value": ["summary", "entity", "concept", "comparison"]},
    {"field": "",            "op": "orphan", "value": true}
  ],
  "select":  ["slug", "title", "entity_type", "updated"]
}}

6. The LLM-as-maintainer loop

When the user adds a new source, the agent should:

  1. write wiki — stash the source (always keep the original).
  2. Read existing context: search wiki for related pages.
  3. Decide what to create or update:
    • New concept → new concept page.
    • Existing concept gets new evidence → update its body, append a log event.
    • Contradiction found → update both sides, log a rename / update.
  4. Wire cross-references: related, sources, subjects refs.
  5. One log entry per logical action (not per SQL write).

Because everything is in one app, the whole step can be a single atomic write batch when the agent knows all the target ids up front.

Design tips