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

Implementation:AMAP ML SkillClaw SkillManager

From Leeroopedia
Knowledge Sources
Domains Skill_Management, Information_Retrieval
Last Updated 2026-10-22 00:00 GMT

Overview

Concrete tool for loading, retrieving, and injecting AI agent skills from a local skill library, provided by the SkillClaw client package.

Description

The SkillManager class loads AgentSkills-compatible skill folders (each containing a `SKILL.md` with YAML frontmatter), maintains an in-memory catalog, and provides retrieval via two modes: template (effectiveness-ranked, zero latency) and embedding (cosine similarity via SentenceTransformer). It also builds OpenClaw-compatible XML injection prompts that list skills as a catalog for the LLM.

Usage

Import and use when you need to:

  • Load skills from a local directory into memory
  • Retrieve the most relevant skills for a given task description
  • Build a skill catalog prompt for injection into LLM system messages
  • Track skill injection statistics (effectiveness scoring)
  • Detect and hot-reload changes to the local skill directory

Code Reference

Source Location

  • Repository: SkillClaw
  • File: `skillclaw/skill_manager.py:L171-879`

Signature

class SkillManager:
    """Load, retrieve, and inject skills from a local skill library.

    Supports two retrieval modes:
      * "template" – flat effectiveness-ranked retrieval, zero latency
      * "embedding" – cosine similarity via SentenceTransformer
    """

    def __init__(
        self,
        skills_dir: str,
        public_skill_root: str = "",
        retrieval_mode: str = "template",
        embedding_model_path: Optional[str] = None,
        embedding_type: str = "local",
        embedding_api_url: Optional[str] = None,
        embedding_api_model: Optional[str] = None,
        embedding_api_key: Optional[str] = None,
    ) -> None:

    def retrieve(self, task_description: str, top_k: int = 6) -> list[dict]:
        """Retrieve relevant skills for task_description."""

    def get_all_skills(self) -> list[dict]:
        """Return all loaded skills eligible for model invocation."""

    def build_injection_prompt(
        self,
        max_chars: int = 30_000,
        read_tool_name: str = "read",
    ) -> str:
        """Build an OpenClaw-compatible <available_skills> XML catalog prompt."""

    def reload(self) -> None:
        """Reload skills from disk (called after skill sync)."""

    def refresh_if_changed(self) -> bool:
        """Reload if the skill directory fingerprint has changed."""

    def record_injection(self, skill_names: list[str]) -> None:
        """Record that skills were injected (for effectiveness stats)."""

    def get_effectiveness(self, skill_name: str) -> float:
        """Return the effectiveness score [0, 1] for a skill."""

    def get_skill_count(self) -> int:
        """Return the number of loaded skills."""

Import

from skillclaw.skill_manager import SkillManager

I/O Contract

Inputs

Name Type Required Description
skills_dir str Yes Path to the skill library directory
public_skill_root str No Optional public skill root for shared skills
retrieval_mode str No "template" (default) or "embedding"
embedding_model_path None No SentenceTransformer model path (embedding mode)
embedding_type str No "local" (default) or "api"
task_description str Yes (retrieve) Task text to match skills against
top_k int No Max skills to retrieve (default 6)

Outputs

Name Type Description
retrieve() returns list[dict] Skills with name, description, category, content, file_path
get_all_skills() returns list[dict] All eligible skills (excluding disabled-model-invocation)
build_injection_prompt() returns str XML catalog string for system message injection
get_skill_count() returns int Number of loaded skills

Usage Examples

Template-Mode Skill Loading

from skillclaw.skill_manager import SkillManager

# Load skills with effectiveness-ranked retrieval (zero latency)
manager = SkillManager(
    skills_dir="/home/user/.skillclaw/skills",
    retrieval_mode="template",
)
print(f"Loaded {manager.get_skill_count()} skills")

# Retrieve top 6 skills for a task
top_skills = manager.retrieve("How to deploy a Python web app")
for skill in top_skills:
    print(f"  - {skill['name']}: {skill['description']}")

Embedding-Mode Skill Retrieval

from skillclaw.skill_manager import SkillManager

# Load skills with cosine similarity retrieval
manager = SkillManager(
    skills_dir="/home/user/.skillclaw/skills",
    retrieval_mode="embedding",
    embedding_model_path="Qwen/Qwen3-Embedding-0.6B",
    embedding_type="local",
)

# Semantic search
results = manager.retrieve("write a REST API endpoint", top_k=10)

Build Injection Prompt

from skillclaw.skill_manager import SkillManager

manager = SkillManager(
    skills_dir="/home/user/.skillclaw/skills",
    retrieval_mode="template",
)

# Build the XML catalog for system message injection
injection_prompt = manager.build_injection_prompt(
    max_chars=30_000,
    read_tool_name="read",
)
# This string is appended to the system message in the LLM request

Hot-Reload After Sync

# After SkillHub.pull_skills() downloads new skills:
if manager.refresh_if_changed():
    print("Skills changed, reloaded automatically")
    # SkillManager has updated its in-memory catalog

Related Pages

Implements Principle

Uses Heuristic

Page Connections

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