Working context is the information available to a model at inference time that influences its output. It is assembled for a model call and must fit within the context window, the limited amount of text the model can process at once, usually measured in tokens. section 1.0 section 1.1
Context engineering assembles, maintains, and routes this information, aiming to supply the smallest set of tokens that makes a task solvable. Unlike prompt engineering, which focuses on an input’s wording, it manages everything the model sees when that input arrives. section 1.0 section 1.1
A call’s context can be assembled from six sources:
- Instructions: behavioral guidelines, constraints, and role expectations. section 12.1.1
- Knowledge: retrieved or supplied external information. section 12.1.1
- Tools: available actions and their schemas. section 12.1.1
- Memory: information from earlier interactions or long-term stores. section 12.1.1
- State: the current runtime state. section 12.1.1
- Query: the current user input. section 12.1.1
Context differs from model parameters: parameters encode what the model learned during training, while context supplies information at inference time. As each output token is generated, its probability depends on the supplied context and the tokens already generated. section 12.1.1
A tool result enters working context
A Python application sends a user prompt and a weather function definition to an OpenAI model. It executes the function requested by the model and injects the returned weather value into context for the final response. The tool extends both what the application can do and what the model knows for that response. section 4.6.1
Promoting long-term memory into context
For each new message, a chat application retrieves relevant memories using Mem0 and Qdrant, inserts them into instructions, calls the model, and writes the latest interaction back to memory. Stored memory is not all working context: retrieval selects what to promote. Too much irrelevant memory can degrade quality and waste tokens. section 5.5.1
Listing 5.2 Python excerpt using Mem0 and Qdrant to illustrate long-term memory retrieval and persistence
from mem0 import Memory
def build_mem0_config() -> Dict[str, Any]: #1
return {
"vector_store": {
"provider": "qdrant",
"config": {
"collection_name": os.getenv("MEM0_COLLECTION", "mem0_demo"),
"host": os.getenv("QDRANT_HOST", "localhost"),
"port": int(os.getenv("QDRANT_PORT", "6333")),
},
},
}
mem0 = Memory.from_config(build_mem0_config())
retrieved = mem0.search(user_message, user_id=user_id) #2
instructions = f"""
You are a helpful assistant. The following items are retrieved from
long-term memories from previous sessions. Use them when relevant,
but do not assume they are always correct.
MEMORIES: {format_memories(retrieved)} #3
"""
response = client.responses.create(
model="gpt-5",
instructions=instructions,
input=[ {"role": "user", "content": user_message} ],
)
assistant_reply = response.output_text
mem0.add( #4
messages=[
{"role": "user", "content": user_message},
{"role": "assistant", "content": assistant_reply},
],
user_id=user_id,
)
Inspect the memory configuration, search, and instruction assembly used to move stored memories into a model call. section 5.5.1
The management scope changes with the application. Application frameworks can assemble context for individual calls; agent orchestration frameworks also manage how state, tool observations, and memories evolve across multi-step workflows. Assistant interfaces may hide parts of context, so answers about system instructions or available tools can be approximate or sanitized. section 10.1 section 1.6.1
