# Context engineering

> Context Engineering: What It Is and How to Test It. Canonical page: <https://zapple.tech/glossary/context-engineering/>

Context engineering is deciding what an AI model sees when it answers: instructions, message history, tools, retrieved documents and memory. LangChain's documentation defines it as providing the right information and tools in the right format so the model can finish a task. The context is an artefact you can test, review and version.

## What is context engineering?

LangChain's documentation on [context engineering](https://docs.langchain.com/oss/python/langchain/context-engineering) defines it as "providing the right information and tools in the right format so the LLM can accomplish a task". In plain terms: you decide what the model sees, because the model answers from what it is given.

That includes more than the instruction. LangChain splits it into model context (instructions, message history, tools and response format), tool context (what tools can read and write) and life-cycle context (what happens between calls, such as summarizing a long history). The decision it helps with is where to spend effort when an AI feature gives wrong answers: on a better model, or on what the model is handed.

## How is it different from prompt engineering?

Prompt engineering tunes the wording of an instruction. Context engineering is wider: the instruction is one input among several, and the others can change between calls. A perfect prompt cannot make up for a missing document, a stale instruction file or a tool result that came back empty.

It also overlaps with two checks we cover elsewhere. Scoring whether retrieved documents were right is [RAG evaluation](/glossary/rag-evaluation/), and checking that an answer stays inside its sources is [groundedness](/glossary/groundedness/). Context engineering is the step before both: choosing what goes in.

## What sources make up the context, and what fails in each?

| Context source | What fails when it is wrong or stale | The check that catches it |
|:--|:--|:--|
| System instructions | The agent follows an old rule or two rules that conflict | Review the file on every change; run a fixed set of cases after it |
| Repository rules file | A coding agent uses the wrong build command or house style | A change to the file goes through code review |
| Retrieved documents | The answer cites a page that is out of date | A groundedness and retrieval score on a labelled set |
| Tool results | An empty or truncated result is treated as "no data" | Cases where each tool returns an error, nothing or too much |
| Conversation history | Early details are lost or contradicted late in a long session | A long-session case that checks an early fact |
| Memory | An old preference or correction is applied where it no longer fits | Review what memory holds; clear it between test runs |

Instructions, tools, message history and memory are named in the [LangChain](https://docs.langchain.com/oss/python/langchain/context-engineering) and [Claude Code](https://code.claude.com/docs/en/memory) documentation; retrieved documents are our addition. The failure and check columns are our reading, not those vendors' statements.

## When output is wrong, is it the model, the prompt or the context?

LangChain says LLMs fail for one of two reasons, either the model is not capable enough or the "right" context was not passed, and that "more often than not" the second is what makes agents unreliable. That is a vendor's claim, not a measured rate. Our rule of thumb for a single bad answer:

1. Log exactly what the model received for that case.
2. Ask whether a person given only that input could answer correctly.
3. If not, add the missing fact and rerun. A correct answer now means a context fault.
4. If the answer is still wrong with complete context, look at the prompt, then at the model.

This tells you whether to spend on prompt work, retrieval work or a model change. Our [AI QA adoption](/services/ai-qa-adoption/) service covers tool choice, a measured pilot, written working rules and training.

## Who should own the context files your coding and testing agents read?

Give each file one named owner and review changes like code. Anthropic's [documentation](https://code.claude.com/docs/en/memory) says Claude "treats CLAUDE.md files and auto memory as context" and that they "aren't enforced configuration", so a rule written there is a request, not a guarantee. The same page describes a prompt audit that looks for outdated instructions, references to files that do not exist, and files that contradict each other.

Formats differ across tools. [AGENTS.md](https://agents.md/) describes itself as "a README for agents". GitHub's [documentation on repository instructions](https://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/add-custom-instructions/add-repository-instructions) says that when Copilot is working, the nearest AGENTS.md file in the directory tree takes precedence. Our judgment: if two files can disagree, someone must own the tie-break, and a test should show which one the agent followed. The [agentic test case standard](/blog/test-automation-methodologies/cige-agentic-test-case-standard/) we published shows one way to write such cases. For agents that write or change code, read the [AI code review checklist](/blog/types-of-automation-testing/ai-code-review-checklist/) next, and for agents in general, [how to test AI agents](/blog/types-of-automation-testing/how-to-test-ai-agents/). Where a model grades another model's output, see [LLM-as-a-judge](/glossary/llm-as-a-judge/).

## What does context engineering not solve?

Better context raises the odds of a right answer; it does not check the answer. Output still needs tests, review and an evaluation set. More context is also not better by default: Anthropic's [context windows documentation](https://platform.claude.com/docs/en/build-with-claude/context-windows) says that as token count grows "accuracy and recall degrade", a phenomenon it calls context rot. A fuller window can make results worse. In our view context also drifts, because files and documents change, so a check that passed last month proves little today.

## What does Zapple.Tech do about it?

If you are not sure what your AI features are given when they answer, start with the evidence. Zapple.Tech starts with a one-week QA audit of one product area. It looks at its tests, pipeline and release process, and ends in a written report on what is at risk and what to fix first, plus a pilot plan you can run with Zapple.Tech or without it. Read more on the [QA audit and assessment](/services/audit-and-assessment/) page.

Tell us about your AI feature in the form below.

## FAQ

### What is context engineering?

Context engineering is choosing and shaping what an AI model sees before it answers: instructions, message history, tools, retrieved documents and memory. LangChain's documentation defines it as providing the right information and tools in the right format so the model can accomplish a task.

### What is the difference between context engineering and prompt engineering?

Prompt engineering is about the wording of an instruction. Context engineering covers everything the model receives, of which the instruction is one part. In LangChain's description, model context holds instructions, message history, tools and the response format.

### Why does context engineering matter for AI coding agents?

A coding agent works from what it is given: the files it reads, the tool results it gets and the instruction files in the repository. AGENTS.md describes itself as a README for agents. If those files are wrong or out of date, the agent's output follows them.

### How do you test whether an agent has the right context?

Log what the model received for a failed case, then check it against what a person would need to answer. Rerun the case with the missing fact added. If the answer is now right, the fault was in the context, not the model.

## Sources

- [LangChain documentation, Context engineering in agents (current docs)](https://docs.langchain.com/oss/python/langchain/context-engineering)
- [Anthropic documentation, Context windows (current docs)](https://platform.claude.com/docs/en/build-with-claude/context-windows)
- [Claude Code documentation, How Claude remembers your project (current docs)](https://code.claude.com/docs/en/memory)
- [AGENTS.md, a README for agents (current site)](https://agents.md/)
- [GitHub Docs, Adding repository custom instructions for GitHub Copilot (current docs)](https://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/add-custom-instructions/add-repository-instructions)
