Skip to content

Feature: Skills/Tools Prompt Budget Management #70

@Sahil5963

Description

@Sahil5963

Summary

Implement configurable budget limits for skills and tool definitions in prompts to prevent context overflow.

Problem

When loading many skills or tools:

  • Skill descriptions can consume excessive context
  • No limit on how much space tool definitions take
  • Large skill files can blow up the prompt
  • Users have no visibility into token usage

Proposed Solution

Configuration Options

interface SkillsBudgetConfig {
  enabled?: boolean;                    // Default: false
  
  limits?: {
    maxSkillsInPrompt?: number;         // Default: 150
    maxSkillsPromptChars?: number;      // Default: 30_000 (30K chars)
    maxSkillFileBytes?: number;         // Default: 256_000 (256KB per file)
    maxToolDefinitionChars?: number;    // Default: 50_000
  };
  
  optimization?: {
    compactPaths?: boolean;             // Replace /Users/x/ with ~/
    minifyDescriptions?: boolean;       // Shorten verbose descriptions
    prioritization?: 'recent' | 'frequent' | 'alphabetical';
  };
  
  warnings?: {
    enabled?: boolean;                  // Warn when approaching limits
    thresholdPercent?: number;          // Warn at 80% usage
  };
}

// Usage
const chat = createChatWithTools({
  skillsBudget: {
    enabled: true,
    limits: {
      maxSkillsInPrompt: 100,
      maxSkillsPromptChars: 25_000,
    },
    optimization: {
      compactPaths: true,
      prioritization: 'frequent',
    },
    warnings: {
      enabled: true,
      thresholdPercent: 80,
    }
  }
});

Smart Fitting Algorithm

// Binary search to fit maximum skills within budget
function fitSkillsToBudget(skills: Skill[], config: SkillsBudgetConfig): Skill[] {
  const { maxSkillsInPrompt, maxSkillsPromptChars } = config.limits;
  
  // 1. Limit by count
  let candidates = skills.slice(0, maxSkillsInPrompt);
  
  // 2. Binary search to fit char budget
  let lo = 0, hi = candidates.length;
  while (lo < hi) {
    const mid = Math.ceil((lo + hi) / 2);
    const prompt = formatSkills(candidates.slice(0, mid));
    if (prompt.length <= maxSkillsPromptChars) lo = mid;
    else hi = mid - 1;
  }
  
  return candidates.slice(0, lo);
}

Path Compaction (Token Savings)

// Before: /Users/alice/.config/copilot/skills/github/SKILL.md
// After:  ~/.config/copilot/skills/github/SKILL.md
// Saves ~5-6 tokens per skill path

optimization: {
  compactPaths: true,  // Enable path compaction
}

Use Cases

  • Large skill libraries with 100+ skills
  • Enterprise deployments with many custom tools
  • Multi-tenant systems with per-user skills
  • Resource-constrained environments

Benefits

  • Fully optional - disabled by default
  • Configurable limits - tune for your context window
  • ✅ Prevents prompt overflow from too many skills
  • ✅ Smart fitting maximizes skills within budget
  • ✅ Path compaction saves tokens
  • ✅ Warnings before hitting limits
  • ✅ Prioritization keeps most useful skills

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions