AI Hallucination: Why AI Makes Things Up and How to Reduce It
What is an AI hallucination? Learn why language models invent facts, how to spot it, and practical ways to reduce hallucinations in chats and AI agents.
What is a context window? Learn what tokens are, how LLMs count them, why context limits matter, and practical ways to work within them for better results.
A context window is the amount of text an AI model can consider at one time, measured in tokens. Tokens are the small chunks of text a model reads and writes, often a piece of a word. Everything the model works with in a single request, including your instructions, the conversation so far, any pasted documents, and its own reply, has to fit inside that window.
Understanding these two ideas explains a lot: why long chats get forgetful, why some tasks cost more than others, and why AI agents work the way they do. Here is the simple version.
Language models do not read letters or whole words. They read tokens, which are chunks of text from a fixed vocabulary the model learned to use.
A token might be:
The exact split depends on the model’s tokenizer, and different model families tokenize differently. As a rough rule of thumb for English prose, one token is a bit less than one word, so a page of text is several hundred tokens. Treat that as an estimate, not a conversion rate.
Tokens give the model a manageable vocabulary that can still spell out anything. Common words get a single token, which is efficient. Rare words, names, and typos can still be represented by combining smaller pieces. This is also why models sometimes stumble on tasks like counting letters in a word: they never see individual letters, only tokens.
Some content is “token-heavy” compared with plain English:
The context window is the model’s working memory for a single request. It is the maximum number of tokens the model can take in and produce together.
Think of it like a desk. Everything the model needs to look at has to be on the desk at once. If the pile gets too big, something must come off before anything new goes on.
What goes on that desk:
| Part of the context | Example |
|---|---|
| System prompt | Hidden instructions from the app about how the model should behave |
| Your messages | Questions, instructions, requests |
| Earlier replies | The model’s previous answers in the conversation |
| Attached content | Files, documents, web pages, search results |
| Tool results | Output from commands, tests, or API calls (for agents) |
| The new reply | The tokens the model is generating right now |
Context window sizes vary widely between models, from a few thousand tokens to very large windows that can hold entire books or codebases. Larger is not automatically better, as you will see below.
An LLM does not remember anything between requests by itself. Each time you send a message, the app sends the relevant conversation back to the model inside the context window. The model’s sense of memory is just that text.
When a conversation grows past the window, the app has to do something:
This is why a long chat can suddenly “forget” a detail from the start. It was not forgotten in a human sense. It simply was no longer on the desk.
Large context windows are useful, but they come with costs:
The practical lesson: give the model the right context, not all the context.
Context is even more important for AI agents. An agent does not just answer once. It loops: read files, run a command, read the output, decide the next step. Every file it opens and every test log it reads goes into the context window.
On a big task, that fills up fast. Good agent tools manage this by:
That last idea is one reason teams of agents can handle bigger projects than one agent alone. In BotQuarters, for example, a team lead agent breaks a goal into tasks and gives each teammate its own focused piece of work, with its own context. For more on how agents run, see what is an AI agent.
Context also affects cost directly, since every step re-sends tokens. Our guide to AI agent costs covers how that adds up.
Whether you are chatting or running agents, these habits help:
If you want to see where tokens fit into the bigger picture of how models generate text, read how LLMs work.
A context window is the maximum amount of text, measured in tokens, that a language model can consider in one request. It includes your instructions, the conversation history, any attached documents, and the model’s own response.
It depends on the model and the text. For typical English writing, a token is usually a bit less than a word on average, so a given number of tokens covers somewhat fewer words. Code, numbers, and many other languages usually take more tokens per word.
The model cannot see anything outside the window. Depending on the app, older messages are dropped or summarized, or you get an error asking you to shorten the input. Either way, details that fall outside the window no longer affect the answer.
Not always. A bigger window lets you include more material, but it can cost more, respond more slowly, and make it harder for the model to focus on what matters. Well-chosen, relevant context often beats simply stuffing in everything.
What is an AI hallucination? Learn why language models invent facts, how to spot it, and practical ways to reduce hallucinations in chats and AI agents.
How do LLMs work? A plain explanation of tokens, training, attention and next-token prediction, with no math, plus what it means for using AI tools well.
Open source LLM or closed model? Learn what open-weight really means, why licenses vary, and the trade-offs in privacy, cost, quality and control.