Skip to main content
Glama

trim_llm_context

Prune LLM message history to fit token budgets by deduplicating repetitive outputs, condensing payloads, and preserving recent turns and system instructions.

Instructions

    [Free Promotional Preview / Zero Auth] Compresses and prunes LLM message history to strictly fit within a target token budget.
    Deduplicates repetitive tool outputs, condenses bulky historical payloads,
    and prunes older turns while preserving system instructions and recent context.

    Args:
        messages: Native list of OpenAI/Anthropic format message dicts (or JSON string).
        messages_json: Optional stringified messages for backward compatibility.
        max_tokens: Maximum target token count (default: 4000).
        preserve_recent_turns: Number of recent conversational turns to preserve untouched (default: 4).
        payment_signature: Optional x402 Base USDC transaction hash or developer mock key.
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
messagesNo
max_tokensNo
messages_jsonNo
payment_signatureNo
preserve_recent_turnsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.3.0

TDQS

B3.3/5.0
Behavior3/5

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

With no annotations, the description carries the full burden. It does disclose pruning, deduplication, preservation of system instructions/recent context, and zero-auth status. However, it does not reveal potential side effects, whether input is mutated, or what happens when the budget cannot be strictly met.

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 overview is only two sentences and the parameter list is well-structured and reasonably brief. The 'Free Promotional Preview / Zero Auth' prefix is mildly promotional but still informative; no major redundancy or bloat.

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?

The description covers the main behavior and all parameter semantics, and an output schema exists. Still, it omits error behavior, output format details, and the relationship to the nearby compress_document_tool sibling, leaving some ambiguity for agent selection.

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

Parameters4/5

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

Schema description coverage is 0%, but the Args section compensates by explaining each parameter's purpose, types, and defaults. It adds useful context such as 'OpenAI/Anthropic format message dicts', backward-compatibility behavior, and the payment signature's role.

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 clearly states the action ('Compresses and prunes LLM message history') and the target resource, plus the budget constraint. It is specific enough to distinguish from generic compression tools, though it does not explicitly differentiate from the sibling 'compress_document_tool'.

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

Usage Guidelines2/5

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

The description implies use when message history exceeds a token budget, but it gives no explicit guidance about when to choose this tool over alternatives. There are no stated exclusions, prerequisites, or comparison with sibling tools such as compress_document_tool.

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