Memory Without Replaying Everything

NextChat does not normally send an entire conversation every time a user writes a new message. This chapter follows how NextChat selects context from a session, a mask, recent messages, and a stored summary, then shows what happens when the conversation becomes too large or the user clears its history. The aim is practical: readers should be able to predict what a provider is likely to see and choose between exact short context and lossy long-conversation memory for the task at hand.

The request is assembled in layers

A NextChat session contains more than a transcript. It holds messages, a mask, model settings, a possible memory summary, and a marker that can cut older messages out of future requests. When the user submits new text, the chat store first builds a context list from those pieces. The current input is then added to that list before the selected provider adapter turns it into a provider-specific request.

The order matters. A request can include several layers:

  1. a system instruction when the selected model and settings call for one;
  2. an MCP instruction when that optional capability is enabled;
  3. a long-term memory message containing a previous summary;
  4. the mask’s ordered context prompts; and
  5. a short-term window of recent conversation messages.

The new user input follows these layers. The provider therefore receives a constructed context, not simply “the chat so far.” Two sessions with similar visible histories can send different requests if they use different masks, memory settings, clear-context markers, or models.

The system layer is conditional rather than universal. NextChat injects its ChatGPT-style system text for selected GPT-family models when system-prompt injection is enabled. That text can include model and time information and formatting guidance. If the condition does not apply, the request does not necessarily contain that same system message. MCP adds another conditional instruction that describes the available tools and the format expected for a tool request. These prompts are part of the request boundary, even though they may not look like messages typed into the visible conversation.

A mask adds a more deliberate form of context. It can contain ordered user and assistant prompts that establish a role, a format, or a small amount of domain knowledge. It also carries model settings, memory preferences, language, and optional capability selections. The mask is therefore not only a saved opening sentence. It is a session-level policy for what kind of conversation the user is trying to run.

The distinction between global and session settings changes the result again. A new session can inherit the global model configuration and a mask can contribute its own overrides. If a user edits the configuration inside a conversation, that session can stop following later global changes until the user restores synchronization.