Skip to main content
Two stages turn a raw source into knowledge a campaign can search: ingestors extract structured wiki pages from each source, then the merger folds those pages into the graph. learn_knowledge() runs both.

How do I run the pipeline?

Full pipeline

index_builder builds the wiki’s search index when it has none yet (the first merge into a fresh wiki_dir); Kapso.index_kg reads the search backends and the collection from the config. kapso.learn_knowledge() wires this itself.

Via Kapso API

Extract only (no merge)

What can I ingest?

The Source namespace provides typed wrappers for knowledge inputs:

Stage 1: Ingestors

Ingestors extract WikiPages from sources. Each source type has a dedicated ingestor.

IngestorFactory

RepoIngestor

The most sophisticated ingestor, using a two-branch multi-phase pipeline: Phase 0: Repository Understanding (pre-phase)
  • Parse repo structure, generate _RepoMap.md with AST info
  • Agent fills in natural language understanding for each file
  • Subsequent phases read this file instead of re-exploring
Branch 1: Workflow-Based Extraction
  • Phase 1a: Anchoring - Find workflows from README/examples, write Workflow pages + rough WorkflowIndex
  • Phase 1b: Anchoring Context - Enrich WorkflowIndex with detailed implementation context
  • Phase 2: Excavation+Synthesis - Trace imports, write Implementation-Principle pairs together
  • Phase 3: Enrichment - Mine constraints/tips, write Environment/Heuristic pages
  • Phase 4: Audit - Validate graph integrity, fix broken links
  • Phase 4b: Repo Builder - Publish each Workflow as a runnable GitHub repository. Runs after the deterministic validation, and only when learner.ingestor.publish_workflows is on (or github_org / is_private is passed); gh authenticates with GH_TOKEN
Branch 2: Orphan Mining (runs after Branch 1)
  • Phase 5a: Triage (code) - Deterministic filtering into AUTO_KEEP/AUTO_DISCARD/MANUAL_REVIEW
  • Phase 5b: Review (agent) - Agent evaluates MANUAL_REVIEW files
  • Phase 5c: Create (agent) - Agent creates wiki pages for approved files
  • Phase 6: Orphan Audit - Validate orphan nodes
  • Phase 6b: Verify (code) - Every file that must get a page is marked done and every review has a decision; undone work gets one targeted audit pass with the findings, and the run fails if any remains
Sessions. Every phase is a Claude Code session holding five file tools (Read, Write, Edit, Glob, Grep) and, for the merge, the knowledge tools, and nothing else: the built-in set is pinned with the CLI’s --tools flag and only Kapso’s own MCP servers are mounted, so a repository’s code or README cannot make the session run anything, reach the network, delegate to a sub-agent or touch the account’s connectors. The one exception is the Repo Builder, which also gets Bash for git and gh. Staging and resume. A run stages everything under <wiki_dir>/_staging/<repo>/<branch>: the clone, the repository map, the phase reports and the pages, which are copied into wiki_dir at the end. Each finished phase leaves a marker in _phases/. A run that stops, on a failed phase or a killed process, keeps the directory, and learning the same source again continues from the first unfinished phase; a completed run’s directory is replaced by the next run of that source. cleanup removes the clone when a run completes, cleanup_staging the whole directory.

Research ingestors

Research ingestors convert web research results into WikiPages using a three-phase agentic pipeline: Phase 1: Planning
  • Analyzes content and decides what pages to create
  • Writes _plan.md with page decisions
Phase 2: Writing
  • Creates wiki pages following section definitions
  • Writes pages to staging directory
Phase 3: Auditing
  • Validates pages and fixes issues
  • Ensures graph integrity
There are three specialized research ingestors:

Stage 2: Knowledge merger

The merger uses a hierarchical sub-graph-aware algorithm with a single Claude Code agent call. It processes connected pages as units, respecting the knowledge graph DAG structure.

Wiki hierarchy

The Knowledge Graph follows a top-down DAG structure:

Merge algorithm

The merger executes a 5-phase process: Phase 1: Sub-Graph Detection
  • Parses outgoing_links to build an adjacency list
  • Finds root nodes (no incoming edges from proposed pages)
  • Groups connected components into sub-graphs
Phase 2: Planning (Top-Down)
  • For each sub-graph, makes merge decisions starting from root:
    • Root decision: Search for similar pages of same type → MERGE or CREATE_NEW
    • Children decisions (recursive):
      • If parent = CREATE_NEW → child inherits CREATE_NEW (no search needed)
      • If parent = MERGE → search only among target’s children → MERGE or CREATE_NEW
    • Special case: Heuristics with multiple parents use lowest parent for scoped search
  • Computes execution order (bottom-up): Environment → Heuristic → Implementation → Principle
  • Records deferred edges (which parent adds edge after processing)
Phase 3: Execution (Bottom-Up)
  • Processes nodes in computed order
  • For CREATE_NEW: Get page structure, prepare content, call kg_index
  • For MERGE: Get page structure, fetch target, merge content intelligently, call kg_edit
  • Updates outgoing_links to point to processed children’s result_page_id
Phase 4: Audit
  • Verifies nodes exist (CREATE_NEW/MERGE)
  • Verifies edges (parent has edge to child’s result_page_id)
  • Handles failures with retries (max 3)
Phase 5: Finalize
  • Collects all result_page_id values
  • Categorizes as created (CREATE_NEW) or edited (MERGE)
  • Writes final summary to _merge_plan.md

Edge types

Merge rules

Beyond the phase mechanics above: search is same-type only (Principles among Principles, never a Principle merged with an Implementation), and a merge keeps existing edges, only ever adding new ones.

MCP tools used

The merger uses these MCP tools via the kg-graph-search server:

Using the merger

Merge modes

The merger operates in two modes based on whether a KG index exists:
  1. No Index Mode: Creates all pages as new, writes to wiki directory, then builds the index through index_builder (a merger without one fails here)
  2. Merge Mode: Runs agentic hierarchical merge using MCP tools
In merge mode the result is settled from the store after the session, not from the plan file the session writes: created are the proposed pages the store now holds, edited the pages the session’s kg_edit calls named, and the remaining proposed pages were folded into those, so their files (published into wiki_dir before the merge) are removed and the index file’s page count follows the store. A page the session indexed that the store does not hold fails the merge, as does a proposed page that vanished while nothing was edited. Index detection order:
  1. Explicit kg_index_path from config
  2. Auto-detect .index file in wiki directory

Merge result

WikiPage structure

How do I run it from the CLI?

The command runs Kapso.learn_knowledge(), so the preflight, the models and the search backends come from the config.

CLI options

What does it return?

Knowledge graph

What the graph holds

Search backends

How it is queried
Related pages: Knowledge graph · Search backends · Knowledge graph Kapso is an open-source framework by Leeroo that builds software toward measurable goals through experiment campaigns. Source code: github.com/Leeroo-AI/kapso · Install: pip install leeroo-kapso · Every page as plain text: llms.txt.