Context window
A context window is the bounded sequence of tokens or other input information a model can access when processing or generating an output.
Software Testing with Generative AI
The bounded amount of tokenized input and related context that a language model can process for a request.
- How it is used
- Constrains prompt design, retrieval, testing workflows, and fine-tuning data preparation.
- How deep it goes
- Explains tokenization, truncation, errors, cost, and relevance strategies, but does not detail model-internal context handling.
- Examples
- Uses a city-list tokenization example, testing artifacts, a booking-deletion query, Llama-2 capacity, and gpt-4 turbo pricing.
- What you can do after
- Evaluate prompt size, select relevant context, and avoid truncated inputs during LLM testing and fine-tuning.
Read how Software Testing with Generative AI explains context window →
Generative AI in Action
The context window is the bounded amount of input and generated text that a language model can consider within one interaction.
- How it is used
- Guides token budgeting for chat conversations and prompts that must fit both input and generated output.
- How deep it goes
- Defines the window and explains next-token growth, size trade-offs, and practical counting without deriving attention mathematics.
- Examples
- Uses a growing chat message list and a tiktoken-based console application to illustrate token-limit management.
- What you can do after
- Operate/configure a chat application to count tokens, reserve response space, and shorten requests that exceed model limits.
LLMs in Production
Context length is the maximum amount of tokenized input and generated context that a language model can process in one request.
- How it is used
- Constrains how many retrieved code examples a coding assistant can include with its prompt.
- How deep it goes
- Explains the limit through model selection and token-counted prompt assembly, without specifying how model architectures enforce it.
- Examples
- Uses DeciCoder’s 2,048-token limit and a RAG coding prompt that filters retrieved examples by token count.
- What you can do after
- Apply it via a tokenizer-backed counter to select retrieved examples that fit a DeciCoder prompt.
AI for Everyday IT
A context window is the amount of input and conversational or document context that a language model can process for one interaction.
- How it is used
- Guides chatbot and coding-assistant users in preserving coherence, reliability, and manageable costs during extended work.
- How deep it goes
- Explains capacity limits, token growth, failure symptoms, summaries, fresh chats, and focused tasks without detailing model internals.
- Examples
- Uses a two-month ChatGPT conversation, overloaded code assistants, focused coding prompts, and test-first refactoring.
- What you can do after
- Operate chatbots and coding assistants more reliably by summarizing, restarting chats, narrowing tasks, and testing changes.
Time Series Forecasting Using Foundation Models
Context length is the fixed number of preceding sequence elements that a model can consider when processing an input.
- How it is used
- Controls the historical input available to time-series forecasting models and provides a parameter for model comparison.
- How deep it goes
- Defines the input window, relates it to tokenization and inference cost, and stops short of a universal selection rule.
- Examples
- Uses Walmart weekly sales, Lag-Llama lengths of 16, 32, and 64, Moirai historical inputs, and TimesFM limits of 32-step multiples up to 2048.
- What you can do after
- Apply it via Lag-Llama by testing candidate lengths with rolling cross-validation and MAE or sMAPE evaluation.
Read how Time Series Forecasting Using Foundation Models explains context window →
Starting Data Analytics with Generative AI and Python
The maximum amount of conversational or input-output context that a language model implementation can process in one exchange.
- How it is used
- Guides how much prompt history, data, code, and generated output can be used in an AI-assisted analysis exchange.
- How deep it goes
- Defines the token-based limit, describes silent truncation, and gives practical mitigation strategies without detailing model internals.
- Examples
- Uses an overheard-conversation analogy, ten pasted reviews, and long code split across prompts.
- What you can do after
- Diagnose/debug with it by recognizing forgotten instructions, dividing oversized inputs, and checking outputs and generated code.
Read how Starting Data Analytics with Generative AI and Python explains context window →
AI Agents in Action, Second Edition
The finite amount of input and conversational context that an agent can retain or process in one interaction.
- How it is used
- Sets the per-call budget for conversation history, tool results, and retrieved information in an agent.
- How deep it goes
- Defines the token limit and explains selection trade-offs, while deferring detailed memory architectures and context strategies.
- Examples
- Uses older conversation turns, tool outputs, retrieved results, and task distribution among agents to illustrate context choices.
- What you can do after
- Operate/configure it by measuring tokens and selecting which history, tool output, and retrieval results enter each call.
Read how AI Agents in Action, Second Edition explains context window →
Grokking AI Algorithms, Second Edition
A context window is the maximum sequence of tokens a language model processes as contextual input at one time.
- How it is used
- Uses the context window to divide token streams for training and to set how much preceding text the model can process.
- How deep it goes
- Explains the definition, token batching, architecture role, and tuning trade-offs without developing the model’s internal computations.
- Examples
- Uses a 32-token toy model, token-ID streams, visual batches, and a Python slicing routine.
- What you can do after
- Apply it via token batching and choose it as a Transformer hyperparameter for the longest required prompt.
Read how Grokking AI Algorithms, Second Edition explains context window →
Build AI-Enhanced Web Apps
A context window is the maximum amount of tokenized input and generated content a language model can process in one interaction.
- How it is used
- Guides prompt budgeting, provider selection, token billing, and tool design for language-model applications.
- How deep it goes
- Explains token allocation, provider limits, billing, and agent constraints, then demonstrates JavaScript counting without detailing tokenizer internals.
- Examples
- Uses GPT and Gemini limit comparisons, a tiktoken counter, and a LangChain agent constrained by tool descriptions and arguments.
- What you can do after
- Apply it via @dqbd/tiktoken to measure prompt tokens and reserve capacity for generated output.
Read how Build AI-Enhanced Web Apps explains context window →
Grokking AI Applications
A context window is the maximum number of tokens a language model can process in one prompt.
- How it is used
- Limits prompt content and guides tool allocation and agent decomposition.
- How deep it goes
- Defines token capacity, gives a GPT-3 example, and explains practical degradation without detailing context implementation.
- Examples
- Uses GPT-3’s 2,048-token prompt limit and an overloaded solo-agent scenario.
- What you can do after
- Evaluate prompt and tool-load trade-offs when designing language-model agents.
The Art of AI Product Development
The maximum amount of tokenized input and retained conversational or task information that a language model can process in one operation.
- How it is used
- Guides agents in retaining the right task information while managing prompt limits, latency, token costs, and accuracy risks.
- How deep it goes
- Explains prompt contents, memory choices, and operational trade-offs, but stops short of specifying a context-management algorithm.
- Examples
- Uses multistep trend research, roadmap synthesis, conversation history, tool contexts, and retrieved prior-quarter interactions.
- What you can do after
- Diagnose agent bottlenecks by separating useful current context from information better stored and retrieved externally.
Read how The Art of AI Product Development explains context window →
Machine Learning Platform Engineering
A context window is the maximum amount of tokenized input and output that a language model can process in one interaction.
- How it is used
- Guides retrieval, prompt construction, response limits, and decomposition for production LLM applications.
- How deep it goes
- Explains token budgeting, failure modes, and decomposition, but stops short of model-specific implementation code.
- Examples
- Uses a 50-chunk RAG calculation, a 32K window, and model comparisons including GPT-4 Turbo, Claude 3.5 Sonnet, and Gemini.
- What you can do after
- Operate/configure retrieval and generation budgets to avoid request failures, truncation, wasted tokens, and degraded reasoning.
Read how Machine Learning Platform Engineering explains context window →
AI Agents and Applications
A context window is the maximum amount of input and conversational context a language model can process in one interaction.
- How it is used
- Limits the prompt text available for document summarization and knowledge-base Q&A.
- How deep it goes
- Defines the limit in tokens and outlines chunked summarization, without detailing model internals.
- Examples
- Uses an oversized document and company information spread across intranet pages and files as concrete cases.
- What you can do after
- Apply it via TokenTextSplitter to size document chunks for staged summarization.
Read how AI Agents and Applications explains context window →
Effective Conversational AI
A context window is the maximum amount of input text or tokens that a language model can process in one inference request.
- How it is used
- Guides document chunking for retrieval-augmented generation so selected language models can process passages in one inference pass.
- How deep it goes
- Explains chunk sizing, computational trade-offs, diminishing returns, and attention gaps without specifying model-specific limits.
- Examples
- Uses long documents, annual reports, meeting transcripts, and HTML splitting to illustrate chunking decisions.
- What you can do after
- Operate document chunking so retrieved passages fit a model’s context window while limiting irrelevant text.
Read how Effective Conversational AI explains context window →
Build Python Web Apps with Streamlit
Context window length is the maximum number of tokens that a language model can process as input in a single prompt.
- How it is used
- Frames how much supporting information an LLM can receive in one prompt when designing knowledge-grounded applications.
- How deep it goes
- Defines token capacity and explains overload and cost trade-offs, but stops short of implementation limits or token-counting procedures.
- Examples
- Compares model capacities with large literary works and contrasts full knowledge-base prompts with retrieved context.
- What you can do after
- Apply Retrieval Augmented Generation to provide relevant knowledge without sending an entire knowledge base in every prompt.
Read how Build Python Web Apps with Streamlit explains context window →
Building Reliable AI Systems
The maximum amount of input content a model can process in a single input.
- How it is used
- Frames context windows as a reliability constraint when selecting retrieved passages for grounded question answering.
- How deep it goes
- Explains positional loss through a U-shaped performance curve and recommends filtering, without specifying token-budget allocation or threshold calibration.
- Examples
- Illustrates filtering with a roaming FAQ versus related pricing, travel, and terms pages.
- What you can do after
- Operate/configure it by filtering retrieved passages with a similarity threshold and considering chunking for documents exceeding embedding input limits.
Read how Building Reliable AI Systems explains context window →
Build Applications with Local AI Models on a Mac
Context length is the maximum number of tokens a language model can consider at once.
- How it is used
- Explains why long chatbot conversations can lose earlier context and why apps must limit the history sent with each request.
- How deep it goes
- Defines the token limit, estimates conversation growth, and explains overflow; identifies trimming as a remedy without specifying a trimming algorithm.
- Examples
- Compares local-model capacities and estimates how twenty exchanges can consume 5,000–10,000 tokens.
- What you can do after
- Apply it via Streamlit session state by retaining visible history while trimming messages sent to the model.
Read how Build Applications with Local AI Models on a Mac explains context window →
How Large Language Models Work
Context size is the maximum number of tokens a language model can computationally process in one request.
- How it is used
- Constrains how much prompt, retrieved information, and conversation history an LLM can process in one request.
- How deep it goes
- Defines the token limit and demonstrates truncation, but stops short of explaining tokenization or implementation internals.
- Examples
- Uses GPT-3’s 2,048-token limit, long-chat history, whole-book retrieval, and Grok’s 128,000-token capacity.
- What you can do after
- Evaluate models for RAG by checking whether prompts and retrieved documents fit within their context limits.
Read how How Large Language Models Work explains context window →
Build an AI Agent (From Scratch)
A context window is the maximum amount of tokenized input and generated context that a language model can process together.
- How it is used
- Frames context as the information budget governing model responses and agent design.
- How deep it goes
- Defines contents and failure effects, but stops short of implementation details for measuring or managing token budgets.
- Examples
- Uses long prompts, crowded tool sets, context rot, and a four-agent technical blog-writing workflow.
- What you can do after
- Evaluate context quality by identifying irrelevant information, buried details, prompt overload, and tool-selection interference.
Read how Build an AI Agent (From Scratch) explains context window →
Spring AI in Action
A context window is the maximum amount of tokenized input and output that a language model can handle in one interaction.
- How it is used
- Guides model and provider selection for prompts containing conversational history or document context.
- How deep it goes
- Defines token-based capacity and selection implications, but does not explain tokenization mechanics or implementation details.
- Examples
- Contrasts simple questions with prompts expanded by conversational history and document context.
- What you can do after
- Evaluate model fit by checking whether anticipated prompts and responses stay within the available token limit.
AI Agents in Action
A context window is the maximum amount of tokenized input and related context that a language model can consider in one interaction.
- How it is used
- Guides LLM selection by matching available context or memory to task complexity and agent interaction patterns.
- How deep it goes
- Defines context capacity and gives practical thresholds, but does not explain tokenization or model internals.
- Examples
- Uses simple tasks below 4,000 tokens and conversations among multiple agents as contrasting capacity requirements.
- What you can do after
- Evaluate model options by estimating whether their context capacity fits simple tasks or multi-agent conversations.
Build a Large Language Model (From Scratch)
The number of preceding tokens the model conditions on when predicting the next token.
- How it is used
- Uses context_length to control GPT training, positional encoding, and text generation.
- How deep it goes
- Explains configuration, tensor-size implications, and truncation, but does not detail attention internals.
- Examples
- Demonstrates 256-token training configurations, 1,024-token GPT-2 settings, and 8 × 4 token batches.
- What you can do after
- Operate and configure GPT context sizes for training and text generation.
Read how Build a Large Language Model (From Scratch) explains context window →
Related concepts
- tokenmeasures · A token is a discrete unit of text, such as a word, word fragment, character, or symbol, represented and processed as an element by a language model.
- large language modelused by · A large language model is a machine-learning model, typically neural, trained on extensive text data to process and generate language.
- contextcontrasts with · Context is the surrounding information, state, or circumstances that condition how an entity, event, or task is interpreted or how a system behaves.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.





















