agentleFS
youcislayoucisla/Agent-Foundry/skills/core/context-optimization/SKILL.md

context-optimization

Skill1 starsChanged 23 days agoMITView on GitHub

Keep tool outputs small, sandbox large files, reference not repeat. Use

25 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use bdi-mental-states, long-horizon-prompting and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • Downey6689Skill

    bdi-mental-states

    Transforms external RDF context into BDI mental states. Invoke when modeling beliefs, desires, and intentions.

    Also in 7 projects that use this

  • DVwebBiz11Skill

    long-horizon-prompting

    This skill should be used when writing, enhancing, or evaluating the launch prompt for a long-running autonomous agent or a parallel multi-agent orchestration attacking a hard problem: pseudo-formal task briefs that define terms and an exact success predicate linguistically, enumerate non-counting outcomes, set persistence rules with explicit stop and return conditions and effort floors, manage a diverse portfolio of parallel approaches with an approach registry and blocked-route bookkeeping, and gate the return on adversarial audit. Route agent topology and coordination protocols to multi-agent-patterns, runtime control surfaces and loop governance to harness-engineering, evaluator and quality-gate construction to evaluation, judge design to advanced-evaluation, and compaction or memory mechanics to context-compression and memory-systems.

    Also in 5 projects that use this

  • Downey6689Skill

    hosted-agents

    Guidance for hosted/sandboxed agents. Invoke when running background agents in isolated VMs or multi-client setups.

    Also in 6 projects that use this

  • DVwebBiz11Skill

    self-improvement-loops

    This skill should be used when the harness, scaffold, workflow, or optimizer itself is the optimization target: recursive self-improvement (RSI) loops, meta-harnesses, self-improving harnesses that mine their own failures and propose bounded edits, evolutionary or population-based search over agent scaffolds, acceptance gates for self-modifying systems, and agentic context evolution where the mechanism that produces context is versioned and evolved. Route governance of a single autonomous loop (locked surfaces, durable logs, rollback, novelty gates, approval boundaries) to harness-engineering, measurement and quality-gate design to evaluation, judge design to advanced-evaluation, and remote sandbox infrastructure to hosted-agents.

    Also in 4 projects that use this

  • AbdelrhmanAlquranSkill

    latent-briefing

    This skill should be used when the user asks to "share memory between agents", "KV cache compaction for multi-agent", "orchestrator worker context", "latent briefing", "reduce worker tokens", "cross-agent memory without summarization", or discusses Attention Matching compaction, recursive language models with workers, or token explosion in hierarchical agents.

    Also in 4 projects that use this

  • rohunvoraSkill

    advanced-evaluation

    Master LLM-as-a-Judge evaluation techniques including direct scoring, pairwise comparison, rubric generation, and bias mitigation. Use when building evaluation systems, comparing model outputs, or establishing quality standards for AI-generated content.

    Also in 6 projects that use this

  • +1 more from Downey6689

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 5 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 23 edited versions we read keep these.

  • 5

    Distinctive

    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:

    Don't dump — summarize: When a tool returns >2K tokens, return a summary + the path.

    line 22
  2. Distinctive:

    Reference, don't repeat: If you read it once, don't paste it again.

    line 24
  3. Distinctive:

    One tool call, one purpose: Don't bundle a read + a search + a write in one step.

    line 25
  4. Distinctive:

    If the user asks for a literal paste of a file, do it.

    line 40
  5. Distinctive:

    Create artifact directories private (0700) and files exclusively (0600).

    line 84

“Common” is measured: kept by at least 6 in 10 of the 23 edited versions of this file we could read. “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

Context Optimization

Small context is fast context. Apply these rules on any task that reads files or calls tools.

Procedure

The rules

  1. Don't dump — summarize. When a tool returns >2K tokens, return a summary + the path. Not the whole blob.
  2. Sandbox large files. A 5,000-line file → write the interesting parts to a sandbox path, return the path + a grep tool the agent can use. Re-reads are free.
  3. Reference, don't repeat. If you read it once, don't paste it again. Quote the file path and the line range.
  4. One tool call, one purpose. Don't bundle a read + a search + a write in one step. Each call has its own tool result overhead.
  5. Stop when you have enough. First successful outcome is enough. Don't run the test 10 times to "be sure."

When output really is the answer

Some outputs must be verbatim:

  • Stack traces with file:line
  • Exact error messages
  • Test diffs
  • The user's quoted text

For these, the rule is truncate the noise, keep the signal — remove timestamps, request IDs, repeated headers.

When this conflicts with other goals

If the user asks for a literal paste of a file, do it. Context is a default, not a law.

When to skip

  • The user is debugging interactively and needs the full output once.
  • The tool returns <500 tokens — already small enough.

Worked example

A failing test run reduced to a pointer plus the decisive frames.

tool result (2,000 lines):
  ... 3 failed, 197 passed ... (saved to .foundry/spill/pytest-42.log)

answer:
  3 failures; first is KeyError in cache.py:88
  File "agent_foundry/cache.py", line 88, in load
    value = raw["value"]

Anti-patterns

  • Pasting a 5,000-line file when a line range and summary answer the question.
  • Repeating a file body instead of citing path and lines.
  • Truncating the only copy of an output.
  • Treating a spill locator as a parsed path.

Verification Checklist

  • Large output has a summary plus a retrieval reference. (step 1)
  • Exact errors and stack frames are preserved verbatim. (step 2)
  • The full output survives before any truncation. (step 2)
  • Cited line ranges still resolve. (step 3)
  • Output collection stops at the first sufficient result. (step 5)

Compaction and Spill

  • Cap history by estimated tokens and keep the newest N turns. Record compacted_turns and dropped tokens; silent loss is a correctness bug.
  • Compaction is destructive. State the approximation: dropped turns are gone, not summarized, unless a summary backend exists.
  • Spill the full output to a private artifact and keep a bounded inline preview. Never truncate the only copy.
  • Return an opaque locator plus retrieval guidance. Treat the locator as a handle, not a path to parse.
  • A spill failure keeps the inline result; it must not fail the model call.
  • Create artifact directories private (0700) and files exclusively (0600). Never derive a filename from user text.
  • Publish artifacts by temp file, fsync, rename. A half-written artifact is worse than a missing one.

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.