Context Engineering: Give AI the Right Material
Context engineering for writing means choosing and organizing the text, rules, and reference material a language model receives before and during drafting. Prompt engineering deals with the wording of a request. Context engineering deals with everything the model reads as it writes. The right material, in the right order, matters far more than clever adjectives in a prompt.
When an AI draft sounds bland, repeats itself, or gets facts wrong, it is tempting to keep rewriting the request. Writers ask for more expertise, add emotional appeals, or make their instructions longer. Those changes may leave the underlying problem untouched. Depending on the tool, the model may also receive system instructions, project style guides, saved memory, research documents, tool results, and chat history.
If that material is disorganized or contradictory, a well-worded request may still produce generic prose. Managing the surrounding context helps you keep facts, voice, and structure consistent through repeated rounds of drafting.
How the context window works
A language model has a limited context window: the amount of material it can receive in a request.
The Transformer architecture introduced in Attention Is All You Need uses attention to relate tokens in a sequence. A larger input gives the model more material to sort through, but length alone does not tell us how much weight it will assign to a particular instruction.
Check long inputs for two common problems:
- Context drift: In a long session, a draft may repeat points, change its voice, or miss an earlier instruction. Irrelevant notes and old drafts make the useful material harder to locate.
- Unchecked claims: A fluent response can still misread a source note or skip a needed check. More material does not replace verifying the finished draft against its sources.
Placement matters too. In the tasks studied in Lost in the Middle: How Language Models Use Long Contexts, model performance was often highest when relevant information appeared near the beginning or end of a long input, and lower when it appeared in the middle. This long-context retrieval study describes the models and tasks tested, not a fixed rule for every writing tool.
The technical analysis of context engineering on Habr describes how accumulating unfiltered tokens through repeated drafting rounds dilutes attention and adds processing overhead. Aim for the smallest set of useful material that reliably supports the result you need.
The six layers of context in AI writing
You can organize a writing workspace into six layers. Use them to distinguish the model's built-in capabilities from the rules and material you supply.

| Layer | Operational Level | Content and Purpose | Mutability |
|---|---|---|---|
| Layer 0 | Pretrained Weights | Base language capabilities, grammatical patterns, and general web knowledge | Permanent and frozen |
| Layer 1 | System Instructions | Platform harness persona, safety rules, and technical tool formatting | Set by software harness |
| Layer 2 | Project Style Contract | Editorial voice, audience profile, banned vocabulary, and layout standards | Editable project baseline |
| Layer 3 | Curated Memory Dossiers | Cross-session decisions, terminology glossaries, and chapter milestones | Updated between sessions |
| Layer 4 | Dynamic Reference Retrieval | Specific source notes, interview excerpts, and factual data tables | Injected on demand per section |
| Layer 5 | Active Working Buffer | Immediate task instruction, section outline, and recent turn history | Changes with each generation |
Layer 0: Pretrained weights
Pretraining establishes the model's fixed parameters, or weights. These contain its vocabulary, grammar patterns, and general knowledge cutoff. They also carry habits learned from internet text: corporate clichés, overused transitions, and predictable sentence structures. You cannot change those weights during a writing session. You can supply material in the other layers to steer the model away from those habits.
Layer 1: System instructions
The application or its developer supplies the system instruction before the user starts a conversation. It sets the model's role, safety boundaries, and formatting requirements for tools. Users of standard consumer chat interfaces have little access to this layer, though specialized writing environments allow custom settings.
Layer 2: Project rules and style
Layer 2 holds the rules for the whole project: audience, technical depth, voice, formatting, and words or constructions to avoid. These rules usually stay the same across drafting rounds. Store them in a style guide you can reuse instead of typing directions like "write plainly" in every turn. The habits described in signs of AI writing can help you decide what to exclude.
Layer 3: Saved project memory
Layer 3 records decisions made during drafting: approved terminology, fixed character details, topics to omit, and completed chapters. Unlike the style guide, this record changes as the work progresses. Supply it when starting a fresh session so the approved decisions are available without the full conversation and its discarded drafts.
Layer 4: Retrieved source material
Dynamic retrieval supplies the facts needed for the current task. For a section on quarterly revenue, that might mean a financial table and two relevant executive quotes. The rest of the company's history stays outside the window. You do not need to load an entire book, archive, or meeting transcript to write a section that uses only a small part of it.
Layer 5: The current task and recent history
This layer holds the immediate request, section outline, and preceding paragraphs. It is where your drafting prompt belongs. Use it to specify what to write next and which of the supplied material to use.
Put the material in a useful order
For a long input, make the most important instructions easy to find. Put stable rules near the start and the immediate assignment near the end.
Keep stable rules at the beginning
Put system instructions, the project style guide, and core definitions at the top of the window. Keep this opening material unchanged across requests.
The Anthropic prompt caching documentation explains how its API can reuse a matching prompt prefix. Where caching is available and configured, this can reduce latency and cost. A stable opening also gives you one reliable place to maintain the editorial rules.
Make reference material easy to read
Long blocks of unbroken reference text make details easier to miss. Prepare that material before adding it:
- Separate source documents with clear headings.
- Turn dense factual passages into concise bullet points.
- Label numbers, dates, and proper nouns by category.
- Remove email greetings, conversational filler, and unrelated administrative text.
Put the current assignment at the end
Finish with the section outline, required length, and instructions about what to avoid in the current response. This keeps the current task visible next to the material the model should use for it.
Keep long drafts consistent
Generating a long document through one large prompt or an uninterrupted chat can lead to shifts in style and unsupported claims. Watch for changes in terminology or contradictions rather than assuming a particular turn count is safe.
For guides, whitepapers, and chapters, separate the project plan from the drafting conversation.
Write a specification, then draft in sections
Before drafting body text, create a master specification with:
- The full outline and an explicit objective for each section.
- An approved reference sheet defining terms, names, and concepts.
- The project style guide, including tone and instructions about what to avoid.
For each section:
- Open a clean session and insert your static project style guide as the opening prompt prefix.
- Load the approved terminology and completed milestones from your project memory file.
- Supply only the source excerpts, data points, or interview notes required for the active section.
- Issue a direct drafting prompt tied to that specific section outline, specifying target length and any section-specific negative rules.
- Review the generated text against your source material, paste approved prose into your master document outside the chat, and reset the temporary conversational history before moving to the next section.
A good outline before drafting helps each new section answer its own reader question while fitting the whole piece.
Retrieve the passages you need
Uploading ten PDF reports, five transcripts, and an entire website export can feel thorough. Check how much of that background the current section actually needs. Old drafts and unrelated notes are especially worth removing when the output becomes less coherent or stops following the project rules, a problem often called context rot.
Extract the paragraphs, tables, or quotations needed for the active section. Summarize long background documents into factual bullet points before loading them. Keep the original source passages in your local notes so you can verify the summary and check the finished prose.
Tell the model what a summary must retain
Some interactive tools compact a long conversation by summarizing older turns. Details can disappear when the next turn relies on that summary.
You can prepare your own handover before starting a fresh session. Tell the model which decisions the summary must retain:
Summarize our session progress for the next drafting phase. Retain: (1) all approved definitions in the technical glossary, (2) the established negative vocabulary rules, and (3) the list of completed outline sections and next milestones. Discard: all intermediate draft revisions, conversational acknowledgments, and raw source text already processed.
This directs the summary toward the decisions needed for the next section.
Keep research in a separate session
Use a separate session or research subagent to process dense documents. Give that assistant the 40-page paper or raw interview transcript and ask for the answers, data points, and short quotations you need. Copy its 300-word summary into the main drafting session.
Anthropic's guide to building effective agents describes a parallel research pattern in which separate workers return results to a coordinator. A writer can use the same division of work to keep raw research outside the active drafting session.
Worked examples
Example 1: unorganized prompt for a rollout update
A writer combines meeting notes, requests for an exciting introduction, and words to avoid in one prompt:
Before:
You are a world-class technology journalist. Write an introductory section about our enterprise software rollout. Make it engaging, captivating, and visionary. Here are some notes from our team meeting: John said security review took 4 weeks instead of 2. Sarah noted SSO testing revealed 2 timeout bugs. We moved launch from Nov 15 to Dec 3. Training is done. Documentation is finished. Do not use buzzwords like leverage or streamline. Keep it concise. Make sure readers feel excited about the future of work.
The request for a "world-class technology journalist" sets no useful standard for this update. The notes cover a delayed launch, testing bugs, and completed work; they offer nothing to support claims about the future of work. Ask for an account of those facts, and keep the vocabulary restrictions separate from the meeting notes.
A weak draft might read:
In today's rapidly evolving corporate landscape, seamless identity management stands as a transformative milestone for organizational agility. As enterprises navigate the shifting frontiers of digital infrastructure, robust authentication mechanisms serve as the bedrock of modern operational resilience. While unforeseen technical challenges temporarily recalibrated our initial deployment schedule, our team's unwavering commitment has successfully propelled this vital initiative forward, illuminating an exciting path toward the future of collaborative productivity.
This draft omits both launch dates, the review duration, and the bug count. "Recalibrated our initial deployment schedule" hides the date change, while "unwavering commitment" adds praise unsupported by the notes.
Example 2: structured context layers for the same update
The task and audience change deliberately here. The original request asks for a visionary introduction without naming its readers. The revision asks for a two-paragraph status update for departmental project managers because the available facts concern rollout progress. It also separates the style rules, source notes, and assignment. John and Sarah's names are cut because this update reports the work rather than who spoke at the meeting.
After:
Project Style Contract: - Role: Internal operations lead writing for departmental project managers. - Stance: Objective, practical, and direct. - Prohibited vocabulary: transformative, milestone, bedrock, landscape, leverage, seamless, agility. - Sentence structure: Plain subject-verb-object constructions. No introductory filler phrases.
Curated Source Dossier: - Initiative: Enterprise software rollout with single sign-on (SSO) testing. - Launch date: Moved from November 15 to December 3. - Security review: Took four weeks rather than the planned two. - Testing: Found two SSO timeout bugs. - Other work: Training and documentation are complete.
Immediate Drafting Assignment: - Task: Write a two-paragraph operational status update explaining the revised launch timeline using only the facts in the Source Dossier. - Requirement: State the dates, review duration, testing result, and completed work directly. The notes do not establish why the launch date changed, so do not claim a cause. Do not add speculative claims or promotional language.
A more useful briefing would read:
The enterprise software rollout has moved from November 15 to December 3. The security review took four weeks rather than the planned two, and SSO testing found two timeout bugs. Training and documentation are complete. The notes do not say whether the review or bugs caused the date change, so confirm that relationship before describing it as the reason for the move.

Example 3: keeping approved decisions during a reset
A writer reaches section four of a technical guide in a long chat session.
Before:
The fifty preceding turns contain these approved decisions alongside discarded material:
- The title is Enterprise API Design Guide. The audience is backend software engineers. Earlier reader profiles remain in the chat.
- The approved tone is practical, direct, and imperative.
- The terminology rule is to use "client error" for 4xx responses and "server fault" for 5xx responses.
- Approved text covers Section 1 (protocol baselines), Section 2 (authentication headers), and Section 3 (payload validation). Four superseded introductory drafts also remain.
- Section 4, Error Handling, must define standardized JSON error response payloads and HTTP status code mappings in three concise subsections: Status Code Mapping, Payload Schema, and Retry Guidelines.
- The team has ruled out vendor comparisons and historical protocol background. The thread still contains an abandoned outline organized by software vendor rather than technical principles, debates about early HTTP specifications, and colleagues' pasted feedback.
The writer enters their prompt:
Now write section four covering error handling. Follow the same style as before and remember our earlier discussion about keeping it practical.
The resulting section follows the abandoned vendor outline, includes historical background on early HTTP specifications, and uses "user mistakes" and "server problems" instead of the approved terms. These departures from the plan give the writer specific problems to address before continuing.
After:
The writer starts a fresh session with the approved decisions. They leave out superseded drafts, the rejected outline, and resolved debates because those no longer belong in the assignment:
Project Style Contract: - Document: Enterprise API Design Guide, Section 4 (Error Handling). - Audience: Backend software engineers. - Tone: Practical, direct, and imperative. - Terminology rule: Use the term "client error" for 4xx responses and "server fault" for 5xx responses.
Approved Structural Context: - Section 1 covered protocol baselines; Section 2 covered authentication headers; Section 3 covered payload validation. - Section 4 objective: Define standardized JSON error response payloads and HTTP status code mappings.
Immediate Drafting Assignment: - Write Section 4 (Error Handling) in three concise subsections: Status Code Mapping, Payload Schema, and Retry Guidelines. - Adhere strictly to the terminology rules. Do not include vendor comparisons or historical protocol background.
Check the next draft against this list. Does it use the approved terms and cover all three subsections? Has it reintroduced vendor comparisons or historical background? Compare it with the completed chapters and source notes before accepting it; a clean session still needs editorial review.
Five common context engineering mistakes
1. Loading unedited transcripts
Raw audio transcripts, customer interviews, and email chains contain false starts, tangents, filler, and repeated phrases. Before loading them, extract the useful facts and preserve the original material for verification.
2. Treating chat history as an unlimited archive
A chat interface can keep accepting messages while earlier decisions become harder to track. If the draft starts contradicting them, record what matters and begin a fresh session for the next chapter or topic.
3. Hiding rules inside reference files
Instructions buried between large blocks of research can be easy to miss. Keep editorial rules in a separate style guide at the top of the input. Repeat any immediate restrictions beside the drafting request.
4. Leaving unused tools enabled
Agent environments support plugins, external integrations, Model Context Protocol servers, and specialized skills. Each active tool adds definitions and usage schemas to the system prompt.
Unused tools can add instructions that are irrelevant to the writing task. If your application lets you choose tools, enable those needed for the current phase.
5. Skipping the source check
Good context does not remove the need for human verification. A model can misread an ambiguous note or combine adjacent bullet points into an inaccurate claim.
Before publishing, compare each factual claim with your source material. Then review the prose for clarity and repetition using the signs of AI writing as one editing checklist.
Set up your writing context in five steps
Step 1: save the project style guide
Save the Layer 2 rules in STYLE.md in your project folder. Read the file before reusing it: does it still describe the article you intend to write? If the audience or assignment has changed, revise the relevant rule before drafting. Keep one current version rather than pasting corrections after an outdated guide.
Step 2: prepare the source document
Gather research, interview notes, and primary data. Group related facts under descriptive Markdown headings and write each data point as a clear statement.
OpenAI guidance on prompt engineering and reference text recommends supplying relevant reference material when an answer needs information beyond the model's training. Check the output against those references before using it.
Step 3: record decisions in a memory file
Save the Layer 3 decisions in MEMORY.md and update it after each section or editorial review. Use a glossary for approved terms and a milestone log for completed sections. Give each completed section a one-sentence summary so you can check what the document has already covered.
When a decision changes, replace its old entry. Do not leave two conflicting instructions for the next session. Remove rejected outline ideas once the replacement is approved, and check that any handover summary preserves that decision.
Step 4: check section boundaries
Read each new section beside the end of the previous one. Check that its opening continues the discussion without restating an earlier conclusion. Compare its scope with the outline: a paragraph may be useful but belong in another section. Move it to the right place instead of keeping two versions of the same point.
If one paragraph needs work, request a revision of that paragraph or edit it yourself. Read the surrounding paragraphs again afterward to check the transition.

Step 5: edit the prose yourself
Review generated prose before publishing. Even a draft produced from carefully organized context needs attention to rhythm, transitions, and personal anecdotes. The techniques in how to humanize AI text manually help you adjust sentence lengths, remove mechanical phrasing, and keep your own voice in the finished piece.
Prompt engineering and context engineering compared
| Dimension | Prompt Engineering Focus | Context Engineering Architecture |
|---|---|---|
| Primary Focus | Phrasing individual prompts and finding persuasive adjectives | Organizing the entire active workspace |
| Material managed | The immediate request | Rules, sources, memory, tool results, and the immediate request |
| Long Draft Strategy | Attempts a full draft at once or repeatedly prompts in the same conversation | Drafts sections from a specification and resets sessions |
| Common Failure Mode | An unclear request | Missing sources, conflicting rules, and forgotten constraints |
| Memory Management | Relies on chat history to retain earlier decisions | Uses memory files and directed summaries |
| Cost and Latency | Recalculates the full context repeatedly without optimization | Uses prompt prefix caching and selective document retrieval |
| Primary Tooling | User chat box and system prompts | Project specifications, memory files, and selected source notes |
Frequently asked questions about context engineering
Does context engineering require coding skills or developer tools?
No. Developers use it to build autonomous software agents, but writers can do this work with plain text documents and standard desktop applications. Organize project rules, sources, and memory into Markdown files, then paste them into your writing interface in a structured order. You do not need programming knowledge or command-line tools.
How does context engineering differ from retrieval-augmented generation?
Retrieval-Augmented Generation uses mathematical embeddings and databases to search an archive and insert matching document chunks into a prompt. It automates the retrieval of source material.
Context engineering covers the wider set of decisions: which rules to set, how to format sources, what to remember between sessions, where to put each part of the input, and when to clear the window. Retrieval supplies material; context engineering organizes it for attention and reasoning.
What are the earliest warning signs that context rot is affecting a draft?
Look for banned words returning, a point from three paragraphs earlier presented as new, or precise figures replaced by vague claims. These are reasons to review the working material, though they do not establish why the draft went wrong. Compare the passage with its source notes and the current outline before deciding whether to revise it or reset the session.
Why not simply rely on models with million-token context windows?
A larger window gives you more room for sources, but you still have to decide which ones belong in the request. For a section that needs one table and two quotations, start with those passages. Include more background when the assignment calls for it.
Check response time and, if you use an API, input costs during your own workflow. These depend on the service and its caching rules. Compare whether supplying more material improves the draft enough to justify keeping it in subsequent requests. Window capacity alone is not a reason to resend the whole archive.
How often should a writer reset or compact their drafting context?
Consider resetting after a self-contained section, chapter, or major change of topic, especially if the draft starts repeating or contradicting itself. Before resetting, record approved terms, structural decisions, and key facts in your memory file.