TNS
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
NEW! Try Stackie AI
AI / AI Engineering / Large Language Models

Context Engineering: Going Beyond Prompt Engineering and RAG

What is context engineering and how does it differ from traditional prompt engineering and RAG? A guide for AI-assisted developers.
Jul 8th, 2025 5:35am by
Featued image for: Context Engineering: Going Beyond Prompt Engineering and RAG
Image via Unsplash+. 

The initial wave of large language model (LLM) development centered on prompt engineering – carefully crafting the right question or instruction to coax a desired answer. LLM developers and enthusiasts prided themselves on clever one-shot prompts like “You are an expert X. Do Y like Z”; and the term “prompt engineer” gained traction accordingly. However, as LLM-powered applications have grown more complex and production-ready, developers have realized that achieving good results is about more than formulating a clever query. Enter context engineering, a broader and more powerful approach that focuses on everything the model knows and perceives when it generates a response.

This article introduces context engineering, explains why it matters for LLM application development and shows how it differs from traditional prompt engineering and retrieval-augmented generation (RAG).

What is Context Engineering?

Context engineering is the discipline of building dynamic systems that supply an LLM with everything it needs to accomplish a task. To understand this, it’s essential to realize that an LLM’s “prompt” is not just a single string of text, but an entire context window of input the model sees before producing output. This context includes multiple components beyond the immediate user question.

Context engineering is the discipline of building dynamic systems that supply an LLM with everything it needs to accomplish a task.

For example, a well-engineered context might encompass a system message with instructions that set the model’s role and rules, the user’s query or command, the summary of conversation history or state so far, any long-term memory or stored facts the AI has learned, retrieved documents or data fetched from external sources, and even the outputs of tools or functions that the AI can invoke.

In short, context engineering treats “everything the model sees before it generates a response” as critical input.

Context engineering involves assembling a variety of components, including a basic prompt, memory, output from RAG pipelines, output from tool invocation, well-defined and structured output format, and guardrails. While guardrails may exist outside of the context, it’s a common practice to include the rules that control the behaviour of an LLM within the prompt. Note that guardrails is an optional component of context engineering.

Crucially, context engineering shifts the mindset from just writing prompts to designing a system. The prompt you write becomes only a subset of that system. Equally important is how you structure and manage all the supporting information. This includes careful attention to formatting and managing the context window limits. LLMs have a fixed token limit for input, so a context engineer must decide which information is most relevant and how to compress or truncate less-critical content. In essence, context engineering is a holistic approach that involves curating and optimizing the model’s short-term “working memory” each time it is invoked.

Context Engineering vs. Prompt Engineering

How is context engineering different from the prompt engineering techniques that developers are already familiar with? The key difference is scope. Prompt engineering typically refers to crafting an effective prompt string, such as phrasing the user’s request and instructions clearly to guide the model. It’s often a one-off, focusing on “what to say to the model at a moment in time.”

Context engineering is a superset of prompt engineering.

In contrast, context engineering is concerned with “what the model knows when you say it – and why it should care.” Instead of merely tweaking the wording of a single prompt, context engineering considers the entire interaction, including whether the information should be included before and after the primary instruction, how to incorporate memory from previous turns and how to format retrieved facts, among other factors. Prompt engineering occurs within the context window, whereas context engineering determines what fills that window. So, context engineering is a superset of prompt engineering.

Another way to contrast the two is by examining their outcomes and longevity. A prompt engineering mindset often leads to trial-and-error tinkering, where you tweak the phrasing, run the model and see if the output improves, repeating the process as needed. It might yield a good result for one input, but then fail for a slightly different case, necessitating further adjustments.

Context engineering, on the other hand, emphasizes systematic, repeatable frameworks. By designing how context is generated and maintained, you aim for consistent performance across various inputs and scenarios. It’s more of an architectural approach akin to software architecture, rather than writing a single subroutine. This becomes crucial for applications that must handle edge cases and varied user queries without requiring manual prompt tuning each time.

In summary, prompt engineering involves writing accurate and precise instructions that elicit the expected response from the LLM. In contrast, context engineering is about constructing the entire information environment so that the model can handle anything that comes its way. Developers are finding that the latter is the core competency required for advanced LLM-driven systems.

Context Engineering vs. RAG

Retrieval-augmented generation, commonly referred to as RAG, combines a search step with a large language model, allowing authoritative passages from an external knowledge store to be fetched and injected into the prompt just before generation. This enables the model to answer with up-to-date facts, rather than relying solely on its frozen training data. The pattern first appeared in a 2020 paper and is now standard practice at companies such as Microsoft, Google and Nvidia, because it grounds responses and sharply reduces hallucinations.

RAG becomes one of the components that context engineering relies on for grounding the responses in factual data.

Context engineering, by comparison, is the broader craft of curating everything the model sees – system instructions, conversation history, tool outputs and any retrieved text – and arranging those elements inside the limited context window in a way that the model can use. RAG becomes one of the components that context engineering relies on for grounding the responses in factual data.

RAG addresses a specific problem that ensures accurate answers when the corpus exceeds the model’s context window. However, its efficacy still relies on context engineering to determine which snippets are relevant, how many tokens to allocate and where to place them so that the user’s question remains salient. Experiments show that if retrieval returns irrelevant or repetitive passages, those extra tokens crowd the window, push critical prompts out of focus and allow hallucinations to creep back in despite the use of RAG.

Developers attempted to bypass retrieval by transitioning to long context models that ingest 128,000 tokens or more. However, benchmarks reveal higher latency, increased GPU memory usage and a decline in quality once the window fills with low-value text. RAG avoids those costs by sending only a handful of top-ranked passages, although it introduces new infrastructure, such as vector stores and retrievers, that must be maintained and tuned. A pragmatic guideline is to choose RAG whenever the knowledge base is larger or more dynamic than the context window, and to rely on long context only when a self-contained document fits comfortably inside the limit.

Context engineering transforms LLMs from being simple chatbots to the brain behind powerful autonomous agents.

Even while designing a simple RAG stack, you must decide how to embed the retrieved passages. Positioning, formatting and compression are context-engineering choices that influence final accuracy.

In short, RAG is a potent tactic embedded within the broader discipline of context engineering. The latter orchestrates retrieval alongside compression, memory, placement and formatting to deliver precisely the correct information at exactly the right moment.

Conclusion

Context engineering transforms LLMs from being simple conversational chatbots to the brain behind powerful autonomous agents. By deliberately curating system instructions, memory, retrieved knowledge, tool outputs and guardrails within the finite context window, developers provide agents with the situational awareness necessary to reason, decide and act autonomously across diverse tasks.

The discipline also enforces guardrails, compresses noise and balances token budgets, ensuring decisions remain grounded and efficient at runtime. In agentic workflows, where one agent’s output feeds another, consistent context design becomes the protocol that preserves intent integrity, reduces error propagation and ultimately elevates end-to-end system performance, overall reliability and user trust.

Group Created with Sketch.
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.