Context
What is context?
Context is the information available to a language model or AI agent when it produces its next response or decision. It can include prompts, instructions, conversation messages, retrieved documents, tool definitions, observations, current state, and selected memories.
The model does not automatically know everything available to the surrounding application. Relevant information must be placed into the current context or made accessible through a tool.
How context is assembled
An agent application often builds context before every inference. It may combine:
- system and user prompts;
- the current goal and constraints;
- recent conversation turns;
- relevant fields from [agent state](/glossary/agent-state/);
- retrieved memory or external documents;
- available tool definitions;
- recent tool results.
For example, before drafting a customer reply, an agent might receive the customer’s message, order status, refund policy, prior approved preference, and a rule requiring approval above a limit.
Context versus context window
Context is the information supplied to the model. The [context window](/glossary/context-window/) is the maximum amount of tokenized input and output the model can handle for one inference. If the available information exceeds that limit, the application must select, summarize, retrieve, or discard material.
More context is not always better. Irrelevant or conflicting information can make the important facts harder to use, while stale context can lead to incorrect decisions.
Context versus memory and state
Memory stores information for possible future use. Context contains the information selected for use now. A user preference may exist in long-term memory but affect the model only after retrieval into the current context.
State tracks the changing status of a task, such as completed steps and pending approvals. State may be stored outside the model and only partially included in context. Working memory is the task-relevant information actively maintained during current work and often contributes to context.
Why context quality matters
An agent’s behavior depends not only on the model but also on what the model sees. Missing constraints can cause unsafe actions; duplicated histories waste tokens; untrusted webpages can attempt to override legitimate instructions.
Strong context management prioritizes relevant, recent, authoritative information. It labels sources, separates instructions from data, protects sensitive content, and refreshes facts that may have changed. Builders should test whether the right evidence reaches the model at the right step rather than simply maximizing input length. See [Memory in AI Agents](/memory-in-ai-agents/) for the full relationship between context, state, retrieval, and memory.
Learn More
Memory in AI AgentsContinue with the full AIRundown guide →