# Context Packs

Curated bundles of the context an agent or prompt needs for a task — specifications, examples, conventions — assembled deliberately.

**Rests on:** Context Window

**Leads to:** Agent Instruction Files, Claude Skills

*LLMs and Generative AI · Prompt Engineering*


## Why learn this

Context Packs are the foundation of reliable AI systems. You will use them every time you build an automated assistant, any system that looks up outside information to answer questions, or any automated task that needs specific knowledge. Mastering this concept lets you move on to refining your instructions — without a well-assembled Context Pack, those techniques have nothing to work on. It also builds directly toward designing how information is presented, where you will decide what information to include, in what order, and how to keep it fresh.


## The intuition

Imagine you are a new employee at a company. On your first day, your manager hands you a thick folder. Inside is a list of your responsibilities, examples of how previous employees solved similar problems, and a note about the company's style — be formal in emails to clients, use bullet points in reports, ask before changing anything in the shared database. You read the folder, and now you know how to work without asking your manager every five minutes. A Context Pack is exactly that folder, but for an AI model. It is a bundle of text that you give to the model before it starts answering. The text contains everything the model needs to do the task well: the instructions (what to do), the examples (how to do it), and the conventions (the rules to follow). Without the pack, the model is like a new employee with no folder — it guesses, makes mistakes, and does things in a random way. With the pack, it acts like a seasoned professional, because you have given it the same knowledge a human would get from experience. The trick is that the model does not remember anything between requests — every time you call it, it is a fresh employee. So you must give it the folder every single time. That is why you build a Context Pack once and reuse it.


## An analogy

Think of a Context Pack as a recipe card for a complex dish, say a traditional Hyderabadi biryani. The recipe card has three parts: the list of ingredients (the specifications), a picture of the finished dish (the example), and notes like 'always use aged basmati rice' or 'do not open the lid while cooking' (the conventions). If you hand this card to a chef, they can cook the dish without asking you questions. If you hand it to ten different chefs, they will all produce something recognizable as biryani, though each will be slightly different. Now imagine you did not give the card — you just said 'cook biryani.' Each chef would do something wildly different: one might add tomatoes, another might use instant rice, a third might make it too spicy. The recipe card is the Context Pack: it turns a vague request into a specific, repeatable result. But the analogy breaks down in one important way: a human chef can remember the recipe after cooking it once, and they can adjust if they run out of an ingredient. A language model cannot remember anything between calls. It only sees the card you give it right now. If you forget to include the note about aging the rice, it will happily use regular rice. So the Context Pack must be complete every time — you cannot assume the model picked anything up from a previous conversation.


## Definition

A Context Pack is a deliberately assembled bundle of text — containing specifications, examples, and conventions — that you give to an AI model before it performs a task, to provide all the context it needs in one reusable, reviewable package.


## How it connects

You already know that a prompt is the text you give a model. A Context Pack is a special kind of prompt — one that is designed to be reused and shared. It is a way of turning the knowledge that lives in your head or in your organisation's documentation into something the model can use. This concept connects to refining your instructions because you will improve your Context Pack based on test results, and to automatically improving those instructions because you can treat the pack's contents as a set of choices to be tuned automatically. It also connects to rules for the reply format: a good Context Pack often includes a template that forces the model to reply in a specific structure, like a form or a code block. And it is the foundation of AI Agents, because an agent needs a pack that describes its tools, its goals, and the rules for using them.


## The mathematics

This concept does not require complex mathematics. It uses simple arithmetic: counting words, counting examples, and comparing sizes. The core idea is that a language model has a limited 'window' — think of it as a fixed-size container, like a cup. Everything you put in the cup — the instructions, the examples, the notes — takes up space. If you put too much, you spill over the edge, and the model forgets the earlier parts (this is called context overflow). So you need to decide, for a given task, what is most important to include. The mathematics here is about measuring: how many words can the model handle? How many examples fit without pushing out the instructions? How do you balance the size of the pack with the amount of detail? These are simple comparisons — is 5 examples better than 10? Does a 200-word spec work better than a 50-word one? You answer these by testing, not by algebra.

Total tokens in pack = tokens(instruction) + tokens(examples) × number_of_examples + tokens(conventions)
Available tokens for user input = context_window − Total tokens in pack


## A worked example

```
Suppose you are building a Context Pack for a small model that summarises customer reviews for a restaurant. The model's context window is 1,000 tokens (a token is roughly one word). You have three components: (1) an instruction: 'Summarise the review in one sentence.' (2) two example reviews with their summaries, each pair using 150 tokens, and (3) a convention: 'Always mention the food quality.' Let us count how much space you have.

Step 1: Instruction: 20 tokens   # The instruction is short.
Step 2: 2 examples × 150 tokens = 300 tokens   # Each example pair takes 150 tokens.
Step 3: Convention: 10 tokens   # A short note.
Step 4: Total so far: 20 + 300 + 10 = 330 tokens   # Sum of the three parts.
Step 5: Remaining space: 1000 − 330 = 670 tokens   # This is room for the actual customer review you will send in each call.

Result: You have 670 tokens left for the review itself. If a review is longer than that, you will need to truncate it, or make your examples shorter. This is the arithmetic of context packing: every token you add to the pack takes away from the space available for the real input.
```


## From scratch, in Python

Here is a simple Python function that builds a context pack from its parts. It uses a dictionary to hold the pieces, and a loop to count tokens.

```python
# Step 1: Define the pieces of the pack
instruction = "Summarise the review in one sentence."
examples = [
    {"review": "The biryani was tasty but the service was slow.", "summary": "Tasty food, slow service."},
    {"review": "Great ambience, but the music was too loud.", "summary": "Good atmosphere, but noisy."}
]
conventions = "Always mention the food quality."

# Step 2: a simple function to count words (very rough token count)
def count_tokens(text):
    return len(text.split())

# Step 3: build the pack by combining everything
def build_pack(instruction, examples, conventions):
    pack = {}
    pack["instruction"] = instruction
    pack["examples"] = examples
    pack["conventions"] = conventions

    # Step 4: count total tokens
    total = count_tokens(instruction)
    for ex in examples:
        total += count_tokens(ex["review"]) + count_tokens(ex["summary"])
    total += count_tokens(conventions)

    pack["total_tokens"] = total
    return pack

# Step 5: use the function
my_pack = build_pack(instruction, examples, conventions)
print(my_pack["total_tokens"])  # This prints a number
print(my_pack["instruction"])   # The instruction text
```


## The same thing, with a framework

In real applications, you would use a library like LangChain or LlamaIndex to build context packs, because they handle the token counting automatically. Here is a Linq-like example:

```python
from langchain.prompts import PromptTemplate
template = """Summarise the review in one sentence.
Review: {review}
Always mention the food quality."""
prompt = PromptTemplate.from_template(template)
prompt_text = prompt.format(review="The biryani was tasty but slow.")
```

Underneath, LangChain is doing the same thing you did: taking the instruction, filling in the review, and concatenating all the text. It does not do any magic — it just automates the assembly.


## What the code does

The code defines a dictionary `pack` that holds the three parts: instruction, examples, and conventions. A dictionary is like a labelled box — you store things by name, not by position. The `for ex in examples:` loop goes through each example, one at a time, and adds the token count of the review and the summary. A `for` loop is a way to repeat an action for each item in a list. Finally, the total token count is stored inside the pack so you can see how big it is. This is exactly what a real context pack builder would do, but in production you would use a proper tokenizer, not just `len(text.split())`.


## Common misconceptions

**Context Pack is just a longer prompt** — I can just put all my instructions and examples into one big text and it will work fine.

A Context Pack is not just a jumble of text. It is structured: instructions, examples, and conventions are distinct parts with different roles. Mixing them chaotically makes the model less likely to follow them. Structure helps the model identify what is important. In fact: A Context Pack is a deliberately assembled bundle with a clear structure — separate sections for instructions, examples, and conventions — so the model can easily find and use each part.

**More context is always better** — If I have a large context window, I should stuff in as much information as possible.

Adding too much irrelevant text makes the model lose focus. The context window is like a cup — if you fill it with sand, there is no room for water. Irrelevant material dilutes the important instructions, and the model may miss key points. In fact: A good Context Pack includes only what is necessary for the task. Every token should serve a purpose. Quality over quantity.

**Context Packs are only for prompts** — This only applies to chatbots and text generation. My model does classification, so it does not need this.

Any model that needs extra knowledge beyond the raw input benefits from a Context Pack. Even a spam filter uses rules and lists that act as a pack. The principle is universal. In fact: Context Packs apply to any AI system where you need to give the model context beyond the immediate input — classification, forecasting, agents, and more.

**The model can remember the pack after the call** — Once I give the model a Context Pack once, it will remember it for the next call.

Language models are stateless between calls. Each request is independent. If you do not include the pack, the model starts from scratch. In fact: You must include the Context Pack with every call. Reusability means you can include the same pack repeatedly, not that the model remembers it.


## In short

A Context Pack is a structured bundle of instructions, examples, and conventions that you give to an AI model to make it behave reliably. It must be deliberately assembled, kept within the context window, and reused on every call. Good packs are versioned and tested, and they are the foundation of prompt engineering, RAG, and agentic systems.


## Where this is used

Context Packs are used everywhere in modern AI engineering. Here is how, in detail.

**Large language models (LLMs)**: When you use ChatGPT or Claude, you are using a huge model with a large context window (e.g., 100,000 tokens). But even with a large window, you cannot just dump everything in — you need to curate. For example, if you are building a customer-support bot, your Context Pack might include the product manual, a list of common issues, and the tone guidelines. The mechanism: every user query is appended to the pack, and the model generates a response based on the whole text. If the pack is poorly organised, the model may ignore important instructions buried in the middle. So you design the pack to put the most critical instructions at the beginning and the end, because the model tends to focus on those. 

**Small models on devices**: When you run a model on a phone or a laptop, the context window is much smaller — maybe 2,000 to 8,000 tokens. Here, Context Packs are even more important because you have less room. A keyword spotters or a smart assistant on your phone must have a tiny pack that fits in the window. For example, a mobile translation app might use a pack that contains just the source and target languages and a small glossary, because there is no room for long examples. The developer must measure the token count of each component and cut ruthlessly. This is where the arithmetic from the mathematics section becomes a daily practice: every token is precious.

**Retrieval-augmented generation (RAG)**: This is a system where a model answers questions by first pulling relevant documents from a database. The Context Pack here is dynamic: you assemble a pack that includes the retrieved passages, the question, and your instructions. The mechanism: you embed the user question as a vector, find the most similar passages using a dot product, and then place those passages into the Context Pack. The pack must be assembled so that the most relevant passages appear first, because the model weights earlier text more. You also include a convention like 'If the answer is not in the passages, say you do not know.' Developers write code to fetch the passages, rank them, and combine them with the instruction — that code is, in effect, building a Context Pack on every call.

**Agentic systems**: An agent is a model that can call tools (like a calculator or a web search) and decide what to do next. Its Context Pack is a kind of 'agent instruction file' that lists the available tools, what each does, and the rules for when to use them. For example, a travel-planning agent might have a pack that says: 'You can search for flights, book hotels, and ask the user for preferences. Always confirm any booking with the user before making it.' The mechanism: the agent reads this pack before taking any action. If the pack is missing, the agent might call a tool with the wrong parameters or make a risky decision. A well-built pack prevents that. Developers build these packs very carefully, often using version control, because a small change in the wording can change the agent's behaviour.

**Everyday applied machine learning**: In classification, forecasting, and other tasks, you use Context Packs indirectly. For a spam filter, the 'pack' might be the list of known spam phrases and the rules for what constitutes spam. In recommendation systems, the pack might contain the user's past preferences and the catalogue guidelines. The mechanism is the same: any time you need to give a model additional knowledge beyond just the raw input, you are creating a Context Pack. 

**What a developer writes**: In practice, a developer creates a directory of text files for different tasks. For a legal document summariser, they might have `instructions.txt`, `examples.jsonl`, and `conventions.md`. Then a script reads these files, combines them, and sends them to the model API. If the pack is too large, the developer sees an error about exceeding the context limit. If the pack is poorly written, the model produces bad output. The developer iterates by editing the text files and re-testing, using Prompt Iteration techniques. Version control (like Git) tracks changes to these files, so a team can review and roll back if needed.


---

Read this on the web: https://basavapurushottam.com/learn-ai/context-packs
