Building AI applications that actually work is less about crafting the perfect prompt and more about controlling the information you feed into the model. If you have ever sat in a long chat with an assistant, only to realize it forgot something you said ten minutes ago, you have already felt what happens when context engineering fails. It is easy to assume the AI has a bad memory. In reality, you bumped against the hard limits of the context window.

To build systems that stay reliable and responsive, you need to understand three fundamentals: tokens, context windows, and the difference between context and memory.

Tokens Are the Real Currency

A token is not a word. When you send text to a model, a tokenizer breaks it into smaller pieces. Short common words like "cat" or "the" might each fill a single token. A dense technical term like "internationalization" gets sliced into several. Punctuation, spaces, and special characters all count too. This matters because tokens govern everything: your API bill, the speed of the response, and the quality of the output.

A developer who plans costs by counting words is flying blind. A hundred-word prompt filled with code brackets and long variable names can inflate well beyond expectations. That is why tokenizers exist as standalone tools. Before you ship a feature, run your typical payloads through one. You will often discover that system instructions, formatting boilerplate, and chat history eat more of your budget than the actual user query. Treat tokens as a scarce resource from day one.

The Context Window Is a Fixed Whiteboard

The context window is the total amount of information a model can see in a single request. Think of it as a whiteboard with fixed dimensions. You can fill it with system rules, conversation history, retrieved documents, and the current question. But once the surface is covered, something has to give. Older notes must be erased, photographed and summarized, or the board simply overflows.

Modern models advertise context windows ranging from a few thousand tokens to hundreds of thousands. It is tempting to treat a larger window as unlimited storage. It is not. The whiteboard still has edges. When history exceeds the limit, the application must drop old messages or compress them. Understanding this constraint helps you stop treating the window like a database and start treating it like active workspace.

Context Is Not Memory

Here is a distinction that trips up even experienced builders. The model itself is stateless. It does not remember you from yesterday, last week, or ten minutes ago in a different session. When an AI seems to recall that you prefer Python over JavaScript, or that you like concise answers, the memory lives in the application layer, not the model.

The application stores those facts in a database, cache, or memory store. On every new request, it injects the relevant profile data back into the prompt. The model is simply reading a script that includes its lines from act one. It has no persistent self. Once you internalize this separation, your architecture changes. You stop asking the model to remember and start designing systems that fetch the right context at the right time.

Why More Context Can Backfire

Common sense suggests that more background information should produce better answers. Often, the opposite happens. Excess context creates noise. If you hand a model an entire codebase when you only need one function fixed, you force it to hunt for a signal in static. Researchers have identified the "Lost in the Middle" effect: models frequently pay closer attention to details at the start and end of a prompt, while information buried in the center gets diluted or ignored. This is not a bug you can patch with clever wording. It is a structural behavior present in transformer-based architectures.

Bloated prompts also hit you where it hurts. Every additional token requires computation. Latency rises. Costs climb. User patience shrinks. A prompt stuffed with irrelevant documents introduces contradictions, distracts the model with tangential details, and increases the odds that the response fixates on the wrong problem. Volume is the enemy of precision.

How to Engineer Better Context

Good context engineering is an exercise in ruthless editing. Here is how to put it into practice.

শুধুমাত্র যা প্রয়োজন তাই পাঠান। যদি কোনো ব্যবহারকারী আপনার রিফান্ড পলিসি সম্পর্কে জিজ্ঞাসা করেন, তবে এমপ্লয়ী হ্যান্ডবুক, API ডকুমেন্টেশন এবং গত প্রান্তিকের মার্কেটিং কপি অন্তর্ভুক্ত করবেন না। ব্যাপকতার চেয়ে প্রাসঙ্গিকতা বেশি কার্যকর।

প্রাসঙ্গিক ডকুমেন্ট সংগ্রহের জন্য RAG ব্যবহার করুন। Retrieval-Augmented Generation আপনাকে একটি বিশাল নলেজ বেস অনুসন্ধান করতে এবং প্রম্পটে শুধুমাত্র সবচেয়ে সামঞ্জস্যপূর্ণ অংশগুলো যুক্ত করতে সাহায্য করে। উইন্ডোতে হাজার পৃষ্ঠার ম্যানুয়াল ঢেলে দেওয়ার পরিবর্তে, আপনি আপনার ডকুমেন্টগুলো এমবেড করুন, ব্যবহারকারীর কুয়েরির বিপরীতে একটি সিম্যান্টিক সার্চ চালান এবং সবচেয়ে প্রাসঙ্গিক তিনটি অনুচ্ছেদ অন্তর্ভুক্ত করুন। মডেলটি ঠিক যা প্রয়োজন তাই পায় এবং আপনার টোকেন বাজেটও অক্ষুণ্ণ থাকে।

পুরানো কথোপকথনগুলো সংক্ষেপ করুন। চ্যাটের সম্পূর্ণ ট্রান্সক্রিপ্ট ব্যয়বহুল এবং বিভ্রান্তিকর হতে পারে। দীর্ঘ মেসেজ হিস্ট্রিকে চলমান সারাংশ দিয়ে প্রতিস্থাপন করুন। উদাহরণস্বরূপ, মডেলকে ত্রিশটি আদান-প্রদান করা মেসেজ দেওয়ার পরিবর্তে, একটি মাত্র অনুচ্ছেদ সংরক্ষণ করুন: "ব্যবহারকারী Django ডেপ্লয়মেন্ট সম্পর্কে জিজ্ঞাসা করেছিলেন, একটি static files error-এর সম্মুখীন হয়েছিলেন এবং পারমিশন ঠিক করেছেন। বর্তমান সমস্যাটি হলো Postgres 14-এ একটি database migration ব্যর্থ হচ্ছে।" এই সারাংশটি হোয়াইটবোর্ডকে অগোছালো না করেই অবস্থার (state) ধারাবাহিকতা বজায় রাখে।

অ্যাক্টিভ চ্যাট থেকে লং-টার্ম মেমরি আলাদা করুন। ব্যবহারকারীর পছন্দ, প্রজেক্ট সেটিংস এবং অ্যাকাউন্টের ইতিহাস একটি এক্সটার্নাল মেমরি স্টোরে রাখা উচিত। সেই স্টোর থেকে বেছে বেছে কুয়েরি করুন। লাইভ কনটেক্সট উইন্ডোতে শুধুমাত্র তাৎক্ষণিক কাজ এবং ধারাবাহিকতা বজায় রাখার জন্য প্রয়োজনীয় সংক্ষিপ্ততম ব্যক্তিগত তথ্য থাকা উচিত।

প্রোডাকশনে টোকেন ব্যবহার পর্যবেক্ষণ করুন। ল্যাটেন্সি স্পাইক প্রায়শই কনটেক্সট অতিরিক্ত বেড়ে যাওয়ার কারণে ঘটে। রিকোয়েস্টগুলো যখন আপনার মডেলের সীমার কাছাকাছি পৌঁছায়, তখন অ্যালার্ট সেট করুন। অপ্রয়োজনীয় বোঝা বহনকারী প্রম্পটগুলো শনাক্ত করতে লগ পর্যালোচনা করুন। অপ্টিমাইজেশন প্রতিবার একই প্রশ্ন দিয়ে শুরু হয়: কাজটি ব্যাহত না করে আমরা কী কী বাদ দিতে পারি?

আসল শিক্ষা

সেরা AI অ্যাপ্লিকেশনগুলো সবচেয়ে বড় কনটেক্সট উইন্ডো থাকার কারণে জয়ী হয় না। তারা জয়ী হয় কারণ তারা শৃঙ্খলার সাথে কনটেক্সট পরিচালনা করে। একটি বিশাল হোয়াইটবোর্ডও অকেজো যদি সেটি হিজিবিজি লেখায় ভরা থাকে। এমন সিস্টেম তৈরি করুন যা তথ্য সংগ্রহ (retrieve), সংক্ষেপ (summarize) এবং ফিল্টার (filter) করতে পারে। এতে আপনার ব্যবহারকারীরা দ্রুত উত্তর পাবেন, আপনার ইনফ্রাস্ট্রাকচার খরচ অনুমানযোগ্য থাকবে এবং আপনার মডেলগুলো অবশেষে সেই বিষয়টির দিকেই মনোযোগ দেবে যা আসলে গুরুত্বপূর্ণ।

উৎস: AI Context Engineering: Tokens, Context Windows, & Memory

কমিউনিটি: GyaanSetu AI on Telegram