Skip to main content
Glama

Context Window Packer

pack_context_window

Selects optimal content chunks to fit within LLM token limits using priority, greedy, or balanced strategies when content exceeds context window capacity.

Instructions

Pack content chunks into a token budget for an LLM context window. Selects the best subset of chunks that fits within the token limit using priority, greedy, or balanced strategies. Use when you have more content than fits in the context window.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chunksYesContent chunks to pack
tokenBudgetYesMaximum tokens allowed
modelNoTarget model for tokenizationgpt-4o
strategyNoPacking strategypriority
separatorNoText between chunks
systemPromptNoSystem prompt to reserve tokens for
reserveForOutputNoTokens to reserve for output

Implementation Reference

  • The 'pack_context_window' tool is registered in mcp-server/src/index.ts, and its handler calls the Agent Toolbelt API endpoint 'context-window-packer'.
    server.registerTool(
      "pack_context_window",
      {
        title: "Context Window Packer",
        description:
          "Pack content chunks into a token budget for an LLM context window. " +
          "Selects the best subset of chunks that fits within the token limit using priority, greedy, or balanced strategies. " +
          "Use when you have more content than fits in the context window.",
        inputSchema: {
          chunks: z.array(z.object({
            text: z.string().describe("Content of this chunk"),
            label: z.string().optional().describe("Optional identifier"),
            priority: z.number().min(0).max(10).default(5).describe("Importance 0–10"),
            metadata: z.record(z.unknown()).optional(),
          })).describe("Content chunks to pack"),
          tokenBudget: z.number().int().describe("Maximum tokens allowed"),
          model: z.string().default("gpt-4o").describe("Target model for tokenization"),
          strategy: z.enum(["priority", "greedy", "balanced"]).default("priority").describe("Packing strategy"),
          separator: z.string().default("\n\n").describe("Text between chunks"),
          systemPrompt: z.string().optional().describe("System prompt to reserve tokens for"),
          reserveForOutput: z.number().int().min(0).default(0).describe("Tokens to reserve for output"),
        },
      },
      async ({ chunks, tokenBudget, model, strategy, separator, systemPrompt, reserveForOutput }) => {
        const result = await callToolApi("context-window-packer", { chunks, tokenBudget, model, strategy, separator, systemPrompt, reserveForOutput });
        const data = result as any;
        const r = data.result;
    
        const lines = [
          `**Packed ${r.stats.chunksPacked}/${r.stats.chunksTotal} chunks** | ${r.stats.tokensUsed}/${r.stats.effectiveBudget} tokens (${r.stats.utilizationPercent}% utilized)`,
          `**Strategy:** ${r.strategy} | **Model:** ${r.model}`,
          r.stats.systemPromptTokens > 0 ? `**System prompt:** ${r.stats.systemPromptTokens} tokens reserved` : "",
          r.stats.reservedForOutput > 0 ? `**Output reservation:** ${r.stats.reservedForOutput} tokens` : "",
          "",
          r.packed.length > 0 ? `**Packed chunks:**\n${r.packed.map((p: any) => `- ${p.label || `chunk[${p.originalIndex}]`} (priority ${p.priority}, ${p.tokens} tokens)`).join("\n")}` : "",
          r.excluded.length > 0 ? `\n**Excluded chunks:**\n${r.excluded.map((e: any) => `- ${e.label || `chunk[${e.originalIndex}]`} (${e.tokens} tokens, ${e.reason})`).join("\n")}` : "",
        ].filter(Boolean);
    
        return { content: [{ type: "text" as const, text: lines.join("\n") }] };
      }
    );
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses algorithmic behavior (priority/greedy/balanced strategies) but omits operational details: whether the tool is idempotent, what the return format contains (indices, text, or metadata), and any side effects or rate limits.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Three sentences with zero waste: sentence 1 states the core action, sentence 2 elaborates mechanism/strategies, sentence 3 provides usage condition. Front-loaded with the essential verb and resource.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 7 parameters with 100% schema coverage, the description adequately explains the operation. However, with no output schema provided, the description fails to specify what gets returned (formatted string, chunk array, or indices). Missing annotations for safety profile (read-only vs destructive) also creates a gap.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, establishing a baseline of 3. The description adds conceptual context ('pack content chunks into a token budget') that helps understand parameter interactions, but does not add syntax details or format examples beyond what the schema already provides.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a specific verb ('Pack') and clear resources ('content chunks', 'token budget', 'LLM context window'). It distinguishes from siblings like count_tokens by emphasizing the selection/packing functionality rather than just counting.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides explicit when-to-use guidance ('Use when you have more content than fits in the context window'). Lacks explicit alternatives or exclusions (e.g., 'use count_tokens instead if you only need token counts'), but the conditional usage is clearly stated.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/marras0914/agent-toolbelt'

If you have feedback or need assistance with the MCP directory API, please join our Discord server