home/glossary/Context Density
Context Engineering

Context Density

definition

Context density measures how much useful, task-relevant information is packed into each token of context, and optimizing for density is the primary lever for getting better agent performance within fixed context window constraints. Low-density context wastes tokens on boilerplate, irrelevant examples, verbose formatting, and redundant information; high-density context strips everything to its essential signal — tight type signatures instead of full source files, relevant test failures instead of entire test suites, summarized conversation history instead of raw transcripts.

Context density measures how much useful, task-relevant information is packed into each token of context, and optimizing for density is the primary lever for getting better agent performance within fixed context window constraints. Low-density context wastes tokens on boilerplate, irrelevant examples, verbose formatting, and redundant information; high-density context strips everything to its essential signal — tight type signatures instead of full source files, relevant test failures instead of entire test suites, summarized conversation history instead of raw transcripts. Research on "lost in the middle" effects shows that models attend less to information in the center of long contexts, making density optimization not just about fitting more in, but about ensuring critical information is positioned where the model will actually use it. Mastering context density is the difference between an agent that runs out of context window at step 5 and one that completes a 20-step workflow with budget to spare. This concept connects to context window budget for the constraint that makes density matter, context assembly pipelines for the system that controls density, token economics for understanding the cost of wasted context, and few-shot examples for a common source of context bloat.