Skill

token-compression

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.

Category
optional
Version
0.2.0
License
MIT
Status
active
Length
79 lines
Source
skills/optional/token-compression/SKILL.md

Install and discovery

npx --yes --package @youcisla/agent-foundry agent-foundry-install

After the installer runs, this record is available as token-compression. See the docs for harness roots and verification steps.

Contents

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.

  1. Classify the content. Structured JSON, logs, prose, code, or a mix. The

class determines the safe reduction.

  1. Prefer lossless structure. Project JSON fields, filter log levels, keep

head and tail with an explicit marker, deduplicate repeated lines.

  1. 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.

  1. Keep decisive evidence verbatim. Error messages, stack traces, request

IDs, file paths, and the lines a decision depends on survive unchanged.

  1. Record what was dropped. State the reduction method and the volume in

the output so a later reader can judge completeness.

  1. 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)