Do You Still Need RAG and Agents in the Era of Long Context?
This article examines whether million-token context windows make retrieval-augmented generation (RAG) and external knowledge mechanisms obsolete. It explains why capacity is not the same as usable knowledge, breaks down the real costs of long context across cost, latency, maintainability, and auditability, and clarifies how RAG and long context divide the work between working memory and external memory. It also covers why agents depend on externalized knowledge and state, and offers a practical selection framework for building an observable, elastic knowledge supply chain.
1. Define the Problem First: Long Context Is Not Usable Knowledge
The industry has recently entered a race over context capacity. One cloud vendor’s flagship model has pushed its window to roughly one million tokens, a team behind an AI coding tool has set a new record by combining a million-token window with a trillion-parameter model, and another vendor is reportedly testing a two-million-token context. Numbers like these make it tempting to conclude that if you can fit an entire book into a single prompt, retrieval-augmented generation (RAG) should retire.
That inference skips a critical step: being able to fit something does not mean you can use it well. The context window solves a capacity problem, while knowledge supply has to solve relevance, freshness, and traceability. Load 500,000 words of project documentation into a prompt and the model can indeed read it, but output quality depends on whether it can locate the right few passages at the right moment and cite them consistently along its reasoning chain. The widely observed “lost in the middle” effect shows that recall for details in the middle of a long sequence is usually lower than for the beginning and end. This has nothing to do with window size and everything to do with how attention is allocated.
A more accurate statement is this: long context reduces the need for RAG on capacity, but not its need for knowledge governance.
2. The Real Cost Across Four Dimensions
Deciding whether you need external retrieval is not just about whether content fits. You have to account for the total cost.
- Cost: attention computation and memory usage grow superlinearly with sequence length, and per-request token charges rise linearly with input length. Sending stable background material with every request means paying repeatedly for the same knowledge.
- Latency: time to first token correlates positively with input length. For an agent built for interactive scenarios, carrying the full context on every turn noticeably degrades the user experience.
- Maintainability: updating knowledge means reorganizing an entire prompt, which makes fine-grained version control and canary releases difficult. On the retrieval side, you only update the index and the chunks.
- Auditability: compliance and troubleshooting require showing which passage of which document an answer came from. Implicit citations inside a long context can hardly provide a stable evidence chain.
A rough rule of thumb for splitting the load: a few hundred to a few thousand tokens of stable background (role definition, output specification, current task state) belongs in a resident context; knowledge above ten thousand tokens that needs to be filtered dynamically per query is more economical to hand to retrieval.
3. Where RAG and Long Context Divide the Work
The two are not substitutes. They are knowledge supply mechanisms at different levels. Think of it as a division between working memory and external memory: the context window is a workspace with limited capacity but very fast access, while the retrieval system is external memory that can be expanded on demand.
The more practical engineering combination is to use retrieval first to narrow candidates from the millions down to a few thousand, then place that high-confidence content into a long context for deep reasoning and cross-passage integration. The value of long context here is not to replace retrieval but to hold more retrieved fragments, which enables cross-document comparison, reasoning over long tables, and multi-round revision—tasks that previously required repeated back-and-forth.
A schematic layered logic:
def build_context(query, session, kb):# Layer 1: a small amount of resident, stable informationparts = [session.system_spec, session.task_state]# Layer 2: retrieve on demand, with a budgethits = kb.search(query, top_k=8, max_tokens=3000)parts.extend(f"[{h.doc_id}#{h.span}] {h.text}" for h in hits)# Layer 3: enable long context only when cross-document integration is neededif need_global_reasoning(query):parts.extend(kb.expand(hits, max_tokens=60000))return "\n\n".join(parts)
4. Why Agents Depend More on External Knowledge
What sets an agent apart from single-turn question answering is its multi-step loop of decide, act, and observe, which creates two rigid requirements.
First, state cannot be carried by context alone. History in a multi-step task expands quickly, and stuffing the entire trace back into the window is both expensive and prone to making the model forget earlier constraints. A common approach is to externalize state into structured storage and inject only the current subgoal and the most recent few observations into the prompt.
Second, knowledge and action must be decoupled. Tool descriptions, interface contracts, business rules, and permission boundaries are metadata that changes frequently; delivering them through retrieval or configuration is more controllable than hardcoding them into the system prompt. A typical loop looks like this:
while not done:plan = llm.decide(goal, memory.summary(), retrieved_rules)obs = tool_registry.invoke(plan.tool, plan.args) # separate action from knowledgememory.push(obs)if memory.cost_exceeded():memory.compress() # summarize and compress, archive to storage if needed
The conclusion is clear: an agent does not have to use one specific retrieval approach, but some externalized mechanism for knowledge and state must exist. Without that layer, both the stability and the operability of multi-step tasks collapse.
5. A Practical Selection Framework
- Layer your knowledge first: keep stable specifications resident, retrieve dynamic knowledge, and archive massive cold data to object storage for on-demand pulls.
- Set a context budget: define separate limits for system instructions, retrieved fragments, tool returns, and conversation history, and trigger compression or summarization when a limit is exceeded.
- Prefer hybrid retrieval: run keyword recall and vector recall in parallel, then converge with a reranking model, which significantly reduces noise interference in a long context.
- Build an evaluation loop: use a fixed question set to measure hit rate, latency, and per-request cost for “pure long context” versus “retrieval plus long context,” and decide with data rather than intuition.
- Strengthen observability: feed retrieved fragments, citation IDs, and token consumption into logging services and monitoring alerts to form a traceable chain.
- Scale elastically: deploy the inference service and the retrieval service separately on a container platform so they can scale independently, preventing long-context requests from overwhelming the online path.
6. Conclusion
A million-token context is a capability upgrade, not an architectural verdict. It turns “read all the material at once” from impossible into possible, but the four constraints of cost, latency, maintainability, and auditability remain. For RAG, the center of value is shifting from “solving what does not fit” to “selecting accurately, retaining reliably, and tracing sources.” For agents, an externalized knowledge and state mechanism is an engineering necessity, and its specific form can be tailored per scenario. On Baidu AI Cloud, combining object storage, a container platform, logging services, and monitoring alerts into an observable, elastically scalable knowledge supply chain is a sound path that balances effectiveness and cost.
