agentleFS
patonkikhpatonkikh/APES/skills/ai/context-engineering/skill.md

context-engineering

Skill3 starsChanged 4 months agoMITView on GitHub

Design context assembly strategy: what information enters the model context, in what order, with what budget, and how to handle overflow. Use when working on prompt engineering, AI workflows, agents, context design, or LLM optimization.

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

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

  • 0

    Common

    Most of the 117 edited versions we read keep these.

  • 3

    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:

    Document ranking/scoring for retrieved content.

    line 50
  2. Distinctive:

    Put most relevant context closest to user query.

    line 112
  3. Distinctive:

    Use semantic ranking for RAG chunks.

    line 113

“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

Purpose

Design context assembly strategy: what information enters the model context, in what order, with what budget, and how to handle overflow.

Input: AI architecture, data sources, prompt template, context window limit
Output: Context Engineering specification with budget allocation, assembly pipeline, and truncation rules
Examples: See examples.md for worked input/output.


Workflow

Step 1: Define context budget

SegmentToken budgetPriority

Segments: system instructions, retrieved docs, conversation history, tool results, user query.

Total must fit within model context window minus output reserve (typically 20-30%).

Step 2: Inventory context sources

SourceTypeTypical sizeFreshnessRequired

Sources: RAG chunks, user profile, session history, API tool outputs, documents.

Step 3: Design assembly pipeline

Order of assembly (recommended):

  1. System instructions (fixed)
  2. Critical constraints
  3. Retrieved context (ranked)
  4. Recent conversation (truncated)
  5. User query

Document ranking/scoring for retrieved content.

Step 4: Define truncation strategies

When overflowStrategy
History too longSummarize older turns / sliding window
RAG too largeRe-rank and top-k truncate
Document too largeChunk and select best chunks
Tool output largeSummarize or extract fields

Step 5: Plan caching opportunities

ContentCacheableTTLSavings

Static system prompts, frequent retrievals, embeddings.

Step 6: Validate

Run Validation checklist.


Decision Rules

ConditionAction
No context window limit specifiedUse conservative default; state assumption
Required source exceeds budget aloneRecommend summarization, RAG, or larger model
PII in context sourcesApply redaction before assembly
Conflicting info across sourcesDefine precedence rules
No truncation strategyBlock; overflow will cause failures

Validation

  • Token budget allocated per segment
  • Budget fits within context window minus output reserve
  • All context sources inventoried
  • Assembly order documented
  • Truncation strategy for each overflow scenario
  • Ranking method for retrieved content defined
  • Caching opportunities identified
  • PII handling addressed if applicable

Anti-patterns

  • Stuff everything — no budget, no truncation.
  • Wrong order — user query buried under irrelevant context.
  • Stale context — no freshness consideration for dynamic data.
  • Duplicate content — same info from multiple sources wasting tokens.
  • No output reserve — using 100% context for input.

Best Practices

  • Reserve 20-30% of context for model output.
  • Put most relevant context closest to user query.
  • Use semantic ranking for RAG chunks.
  • Summarize long histories rather than drop silently.
  • Measure context utilization in production metrics.

Output Structure

# Context Engineering: [System Name]

## Model & Budget
- **Context window:** [tokens]
- **Output reserve:** [tokens]
- **Available input:** [tokens]

## Budget Allocation
| Segment | Budget | Priority |
|---------|--------|----------|

## Sources
| Source | Size | Freshness | Required |
|--------|------|-----------|----------|

## Assembly Pipeline
1. [Step]

## Truncation Rules
| Scenario | Strategy |
|----------|----------|

## Caching
| Content | TTL | Expected savings |
|---------|-----|------------------|

## Metrics
| Metric | Target |
|--------|--------|
| Context utilization | <80% |
| Retrieval precision | [target] |

Next Skills

OutcomeRecommended Skill
Design RAG pipelinerag/rag-architecture-designer
Optimize promptsai/prompt-optimizer
Chunking strategyrag/chunking-strategy-advisor
AI architecture updateai/ai-solution-architect

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.