AgentSkillsCN

context-tree

采用层次化摘要树,实现高效的上下文检索——通过导航摘要,仅提取相关片段,而非加载全部内容。

SKILL.md
--- frontmatter
name: context-tree
description: Hierarchical summary tree for efficient context retrieval — navigates summaries to pull only relevant chunks instead of loading everything.

Context Tree — Retrieval Skill

You have access to a context tree that indexes the user's stored context (memories, tool configs, project details, preferences, etc.). Use it to pull only the relevant context for each request instead of loading everything.

How It Works

The context tree is a navigation index, not the storage itself. It contains short summaries and references to full context chunks stored separately. Your job is to read the tree, decide which chunks are relevant, and pull only those.

Retrieval Procedure

Step 1: Read the tree

Read tree.json. It contains a map of nodes, each with:

  • summary — short description of what context this branch covers
  • tags — keywords for quick matching
  • children — sub-branches (if any)
  • chunk_ids — references to full context files (leaf nodes)
  • total_tokens — approximate token count of the referenced chunks

The root node's summary gives you an overview of all available context.

Step 2: Select relevant branches

Given the user's request, decide which branches are relevant:

  1. Match by summary and tags — scan summaries and tags for relevance to the request.
  2. Apply the chunk threshold — check config.json for chunk_threshold (default: 4000 tokens).
    • If a branch's total_tokens <= threshold: pull all its chunks directly.
    • If a branch's total_tokens > threshold AND it has children: drill into children and repeat.
    • If a branch's total_tokens > threshold AND no children: pull its chunks anyway (it's a leaf).
  3. Skip irrelevant branches entirely — don't pull context that clearly doesn't relate to the request.

Step 3: Pull the chunks

For each selected chunk_id, read the corresponding file from the chunks/ directory (e.g., chunks/chunk_001.md).

Step 4: Use the context

Include the retrieved chunks as context for handling the user's request. Do not include chunks that aren't relevant — less noise means better results.

Rules

  • Two-call target: Aim to complete navigation in a single read (tree.json + selected chunks), then handle the task. Avoid multi-round drilling unless the tree is very large.
  • Don't guess: If a summary is ambiguous, pull the chunk to check rather than assuming relevance.
  • Prefer recall over precision: It's better to pull a slightly-irrelevant chunk than to miss a relevant one. Missed context is a silent failure.
  • Respect token budgets: If the request is simple and you already have enough context, stop pulling.

File Layout

code
├── SKILL.md          # This file (instructions)
├── config.json       # Settings
├── tree.json         # Summary tree (navigation index)
└── chunks/           # Full context chunks
    ├── chunk_001.md
    ├── chunk_002.md
    └── ...