agentleFS
topprismdatatopprismdata/cultivating-ml-agent/skills/examples/context-engineering/SKILL.md

context-engineering

Skill5 starsChanged 34 days agoMITView on GitHub

Use when context window is getting crowded, when dealing with long training logs, or when preparing prompts with mixed-priority content (system / task / skills / examples). Triggers when assembling prompts >4000 chars, or when observing "Lost in the Middle" symptoms (model ignores mid-prompt content).

131 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use using-agent-skills, idea-refine 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.
  • LLl0k0laDSkill

    using-agent-skills

    Use when starting a session or when you need to discover which skill applies to the current task. This is the meta-skill that governs how all other skills are discovered and invoked.

    Also in 36 projects that use this

  • LLl0k0laDSkill

    idea-refine

    Refine ideas through structured divergent and convergent thinking. Use "idea-refine" or "ideate" to trigger.

    Also in 44 projects that use this

  • HK-hubSkill

    deprecation-and-migration

    Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when deciding whether to maintain or sunset existing code.

    Also in 40 projects that use this

  • MrCipherSmithSkill

    constraint-driven-development

    Use when a project needs a persistent, measurable quality bar — starting a project without documented standards, 'set up constraints', or when coverage/perf/a11y thresholds get re-debated per-PR. Produces CONSTRAINTS.md with enforceable numbers, ratchets, and a guard against silent weakening. NOT for throwaway prototypes or a one-off CI setup.

    Also in 14 projects that use this

  • HK-hubSkill

    source-driven-development

    Grounds every implementation decision in official documentation. Use when you want authoritative, source-cited code free from outdated patterns. Use when building with any framework or library where correctness matters.

    Also in 44 projects that use this

  • +6 more from LLl0k0laD
  • +1 more from HK-hub

The file

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 117 edited versions we read keep these.

  • 1

    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:

    When every detail must be preserved (use verbatim)

    line 83

“Common” is measured: kept by at least 6 in 10 of the 117 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 Engineering

Context

Even with 1M-2M token context windows, stuffing everything degrades performance ("Lost in the Middle" — Liu et al. 2023). This skill encodes Anthropic's 2025 best practices: dynamic compression, intelligent log truncation, and priority-aware token budgeting.

The core insight: context is RAM, treat it like memory management, not a buffer.

Guidance

Three Tools

from framework.src.context_engineering import (
    ContextCompressor, LogTruncator, TokenEconomy,
    CompressionLevel, BudgetPriority,
)

# 1. Compress long text (LLM outputs, paper abstracts)
compressor = ContextCompressor()
result = compressor.compress(long_paper_abstract,
                              level=CompressionLevel.MEDIUM,
                              focus_query="time series forecasting")
# → AGGRESSIVE for very long, MEDIUM for 4K-20K, LIGHT for <4K

# 2. Truncate training logs (preserve errors + samples)
truncated = LogTruncator(max_lines=200).truncate(training_log)
# → 500 lines → 50 lines, all ERROR/WARN kept, METRIC sampled

# 3. Priority-aware token budget
econ = TokenEconomy()
econ.add_critical(system_prompt, "system")
econ.add_high(current_task, "task")
econ.add(relevant_skill_text, BudgetPriority.MEDIUM, "skills")
econ.add(optional_context, BudgetPriority.LOW, "context")
prompt = econ.assemble()  # auto-drops LOW when over budget

Decision Workflow

Assembling a prompt?
  ↓
1. Are there training logs > 100 lines?
   → LogTruncator first (reduce noise 5-10x)
  ↓
2. Are there paper abstracts / long docs?
   → Compressor + MEDIUM (keep relevant 50%)
  ↓
3. Total still > 8000 chars?
   → TokenEconomy (prioritize, auto-drop LOW)
  ↓
4. Send to LLM

Why This Matters

Without Context EngineeringWith It
Lost in the Middle (model misses mid-prompt)Key info always prioritized
40% token waste on redundant/irrelevant content50-70% token savings
Inconsistent outputs from over-stuffed promptsStable, focused outputs
Can't fit new context when LLM call limit hitAlways room for one more thing

Real ROI: agy research confirms 20% accuracy improvement on code generation when context is properly engineered.

When to Apply

When to Use

  • Any prompt > 4000 chars
  • Training logs in context
  • Mixing system + task + skills + examples
  • "Model keeps ignoring this instruction"
  • Multi-turn conversations with growing history

When NOT to Use

  • Short prompts (<1000 chars) — overhead not worth it
  • When every detail must be preserved (use verbatim)
  • Streaming scenarios (compress after stream ends)

Notes

  • Combine with Memory Hierarchy (don't compete): Memory decides what enters context; Engineering decides how to fit it
  • Measure first: log token counts before/after to validate savings
  • Test with edge cases: 50K chars, all-metrics log, mixed priorities
  • See also: memory-hierarchy-management, runtime-reflexion

References

  • Implementation: framework/src/context_engineering/
  • Inspired by: Anthropic Context Engineering Best Practices (2025)
  • Research: Liu et al. "Lost in the Middle" (2023), Anthropic prompt caching (2024)

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.

Reviews can't be read right now.

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.