Skip to main content
Glama

compact_context

Summarizes and replaces the oldest messages to keep requests under the model context window and prevent prompt-too-long errors.

Instructions

Replace the oldest messages with a summary instead of dropping them.

The summary comes from summary when given, otherwise from the local model via model/base_url (or the CONTEXT_SHRINK_MODEL / CONTEXT_SHRINK_BASE_URL environment variables). With neither, the tool returns a needs_summary plan plus the exact prompt, and no message content is echoed back.

Example call::

compact_context({
    "messages": [...],
    "keep_last": 8,
    "threshold": 0.8,
    "summary": "…",  # omit to summarise with the model
})

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "messages": "<messages>"
    },
    "name": "compact_context"
  }
}

Input Schema

NameRequiredDescriptionDefault
forceNo
modelNo
api_keyNo
summaryNo
base_urlNo
messagesYes
keep_lastNo
thresholdNo
summary_roleNosystem
max_context_tokensNo
summary_budget_tokensNo

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A3.6/5.0
Behavior4/5

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

With no annotations at all, the description carries the full burden and does well: it discloses the summary-source precedence (explicit ``summary`` > ``model``/``base_url`` > CONTEXT_SHRINK_MODEL env vars), the no-summary fallback returning a ``needs_summary`` plan plus prompt, and the data-safety guarantee that no message content is echoed back. It stops short of describing what happens when the threshold isn't met, what ``force`` overrides, or whether the original messages are irrecoverably discarded.

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

Conciseness4/5

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

The core behavior is front-loaded in a single sentence, followed by useful source-precedence and fallback detail; the example call block is justified for an 11-parameter tool. Some vertical whitespace and the parenthetical env-var hedge add length without much extra signal.

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?

An output schema exists, so return values needn't be explained, and the description handles the summary-resolution path well. However, for a mutation tool with 11 undocumented parameters and no annotations, missing coverage of ``force``, token budgets, and ``api_key`` leaves an agent unable to predict cost or override behavior.

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 0% across 11 parameters, so the description must compensate and only partially does: it covers ``messages``, ``keep_last``, ``threshold``, ``summary``, ``model``, and ``base_url`` at a mention level, mostly through an example call with no units or semantics for keep_last/threshold. Five parameters — ``force``, ``api_key``, ``summary_role``, ``max_context_tokens``, ``summary_budget_tokens`` — receive no explanation anywhere.

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

Purpose4/5

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

The description gives a concrete verb and mechanism — 'Replace the oldest messages with a summary instead of dropping them' — which distinguishes it from a drop-based sibling like trim_context without naming it. The purpose is unambiguous, but it never explicitly contrasts itself with the supplied siblings estimate_context and trim_context by name.

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

Usage Guidelines3/5

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

Usage is implied rather than stated: the tool compacts long message lists, and the 'With neither, the tool returns a needs_summary plan' sentence describes a fallback path an agent would use. There is no explicit when-to-use versus estimate_context or trim_context, and no stated condition (e.g. threshold reached) that should trigger a call.

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

Deploy Server

Other Tools