All posts
AI Strategy

Context Engineering for Agentic Systems: Beyond Retrieval-Augmented Generation

Master context engineering for AI agents: compression, routing, and assembly techniques for reliable production systems beyond basic RAG.

By Brightlume Team

Understanding Context Engineering in Modern AI Systems

Retrieval-augmented generation (RAG) solved a critical problem: how to give language models access to external knowledge without retraining them. But RAG was always a halfway measure. It treats context as a static retrieval problem—fetch the most relevant documents, concatenate them, and hope the model reads them correctly.

Context engineering moves beyond this. It treats context as a first-class engineering problem: how to assemble, compress, route, and evolve the information an agent needs to make decisions reliably in production.

This distinction matters because agents operate differently from chatbots. An agent makes autonomous decisions, executes actions, maintains state across multiple steps, and often operates under latency and cost constraints that don't exist in interactive chat. A chatbot can afford to retrieve 10 documents and let the user read them. An agent cannot. It needs exactly the right context, in exactly the right format, at exactly the right time—or it fails silently in production.

Context engineering is the discipline that makes this possible. It's the difference between a pilot that works in a lab and a system that ships reliably for 90 days and beyond.

The Three Pillars of Context Engineering

Context engineering rests on three interconnected practices: assembly, compression, and routing. Each solves a distinct problem, and all three must work together for reliable agentic systems.

Context Assembly: Building the Right Information Landscape

Context assembly is about deciding what information an agent should have access to, and in what form. This isn't just retrieval—it's architectural design.

When you're building a digital coworker using AI agents, you need to think about what decisions that agent makes and what information it needs to make them well. A procurement agent, for instance, doesn't just need vendor data—it needs vendor data in the context of your organisation's policies, risk tolerance, and prior relationships. A healthcare agent managing patient workflows needs clinical guidelines, but also institutional protocols, regulatory constraints, and individual patient history.

Assembly means structuring these information sources so the agent can access them efficiently. This typically involves:

Layered context hierarchies: Not all information is equally relevant at every decision point. A healthcare agent screening new patients might start with demographic and chief complaint data (high relevance, low volume), then expand to historical records only when needed. This layering reduces token usage and latency.

Semantic chunking: RAG systems often chunk documents by token count or page breaks. Context engineering chunks by semantic meaning—grouping related facts, decisions, and constraints together. A policy document isn't split at 512 tokens; it's split at logical policy boundaries.

Structured knowledge representation: Instead of storing everything as unstructured text, context engineering uses structured formats—JSON schemas, knowledge graphs, decision trees—that agents can parse and reason over directly. This is especially critical when building agents that write and execute code, where the agent needs to understand data structures, not just read descriptions.

Context versioning: In production, context changes. Policies update, regulations shift, market data evolves. Context engineering treats context as versioned artifacts, with clear lineage and rollback capabilities—similar to how you'd version code. This connects directly to AI model governance practices that track what context was active when a decision was made.

Assembly also means deciding what not to include. A common mistake in early pilots is including everything—every document, every historical record, every possible policy. This creates noise. Agents perform worse with irrelevant context, not better. Effective assembly means ruthlessly scoping what the agent actually needs to decide, and excluding the rest.

Context Compression: Fitting Knowledge into Finite Token Budgets

Context windows are expanding—Claude Opus 4 supports 200K tokens, GPT-5 pushes even further—but they're still finite. More importantly, latency and cost scale with context size. A 100K token context window means slower inference and higher API costs. In production, you're often running hundreds or thousands of agent decisions per day. Context size matters.

Context compression is the discipline of reducing context volume without losing decision-critical information. This is where context engineering diverges sharply from RAG.

Rag typically compresses through retrieval scoring: retrieve the top-K most similar documents and hope they're sufficient. Context engineering uses multiple compression techniques:

Abstractive summarisation: Instead of storing full documents, store machine-generated summaries that preserve decision-relevant information. A 50-page policy document becomes a 500-token summary of rules, exceptions, and decision criteria. An agent can reason over the summary, and fall back to the full document only when needed.

Fact extraction and consolidation: Pull out the actual facts and constraints from unstructured text. Instead of storing "Patient John Smith presented with chest pain on 2025-01-15, EKG showed..." store structured facts: {"patient_id": "123", "chief_complaint": "chest_pain", "presentation_date": "2025-01-15", "findings": {"ekg": "..."}}. This is denser and more queryable.

Hierarchical context trees: Organise context in a tree structure where leaf nodes are detailed, and parent nodes are summaries. An agent can start with a high-level summary, then drill down to detail only where needed. This is especially effective for AI agent orchestration systems where different agents might need different levels of detail.

Lossy compression for non-critical context: Not all context is equally important. If an agent needs to know that a vendor has been with your organisation for 5 years, it doesn't need the full procurement history. Compress non-critical context more aggressively.

Prompt compression techniques: Research from Anthropic on effective context engineering for AI agents shows that structured note-taking and compaction—reformatting context into dense, machine-readable formats—can reduce token usage by 30-50% without degrading agent performance.

The goal isn't to compress context to the absolute minimum; it's to compress it to the point where the agent has what it needs to decide well, at acceptable latency and cost. This requires instrumentation: measure what context the agent actually uses, where it gets stuck, and where it hallucinates. Use that data to guide compression decisions.

Context Routing: Delivering the Right Context to the Right Agent at the Right Time

Context routing is about deciding which agent gets which context, and when. In simple RAG systems, this is invisible—you query a vector database, get results, and pass them to a single model. In agentic systems, it's explicit and critical.

Consider a multi-agent system handling customer support. You might have agents for billing, technical issues, account management, and escalation. When a customer submits a ticket, you don't give all agents access to all context. The billing agent gets billing history and policies; the technical agent gets system logs and troubleshooting guides; the escalation agent gets decision criteria and manager contact info.

Routing decisions are made at multiple levels:

Initial triage routing: When a request comes in, which agent should handle it? This requires understanding the request and matching it to agent specialisation. If you're comparing agentic AI vs copilots, one key difference is that agents make autonomous routing decisions, while copilots require human routing.

Progressive context revelation: An agent starts with minimal context and requests additional context as needed. A claims processing agent might start with just the claim summary, request policy details when needed, then request historical claim data only if there's ambiguity. This reduces token usage and latency for straightforward cases.

Context specialisation: Different agents have different context needs. A healthcare agent managing clinical workflows needs clinical guidelines and patient history; a hospital operations agent needs staffing data and resource availability. Context routing ensures each agent gets its specialised context, not a generic dump.

Dynamic context loading: Context can be loaded dynamically based on runtime conditions. If an agent is processing a high-value transaction, load more detailed context. If it's a routine transaction, use compressed context. This optimises cost and latency based on risk.

Routing also involves deciding when to escalate context to a human. An agent might realise it lacks critical context to make a decision and request human input. This is where context engineering connects to governance: you need clear rules for when an agent has enough context to decide, and when it should escalate.

Context Engineering in Practice: Real-World Patterns

These three pillars—assembly, compression, routing—play out differently across industries and use cases. Let's look at concrete examples.

Financial Services: Context Engineering for Compliance

In financial services, context is heavily regulated. A lending agent needs to consider borrower creditworthiness, but also regulatory constraints (affordability rules, anti-discrimination rules), institutional risk policies, and product-specific terms.

Context assembly here means building a compliance context layer. This isn't just data retrieval; it's encoding regulatory requirements into a format the agent can reason over. You might represent affordability rules as a decision tree, anti-discrimination constraints as hard bounds, and risk policies as scoring functions.

Context compression is critical because regulatory context is dense and complex. Instead of storing full regulation texts, you extract the decision rules that matter for your specific business. A lending agent doesn't need to know the full history of consumer credit law; it needs to know your organisation's current interpretation of affordability requirements.

Context routing means different agents get different compliance contexts. A credit decision agent gets creditworthiness rules; a disbursement agent gets fraud detection rules; a servicing agent gets payment processing rules. Each agent has exactly the context it needs to operate within regulatory boundaries.

This is where context engineering becomes a governance tool. When a lending decision is questioned, you can trace exactly what context that agent had access to, what rules it applied, and why it decided as it did. This auditability is essential for regulated industries.

Healthcare: Context Engineering for Patient Safety

Healthcare context engineering is more complex because context directly affects patient outcomes. A clinical decision support agent needs patient history, clinical guidelines, institutional protocols, and real-time clinical data—and it needs them in a format that supports rapid, safe decision-making.

Context assembly in healthcare means building layered context: immediate clinical data (vitals, current symptoms), relevant history (prior diagnoses, allergies, medications), clinical guidelines (evidence-based treatment protocols), and institutional protocols (what your hospital does, which might differ from guidelines). Each layer has different currency requirements—vitals update in minutes, guidelines update in months.

Context compression is especially important because clinical context can be overwhelming. A patient might have decades of history. Context engineering means surfacing what's clinically relevant while managing volume. A patient with a history of migraines presenting with headache needs that history; a patient with a history of knee surgery presenting with headache doesn't.

Context routing in healthcare is about matching patient context to clinical expertise. A patient with a complex medication history might be routed to a pharmacist agent; a patient with a straightforward presentation might be routed to a triage agent. This improves both safety and efficiency.

This connects to agentic workflows in healthcare where agents handle patient scheduling, intake, and basic triage, but escalate complex cases to clinicians.

Hospitality: Context Engineering for Guest Experience

Hospitality context engineering is about personalisation at scale. A hotel AI agent handling guest requests needs to know the guest (preferences, prior stays, loyalty status), the property (room inventory, amenities, services), and the context (time of day, season, special events).

Context assembly means building a guest context model. This includes explicit preferences ("no early wake-up calls"), inferred preferences (guest history shows preference for high floors), and real-time context (guest is currently in the lobby, it's 11 PM, the restaurant closes at midnight).

Context compression is about surfacing what matters. A guest requesting a restaurant recommendation doesn't need their full stay history; they need current restaurant availability, your knowledge of their cuisine preferences, and real-time wait times.

Context routing means different agents get different context. A room service agent needs menu and kitchen status; a concierge agent needs local attraction data; a checkout agent needs billing and loyalty information. This specialisation improves both response quality and operational efficiency.

This is where context engineering enables AI-driven guest experience automation that feels personalised without requiring manual configuration for every guest.

The Evolution of Context: From Static to Self-Improving

Early context engineering treated context as static—assemble it once, compress it, route it, and it stays the same. Modern context engineering is moving toward evolving context.

Research on agentic context engineering (ACE) introduces a framework where context improves over time. The system includes three types of agents:

Generator agents create context—they take raw information and structure it into useful formats. A generator might take raw customer feedback and structure it into actionable insights.

Reflector agents evaluate context—they assess whether current context is helping the system succeed or fail. A reflector might notice that an agent frequently requests additional context and flag that as a signal that context assembly is incomplete.

Curator agents refine context—they take feedback from reflectors and update generators to produce better context. A curator might notice that context is missing a particular data field and update the generator to include it.

This self-improving loop means context engineering becomes an ongoing practice, not a one-time setup. In production, you measure how well agents perform with current context, identify gaps, and evolve the context to close those gaps.

This is especially powerful in AI-native engineering approaches where you're building systems that improve through use, not just through manual tuning.

Context Engineering vs. Traditional Approaches

It's worth understanding how context engineering differs from simpler approaches, especially RAG.

RAG retrieves documents based on similarity. It's simple, scalable, and works well for Q&A systems. But it doesn't optimise for agent decision-making. It doesn't compress context, doesn't route intelligently, and doesn't evolve.

Vector databases (a core RAG component) are powerful for similarity search, but they're fundamentally about retrieval, not decision support. A vector database tells you what's similar; it doesn't tell you what an agent needs to decide.

Fine-tuning embeds knowledge directly into model weights. This works for stable knowledge (like domain terminology) but not for changing knowledge (like real-time market data or patient history). It also requires retraining to update, which is expensive and slow.

Context engineering borrows from all three approaches but treats context as a first-class engineering problem. It combines retrieval (when you need dynamic information), structured knowledge (when you need to encode rules and constraints), and evolution (when you need to improve over time).

When you're comparing AI agents vs RPA systems, one key difference is context handling. RPA systems have hard-coded logic; AI agents need flexible context. Context engineering is what makes that flexibility reliable.

Building Context Engineering into Your Production System

If you're shipping agentic systems in production, here's how to think about context engineering:

Start with decision requirements: Don't start with data availability. Start with the decisions your agent needs to make. What information would a human need to make that decision well? That's your context assembly target.

Measure context usage: Instrument your system to measure what context the agent actually uses. If you're including context that the agent never accesses, remove it. If the agent frequently requests additional context, add it.

Compress aggressively: Start with more context than you think you need, measure performance, then compress. You'll often find that agents perform just as well with 30-50% less context, at significantly lower latency and cost.

Route explicitly: Don't give all agents access to all context. Design routing rules that match agent specialisation to context need. This improves both performance and auditability.

Version and audit: Treat context like code. Version it, track changes, and maintain audit trails showing what context was active when decisions were made. This is essential for governance and debugging.

Evolve continuously: Use production data to identify context gaps and improvements. Implement feedback loops (generator-reflector-curator patterns) that evolve context over time.

This approach is what enables Brightlume to ship production-ready AI solutions in 90 days. It's not magic—it's engineering discipline applied to a new problem.

Context Engineering Across Different Agent Types

Different agent architectures require different context engineering approaches.

Single-agent systems have simpler context requirements. You need to assemble all context the agent might need, compress it to fit token budgets, and optimise retrieval. This is closest to traditional RAG, but with more discipline around assembly and compression.

Multi-agent systems (like orchestrated agent networks) require sophisticated routing. You need to decide which agent gets which context at which step. This often involves a coordinator agent that routes requests to specialist agents, each with their own context.

Hierarchical agent systems use layered agents where high-level agents make strategic decisions and delegate to lower-level agents for execution. Context engineering here means building context hierarchies where high-level agents get strategic context and low-level agents get operational context.

Tool-using agents (agents that call APIs, databases, or other services) need context about available tools and when to use them. Context assembly includes tool descriptions, usage examples, and decision criteria for tool selection.

When you're building agents for supply chain management or IT operations, you're typically building multi-agent or tool-using systems. Context engineering becomes about managing context across multiple agents and tools.

Common Pitfalls in Context Engineering

There are predictable mistakes teams make when implementing context engineering:

Context bloat: Including too much context because you're uncertain what the agent needs. This increases latency, cost, and often decreases performance (more irrelevant information hurts reasoning). Start minimal and expand only when you measure the need.

Ignoring latency: Context engineering can optimise cost but increase latency if you're not careful. Compression algorithms, retrieval queries, and routing decisions all add latency. Measure end-to-end latency, not just model inference time.

Static context in dynamic environments: Building context once and never updating it. In production, context changes—policies update, data evolves, regulations shift. Build versioning and update mechanisms from the start.

Poor compression: Using generic summarisation that loses decision-critical details. Effective compression requires understanding what your specific agent needs to decide. It's not a generic problem.

Routing without fallback: If routing fails, the agent gets the wrong context and makes bad decisions. Build explicit fallback logic and monitoring for routing failures.

Missing auditability: Not tracking what context was used for each decision. This is essential for debugging, governance, and compliance. Build audit trails into your context system from day one.

These pitfalls are common because context engineering is still relatively new. Most teams are learning as they go. That's why having engineering partners who've shipped multiple agentic systems is valuable—they've hit these pitfalls and learned what works.

The Future of Context Engineering

Context engineering is evolving rapidly. A few directions worth watching:

Adaptive context: Systems that automatically adjust context based on agent performance and confidence. If an agent is making high-confidence decisions, reduce context. If confidence drops, expand context.

Cross-agent context sharing: In multi-agent systems, agents learning from each other's context. If one agent discovers a useful context pattern, other agents can adopt it.

Context as a service: Treating context assembly, compression, and routing as a separate service that multiple agents consume. This is similar to how observability has evolved as a separate discipline.

Formal verification of context: Proving that context is sufficient for an agent to decide safely. This is especially important in regulated domains like healthcare and finance.

Context marketplace: Teams sharing context patterns and implementations. Similar to how open-source code is shared, teams could share context engineering patterns.

These are emerging trends, not yet mainstream. But they point to a future where context engineering is as mature and well-established as other software engineering disciplines.

Conclusion: Context Engineering as a Core Competency

Context engineering is not an afterthought in agentic systems—it's foundational. It's the difference between a pilot that works in the lab and a system that operates reliably in production.

The three pillars—assembly, compression, and routing—give you a framework for thinking about context systematically. Assembly ensures you have the right information. Compression ensures you use it efficiently. Routing ensures it reaches the right agent at the right time.

When you're building agentic systems that need to operate autonomously, at scale, with measurable ROI, context engineering is non-negotiable. It's where the engineering rigour that makes production AI possible actually lives.

If you're shipping agentic workflows—whether for healthcare operations, financial services, hospitality, or any other domain—context engineering is where you invest your effort. Get the context right, and the agent performance follows. Get it wrong, and no amount of model tuning will fix it.

This is the discipline that separates AI consultancies that ship working systems from those that ship pilots. It's also why understanding the difference between AI-native and AI-enabled approaches matters—AI-native systems are built with context engineering baked in from the start.