sage-context-management

Estimate tokens, prune messages, and auto-compact LLM context histories.

12|1|Updated Jul 15, 2025
One-click install
npx skills add https://github.com/majiayu000/sage --skill sage-context-management
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sage-context-management
Source: https://github.com/majiayu000/sage/tree/main/.sage/skills/sage-context-management
Command: npx skills add https://github.com/majiayu000/sage --skill sage-context-management

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Sage context management provides a structured approach to controlling the LLM's context window by estimating tokens, pruning non-critical messages, and auto-compacting history to preserve important context while staying within limits.

Core Features & Use Cases

  • Token estimation: accurately calculate tokens for messages, including system/user/assistant roles.
  • Pruning: drop older non-system messages while retaining recent context and system prompts.
  • Auto-compact: summarize long histories to fit within context budgets, with optional LLM-assisted summaries.
  • Use Case: When you have extended conversations in coding sessions or planning tasks, this tool keeps the dialogue concise without losing critical information.

Quick Start

Invoke the ContextManager with provider/model configuration, then call estimate_tokens, prune, and check for compaction as needed during a session.

Frequently Asked Questions about sage-context-management

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I manage LLM context window limits during long coding sessions?

To manage LLM context limits, you can estimate tokens, prune older non-critical messages, and auto-compact history. This preserves recent context and system prompts while keeping extended coding sessions concise within model limits.

What is the best way to estimate tokens for messages with different roles?

Token estimation accurately calculates tokens for messages, including system, user, and assistant roles. This provider-aware calculation helps deterministically control context size before hitting the model's hard limits.

How does auto-compaction summarize long conversation histories?

Auto-compaction summarizes long histories to fit within context budgets using optional LLM-assisted summaries. It preserves important context information while dropping older non-system messages to maintain dialogue conciseness.

Can I prune non-critical messages while retaining system prompts?

Yes, pruning drops older non-system messages while retaining recent context and system prompts. This ensures critical information is preserved during extended planning tasks or code review workflows.

When do I need context pruning for planning tasks approaching the token limit?

You need context pruning when messages approach the model's context limit during long-running assistant sessions. It helps control context size deterministically by dropping older non-critical messages while preserving important information.

Does context management work with provider-aware configurations for different models?

Yes, you invoke the ContextManager with provider and model configuration. This enables accurate token estimation and auto-compaction tailored to the specific context limits of your chosen LLM provider.