const files = await readAllFiles('src');
const messages = [
{ role: 'user', content: files.join('\n') + task },
];const files = await searchRelevantFiles('src', task, { limit: 5 });
const context = files.map((f) => `<file path="${f.path}">\n${f.text}\n</file>`);
const messages = [
{ role: 'user', content: `${context.join('\n')}\n<task>${task}</task>` },
];A few relevant files, tagged as data, keep the context small and focused, which gives better answers.
Prompt engineering shapes the instructions. Context engineering decides everything the model sees: instructions, retrieved docs, tool results, memory and history.
Long contexts dilute attention, and key facts get lost among irrelevant text. Models often use information in the middle of a long context less well.
Trim or summarize long tool outputs, drop old steps that no longer matter, and load documents only when the task needs them.