Free 15-minute callFree 15-minute call →
艾维禾砺Vibe Coding LabIvheli · 1:1 coaching
Engineering deep dives

How to prepare context for AI

The same instruction with different material can produce very different results. Context engineering is about placing the most useful small part of the information in a limited window.

Updated 2026-11-113 min readFree guides · 60/96

From prompts to context engineering

Prompt engineering cares about how to phrase a task clearly; context engineering cares about what the model can see each time it judges. The latter includes:

  • System instructions
  • Available tools and their descriptions
  • The material you provide (files, data, web pages)
  • Conversation history and intermediate results
  • Examples (few-shot)

For the same task, different information can produce completely different results.

Why “more makes it fuzzier”

  • Context degrades: the more content in the window, the weaker the model’s ability to recall each item accurately
  • Attention is a limited budget: the model has to distribute attention across a lot of information, and irrelevant content dilutes the key parts
  • Position matters: in long sequences, information in the middle is more easily overlooked

So the principle is: find the smallest set of high-signal information, rather than stuffing in every document.

Write system instructions to “just right”

There are two failure modes:

  • Too detailed: every step hard-coded, so it breaks whenever a case was not covered
  • Too vague: “be professional and accurate”, leaving the model unsure of the concrete standard

The good approach is the middle: state the goal, boundaries and judgement criteria, give the necessary examples, and leave execution details to the model.

Few, clear tools

  • Each tool does one thing, and the description states when to use it and when not to
  • Too many tools make the model make mistakes in choosing
  • Design parameters so that errors are hard to make (for example, require absolute paths to avoid relative path mistakes)

The test: if a skilled person reading the description still cannot tell which tool to use, the model is even less likely to judge it correctly.

Typical examples, not a pile of edge cases

  • Pick two or three representative examples covering common cases and key differences
  • Do not stuff edge cases into the prompt; turn them into rules or tools instead
  • Examples are there to show what the expected shape looks like, not to list every possibility

Let the model fetch things itself

Rather than preloading all the material, let it fetch on demand:

  • Give it lightweight indexes: file paths, query methods, links
  • Read the specific content only when needed
  • Use directory structure, naming and timestamps to help it judge which file is useful

This is “progressive disclosure”: see the directory first, then go deeper layer by layer. The cost is that exploration is slower than preloading, and you need well-designed tools and navigation rules.

Three approaches for long tasks

  1. Compaction: when approaching the window limit, summarise the conversation and reopen; keep key decisions, open questions and implementation details
  2. Notes: have the model write important information outside the context and read it back when needed
  3. Sub-agents: hand subtasks to sub-agents with clean context and return only a conclusion of one or two thousand words

Choose by task: use compaction when there is a lot of back-and-forth; notes when there are clear milestones; sub-agents when exploration needs to run in parallel.

Lessons for everyday use

  • When assigning a task, give the expected result and judgement criteria first, then the necessary material
  • Separate materials: must-read, reference and ignorable, without mixing them together
  • On long tasks, have the AI restate known conclusions mid-way to confirm nothing was lost
  • Do not expect to give all the material at once; giving it step by step is more reliable

Checklist

  • Instructions state the goal, boundaries and judgement criteria
  • Only necessary material is included, with priority marked
  • The number of tools fits on one screen of explanation
  • Examples are typical, with edge cases handled by rules
  • Long tasks have compaction or note-taking mechanisms
  • At key points the AI restates conclusions to confirm no information is lost

Reference: key points adapted from Anthropic’s engineering blog post “Effective Context Engineering for AI Agents”, rewritten for everyday use.

Questions

What is the difference between context engineering and writing prompts?

A prompt is how you assign the task and mainly governs the system instruction; context engineering governs all the information the model can see at each inference: instructions, tools, material, history and examples. The latter determines what the model actually bases its judgement on.

Is more material always better?

No. The more information in the window, the more the model's attention is spread across each item and the weaker its ability to recall accurately; look for the smallest sufficient set of high-signal information.

How do I handle long tasks when context runs out?

Three common approaches: summarise and reopen when approaching the limit, have the model keep key information as external notes, or hand subtasks to sub-agents with clean context that return only a summary.

Want to apply this to your own work?

Read next

Share this article

Where should your idea start?

Bring an idea or a question to a free 15-minute call. Confirm the conversation language and time when booking.

Book a free 15-minute call

Where should your idea start?

Free 15-minute call →Free guides

Book a free 15-minute call

Contact

Booking formEnterprise AI implementation & system developmentSee enterprise services (official site)
Add us on WeChat, mention Vibe Coding and tell us what you want to do
Add us on WeChat, mention Vibe Coding and tell us what you want to do