Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:0xranx OpenContext Context Discovery

From Leeroopedia
Knowledge Sources
Domains Information_Retrieval, Knowledge_Management
Last Updated 2026-10-24 12:00 GMT

Overview

A workflow principle for systematically discovering and loading relevant background context from a knowledge base before starting or resuming a task, combining folder enumeration, semantic search, manifest generation, and document reading.

Description

Context discovery addresses the "cold start" problem in knowledge work: when an agent begins a task, it needs to understand what relevant knowledge already exists. Without a structured discovery process, agents either miss critical context or waste time reading irrelevant documents.

The principle defines a four-stage discovery pipeline:

  1. Folder Discovery: Enumerate available knowledge spaces (folders) to understand the organizational structure of the knowledge base.
  2. Candidate Search: Use semantic search to narrow down relevant documents from the potentially large corpus, returning ranked results with relevance scores.
  3. Manifest Generation: Produce a structured file list for a specific folder, including relative paths, descriptions, stable links, and absolute paths — giving the agent a batch view of available documents.
  4. Document Reading: Load specific document content by path for detailed analysis.
  5. Citation and Summary: Resolve stable IDs and generate stable links for citing sources in the agent's output.

The principle emphasizes safe discovery: search and manifest operations are read-only and do not trigger index builds (which may incur external embedding API costs).

Usage

Use this principle when an AI agent or developer needs to load background context before starting work. It is the standard entry point for any task that requires understanding existing knowledge. The discovery process should be run at the start of a task and whenever the task scope changes and new context is needed.

Theoretical Basis

The context discovery pipeline follows a funnel model:

Corpus→foldersSpaces→searchCandidates→manifestFile List→readContext

Each stage narrows the scope:

  • Folders reduce the corpus to relevant knowledge spaces.
  • Search ranks documents by relevance to the query.
  • Manifest provides metadata (descriptions, stable links) for triage.
  • Reading loads actual content for the most promising candidates.

Pseudo-code Logic:

# Abstract algorithm (NOT real implementation)
def discover_context(query, target_folder=None):
    # Stage 1: Discover folders if target unknown
    if not target_folder:
        folders = store.list_folders(all=True)
        target_folder = choose_folder(folders)

    # Stage 2: Search for candidates (read-only, no index build)
    candidates = searcher.search(query, limit=10, mode="hybrid")

    # Stage 3: Generate manifest for the target folder
    manifest = store.generate_manifest(folder_path=target_folder, limit=10)

    # Stage 4: Read the most relevant documents
    for entry in manifest:
        content = read_file(entry.abs_path)
        yield entry, content

    # Stage 5: Generate citations
    for entry in manifest:
        meta = store.get_doc_meta(entry.rel_path)
        stable_link = f"oc://doc/{meta.stable_id}"
        yield stable_link

Practical Guide

  • Start with folder listing: If the target space is unknown, list all folders first (`oc folder ls --all`).
  • Use search before manifest: When unsure which docs to read, search first to narrow candidates, then use the manifest for the relevant folder.
  • Cite with stable links: Always generate stable links (`oc://doc/<stable_id>`) for citations so links survive renames and moves.
  • Avoid index builds: Search may fail if no index exists; fall back to manifest + keyword matching rather than building the index (which costs API credits).

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment