itsmostafa/llm-engineering-skills/context-engineering
- community
Checking that the SKILL.md file is still in the repository.
Strategies for managing LLM context windows effectively in AI agents. Use when building agents that handle long conversations, multi-step tasks, tool orchestration, or need to maintain coherence across extended interactions.
Install
npx vskill@latest install itsmostafa/llm-engineering-skills/context-engineeringSKILL.md
Context Engineering
Context engineering is the discipline of curating and maintaining the optimal set of tokens during LLM inference. Unlike prompt engineering (crafting individual prompts), context engineering focuses on what information enters the context window and when.
Table of Contents
- Core Principles
- Context Management Strategies
- System Prompt Design
- Tool Design for Context Efficiency
- Long-Horizon Task Patterns
- Implementation Patterns
- Best Practices
- References
Core Principles
Context as a Finite Resource
LLMs have limited "attention budgets." As context length increases, models experience context rot—decreased ability to accurately recall information. The goal is finding the smallest possible set of high-signal tokens that maximize desired outcomes.
Key insight: More context isn't better. The right context is better.
The Context Pollution Problem
Every token added to context has costs:
- Increased latency and compute
- Diluted attention to important information
- Higher risk of hallucination from conflicting data
- Reduced model performance on retrieval tasks
Context Management Strategies
1. Context Trimming
Drop older conversation turns, keeping only the last N turns.
| Aspect | Details | |
|---|---|---|
| Mechanism | Sliding window over conversation history | |
| Pros | Deterministic, zero latency, preserves recent context verbatim | |
| Cons | Abrupt loss of long-range context, "amnesia" effect | |
| Best for | Independent tasks, short interactions, predictable workflows |
2. Context Summarization
Compress prior messages into structured summaries.
| Aspect | Details | |
|---|---|---|
| Mechanism | LLM generates summary of older context | |
| Pros | Retains long-range memory, smoother UX, scalable | |
| Cons | Summarization bias risk, added latency, potential compounding errors | |
| Best for | Complex multi-step tasks, long-horizon interactions |
3. Hybrid Approach
Combine trimming and summarization for optimal balance.
4. Session Memory
Persist reusable facts, preferences, and task state outside the context window. Load only the relevant slice for the current turn.
| Aspect | Details | |
|---|---|---|
| Mechanism | External store keyed by user, session, task, or resource | |
| Pros | Recovers long-range context without carrying all history | |
| Cons | Requires retrieval, freshness, and deletion policies | |
| Best for | Agents, project work, personalization, long-running workflows |
Separate durable memory from ephemeral scratchpads. Durable memory should contain stable facts and explicit decisions, not every intermediate thought.
System Prompt Design
Principles for Context-Efficient Prompts
- Clear and direct language: Avoid ambiguity that requires clarification turns
- Structured sections: Organize by purpose (role, capabilities, constraints)
- Minimal yet comprehensive: Include only what affects behavior
- Self-contained instructions: Reduce need for context retrieval
Example Structure
Tool Design for Context Efficiency
Just-in-Time Context Loading
Instead of front-loading all possible context, load information dynamically as needed.
Tool Design Principles
- Self-contained: Each tool returns complete, usable information
- Scoped: Tools do one thing well
- Descriptive: Names and descriptions guide LLM toward correct usage
- Error-robust: Return informative errors that don't pollute context
Long-Horizon Task Patterns
Pattern 1: Compaction
Periodically compress conversation history to reclaim context space.
Pattern 2: Structured Note-Taking
Agent maintains external notes, retrieving as needed.
Pattern 3: Sub-Agent Architecture
Delegate focused tasks to specialized agents with clean context.
Benefits:
- Each sub-agent has focused, clean context
- Main agent receives condensed results
- Parallelization opportunities
- Failure isolation
Implementation Patterns
Session Memory Manager
Token Estimation
Best Practices
- Treat context as precious: Every token has a cost. Include only information that improves task performance.
- Use progressive disclosure: Start minimal, expand context only when needed via tools.
- Design for recoverability: Agents should be able to reconstruct critical context from external sources.
- Monitor context health: Track token usage, retrieval accuracy, and task completion rates.
- Prefer structured over raw data: JSON, markdown tables, and clear formatting improve information density.
- Implement graceful degradation: When context limits approach, prioritize recent and high-signal information.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/context-engineering/SKILL.md
Popularity
- Repository stars
- 24
- 7-day trend score
- 16
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 5 May 2026, 5 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/itsmostafa/llm-engineering-skills/context-engineering)