Skip to content

Feature: Native skill restore after context compaction #28367

Description

@postrednik

Problem

After context compaction (auto-cleanup when context window fills up), agents lose track of which skills (SKILL.md files) were actively loaded. The agent knows what it was working on (via /tmp/<agent>-current-task.md), but not which skills provided the operational context.

This forces agents to manually re-discover and re-read SKILL.md files after every compaction, wasting tokens and risking missed instructions.

Current Workaround

We've implemented a convention-based approach: agents write an ## Active Skills section in their current-task file with absolute paths to SKILL.md files. After compaction, the agent reads this section and manually re-loads each skill.

## Active Skills
- lc-mc-finance: ~/.openclaw/workspace-leo/skills/lc-mc-finance/SKILL.md
- github: /usr/lib/node_modules/openclaw/skills/github/SKILL.md

This works but is agent-dependent and costs tokens for the re-read.

Proposed Solution

Add native support for skill persistence across compaction:

  1. Track active skills in session metadata — when an agent reads a SKILL.md, record it in session.activeSkills[]
  2. Persist through compaction — include activeSkills in the compaction summary/carryover
  3. Auto-restore — after compaction, automatically re-inject the SKILL.md content into the system prompt (similar to how <available_skills> works, but with full content instead of just name/description)

Config

{
  compaction: {
    restoreSkills: true,  // default: true
    maxRestoredSkills: 3  // prevent token overflow
  }
}

Implementation Notes

  • The skills snapshot infrastructure already exists (per-session, with hot-reload via watcher)
  • Estimated scope: ~50-80 lines across session.ts and compaction.ts
  • Edge cases: skill removed/renamed between sessions → graceful fallback (log warning, skip)
  • Token budget: cap at 3 restored skills to prevent context overflow

Context

This came from a team brainstorming session about improving agent continuity across compaction events. The convention-based workaround (Phase 1) is deployed and working, but native support would be cleaner and more reliable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleMarked as stale due to inactivity

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions