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

Heuristic:AMAP ML SkillClaw System Prompt Compression Cache

From Leeroopedia
Knowledge Sources
Domains Optimization, LLMs
Last Updated 2026-10-22 00:00 GMT

Overview

LLM-driven compression of OpenClaw system prompts to under 2000 tokens while preserving all critical policy and routing rules.

Description

System prompts for coding agents can grow very large with skill catalogs, routing rules, and safety constraints. SkillClaw uses an LLM-based compression utility (`run_llm` in `skillclaw/utils.py`) to rewrite system prompts under 2000 tokens. The compression instruction explicitly lists seven categories of content that must be preserved: (1) tool names and usage constraints, (2) safety prohibitions, (3) skills-selection rules, (4) memory recall requirements, (5) update/config restrictions, (6) reply-tag/messaging rules, and (7) heartbeat handling rules. The compressed prompt removes duplicated prose, repeated examples, and decorative language, preferring compact bullet sections with short imperative statements.

Usage

Use this heuristic when OpenClaw system prompts exceed token limits and need to be compressed without losing critical behavioral rules. It is applied in the `run_llm` utility which routes to either OpenAI or AWS Bedrock for the compression call.

The Insight (Rule of Thumb)

  • Action: Call `run_llm(messages, config)` from `skillclaw/utils.py` to compress a system prompt.
  • Value: Target is under 2000 tokens with `max_completion_tokens=2500` for the response.
  • Trade-off: One LLM API call per compression (latency + cost), but reduces per-request token count for all subsequent calls.
  • Compatibility: Works with both OpenAI and Bedrock providers via provider routing in `_get_llm_provider`.

Reasoning

Large system prompts consume context window budget on every request. By compressing once and caching the result, all subsequent agent requests use a smaller prompt. The compression instruction is carefully scoped to prevent rule weakening — it explicitly says "Do not invent or weaken any rule." The seven preservation categories were identified from OpenClaw's system prompt structure as the critical behavioral constraints that must survive compression.

Code Evidence

Compression instruction from `skillclaw/utils.py:8-23`:

_COMPRESSION_INSTRUCTION = (
    "You are compressing an OpenClaw system prompt. "
    "Rewrite it to be under 2000 tokens while preserving behavior. "
    "Keep all critical policy and routing rules: "
    "(1) tool names and their intended usage constraints, "
    "(2) safety and non-delegable prohibitions, "
    "(3) skills-selection rules, "
    "(4) memory recall requirements, "
    "(5) update/config restrictions, "
    "(6) reply-tag/messaging rules, "
    "(7) heartbeat handling rules. "
    "Remove duplicated prose, repeated examples, and decorative language. "
    "Prefer compact bullet sections with short imperative statements. "
    "Do not invent or weaken any rule. "
    "Output only the rewritten system prompt text."
)

Provider routing from `skillclaw/utils.py:26-45`:

def _get_llm_provider(config: Optional["SkillClawConfig"] = None) -> str:
    if config is not None:
        if getattr(config, "llm_provider", "") == "bedrock":
            return "bedrock"
        return "openai"
    # ... config store lookup ...
    if os.environ.get("SKILLCLAW_USE_BEDROCK", "").lower() in ("1", "true", "yes"):
        return "bedrock"
    return "openai"

Related Pages

Page Connections

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