agentleFS
youcislayoucisla/Agent-Foundry/skills/optional/token-compression/SKILL.md

token-compression

Skill1 starsChanged 23 days agoMITView on GitHub

Compress large tool outputs, logs, and retrieved chunks before they crowd out context, while preserving the lines that carry decisions. Use when one tool result is large enough to dominate the working context.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If you use an external compressor, test it against a sample where you know the correct answer.

    line 37

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Token Compression

Instruction-only compression discipline. No proxy, MCP server, or library ships with this skill. If you adopt an external compressor, verify it on your data before trusting it.

Procedure

  1. Measure first. Count characters or tokens for the raw result. If it is already small enough to reason over, stop.
  2. Classify the content. Structured JSON, logs, prose, code, or a mix. The class determines the safe reduction.
  3. Prefer lossless structure. Project JSON fields, filter log levels, keep head and tail with an explicit marker, deduplicate repeated lines.
  4. Summarize last. Semantic summaries lose detail; use them only when the exact wording is not load-bearing, and keep a pointer to the raw artifact.
  5. Keep decisive evidence verbatim. Error messages, stack traces, request IDs, file paths, and the lines a decision depends on survive unchanged.
  6. Record what was dropped. State the reduction method and the volume in the output so a later reader can judge completeness.
  7. Re-check the answer. Confirm the compressed form still supports every claim you make from it.

Choosing a tool

If you use an external compressor, test it against a sample where you know the correct answer. Reject it if it drops error lines, breaks JSON keys, or cannot reproduce the raw input. Keep the raw output until the task is finished.

Good candidates

  • API responses where only a few fields matter
  • Logs where the error level and adjacent context suffice
  • Large diffs where file names and changed hunks matter more than full context
  • Retrieved chunks that repeat the same passage

Poor candidates

  • A short output you have not read yet
  • Content you cannot replay, such as a one-shot stream
  • Data where exact wording or formatting is the evidence

Worked example

A log compressed without losing the error line that drives the fix.

raw: 8,200 lines
kept: timestamp, ERROR lines, request ids, final summary
dropped: INFO/DEBUG lines, duplicate stack frames
compressed: 74 lines; pointer: artifacts/logs/run-42.gz

Anti-patterns

  • Compressing before reading the error.
  • Using compression instead of backend pagination or a narrower query.
  • Summarizing streaming output that cannot be retrieved again.
  • Reporting a reduction percentage without checking answer quality.
  • Discarding the raw artifact while the task still depends on it.

Verification Checklist

  • The raw size and the reduction method are recorded. (step 1)
  • Every error line and identifier survives the compressed form. (step 5)
  • The compressed output reproduces the answer you relied on. (step 4)
  • The raw artifact remains available until the task closes. (step 4)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.