Context engineering
Deciding what instructions, documents, tools and history a model sees at each step.
Bookmark
Bookmarks are kept in your free account, so you can find this page again on any device.
Sign in to bookmarkOn this page
Overview
Context engineering widens prompt engineering from a single message to everything that ends up in the model's context window: the system prompt, instruction files such as AGENTS.md, retrieved documents, tool definitions, tool results and the conversation so far. Each token competes for the model's attention, so more is not better.
The skill is choosing what to include, what to leave out and when to load it. Typical techniques are short always-on instructions with details loaded on demand (the idea behind Agent Skills), retrieving only the relevant passages, summarising or clearing old history in long sessions, and handing focused work to subagents with their own clean context.
What you will practise
- Keep always-on instructions short and move detail into files loaded on demand
- Retrieve only the passages a step needs
- Recognise when a long session has degraded and compact or restart it
- Delegate noisy searches to subagents with a precise brief
Learning paths
- Agent Skills essentials
A free Agent Skills course: learn what SKILL.md packages are, write and share your own, port it across agents and review third-party skills before installing.
- AI-assisted software engineering
Learn AI-assisted software engineering on real repositories: set up coding agents, give them good instructions, review their diffs and run several in parallel.
- LLMOps: observability, evals and cost
Learn LLMOps in practice: trace every request, gate changes with evals in CI, calibrate judges and keep token spend visible and under control in production.
- Prompt and context engineering
A prompt and context engineering course: go from single prompts to deciding what a model sees at each step, from instructions and examples to files and tools.
Tutorials
- Agent memory and compaction in practice
Keep long Claude Code sessions accurate with compaction, CLAUDE.md, auto memory, subagents and a summarise-and-restart routine, and know what survives each.
- Cut LLM costs with prompt caching and token budgets
Lay out prompts so the provider can cache them, measure tokens before you send, and use batch processing and model routing to cut what each request costs.
- Subagents in Claude Code: delegate without losing control
Define Claude Code subagents with their own tools, model and permissions, keep noisy work out of your main context, and avoid conflicts in parallel runs.
- CLAUDE.md and AGENTS.md: instruction files for coding agents
CLAUDE.md vs AGENTS.md: what to put in each, where Claude Code, Codex, Cursor and Copilot look for them, and how to keep one source of truth without drift.
- Context engineering techniques: what the model should see
What to put in a model's context at each step, what to leave out, and how instruction files, retrieval and tools fit.
- Cursor agent basics: tasks, rules and skills
Use Cursor's agent on a real task: scope it, plan first, use checkpoints, add project rules, AGENTS.md and skills, and review every change before you keep it.
Workflow recipes
- Understand an unfamiliar codebase with an AI agent
Get a read-only map where every claim cites a file and line, check the citations, trace one path and test what you learned.
- Give your coding agent current docs with Context7 or llms.txt
Stop your coding agent using outdated APIs: connect Context7 over MCP, point it at a library's llms.txt, or install a vendor skill, then check it worked.
- Write a useful AGENTS.md: example, template and test
An AGENTS.md example and template with build and test commands, conventions and traps, plus a before-and-after task that shows whether the file actually helps.
Articles
- Harness engineering: why the setup around a coding agent matters as much as the model
Harness engineering is designing the instructions, tests, limits and feedback loops a coding agent works in: what OpenAI reported, the critique, where to start.
- Context rot: why long contexts fail and what to do
Why models get worse as their context fills up, from lost-in-the-middle to distractors and poisoned context, and the practical fixes for agents and RAG.
- Controlling LLM costs without hurting quality
Where LLM spend actually goes (context, retries, agent loops, output) and the levers that cut it without hurting quality: caching, routing, batching, budgets.
- AGENTS.md vs Agent Skills: which one you need, and where MCP fits
AGENTS.md vs Agent Skills: what an instruction file and a skill each do for a coding agent, when to use which, and how MCP servers fit alongside both of them.
- RAG vs long context vs fine-tuning: how to choose
What each approach changes, what it costs, where it fails, and a practical order to try them in before you commit to one.
- What is context engineering?
Context engineering is deciding what a model sees at each step. Why the term replaced prompt engineering for people building agents, and what the work involves.
Tools for this skill
Agent Skills specification
The open specification for SKILL.md skill folders, published at agentskills.io.
AGENTS.md
Open format for instruction files that coding agents read in a repository.
Context7
Serves current, version-specific library documentation to coding agents over MCP.
Deep Agents
LangChain harness with planning, files and subagents.
Letta
Platform for stateful agents that keep long-term memory across sessions.
llms.txt
A proposed Markdown file at a site's root that points models to its key docs.
Mem0
Memory layer that extracts facts from conversations and retrieves them later.
Key terms
Words you will meet while learning this, defined in the glossary.
- Agent memory
Information an agent keeps beyond a single context window, such as user preferences, past decisions or task notes, and retrieves when needed.
- Compaction
Summarising earlier parts of a long conversation and replacing them with the summary to free context space for the work still to do.
- Context engineering
Deciding what information, tools and history a model sees at each step, and what to leave out, to get the result you want.
- Context isolation
Running a subtask in a separate context window so raw tool output and intermediate noise never enter the parent conversation.
- Context poisoning
When a wrong fact, hallucination or bad tool result enters an agent's context and keeps steering later steps in the wrong direction.
- Context rot
The gradual decline in a model's accuracy and instruction-following as its context fills up with long, stale or irrelevant content.
- Context window
The maximum number of tokens a model can consider in one request, covering both the input you send and the output it writes.
- llms.txt
A proposed Markdown file at a website's root that summarises the site and links to its key documentation pages for language models.
- Lost in the middle
The finding that language models use information at the start and end of a long context better than information buried in the middle.
- Progressive disclosure
Loading only skill names and descriptions up front, and the full instructions or bundled files only when a task needs them.