Memory and Context
Each model request has a limited context window. CUST/OS assembles the system prompt, selected skills, current state, and conversation history to fit within it. Persistent memory stores facts that can be used across conversations.
The layers
Every turn, the agent's context is assembled from these sources:
- System prompt -- the agent's persona and behavioral rules (mostly static, cached between turns).
- Selected skills -- the 1-3 most relevant skills for the current message, with their tool definitions and usage rules.
- Dynamic section -- rebuilt every turn with the current time, operator identity, persistent memory facts, active todos, and cached tool results.
- Conversation history -- recent messages in full, older messages in summarized form.
- The operator's latest message.
The runtime caches the persona and skill descriptions, which change less often. It rebuilds the time, recent tool results, and active memory facts for each turn.
Conversations
Each conversation is independent. It has its own message history, its own summary state, and its own tool result cache. The operator can have multiple parallel conversations -- one for route planning, one for casualty reports, one for sensor tasking -- and switch between them instantly.
The chat panel provides a conversation selector and a new-conversation button. Starting a new conversation gives the agent a clean slate without losing the history of prior conversations.
Context management (summarization)
LLMs have a finite context window. A long mission can easily exceed it. CUST/OS handles this automatically:
When the conversation exceeds a configurable threshold, older messages are summarized to free space. The summarization prompt asks the model to retain:
- Exact coordinates and grid references
- Callsigns and unit designations
- Decisions made and their rationale
- Tool calls and their results
- Timestamps and sequence of events
The most recent and first messages are kept verbatim. The middle of the history is compressed into a structured summary. A model-generated summary can omit or misstate details, so check critical values against their source.
If summarization fails, the system falls back to truncation, dropping older messages to fit the context limit. Information in those messages may no longer be available to the model.
Persistent memory
Some facts should outlive a single conversation:
- "My callsign is VIPER-6"
- "OBJ ALPHA is at 38.5N 77.0W"
- "The route through grid 12S WG is mined"
These facts are stored as key-value pairs. Dedicated tools let the agent remember, recall, and forget them. The context builder includes relevant persistent facts with each turn.
Use persistent memory for short facts. For longer passages such as SOPs and reference material, CUST/OS provides a separate vector store for semantic retrieval.
Tool result caching
When the agent calls a tool, the result is cached for the duration of the conversation. On subsequent turns, recently cached results are included in the agent's context under a "previously computed values" section. This serves two purposes:
- Reuse -- the model can refer to a previous position query, unit list, or distance calculation without requesting it again. Changing map state may still require a fresh query.
- Context size -- a short summary of the result uses less space than repeating the full output.
The cache is cleared when the operator switches conversations.
Skill selection
With dozens of skills installed, including all of them in every prompt would exhaust the context window. Instead, CUST/OS selects the 1-3 most relevant skills per turn using a combination of keyword matching and semantic similarity.
Only the selected skills -- their descriptions, rules, and tool definitions -- are included in the prompt. This keeps the system prompt compact even as the skill library grows. The selection is transparent: the operator can see which skills were selected for each turn.
If no skills match the operator's message, the agent responds without skill tools.
What this gets you
These mechanisms let a conversation continue beyond the raw history that fits in one request. Summaries and selection reduce context size at the cost of detail. Use persistent memory for facts needed across conversations, and fresh tool queries for state that may have changed.
See also
- Architecture overview -- where memory fits in the larger system
- The ReAct loop -- how the agent uses context each turn
- How skills are loaded and shared -- skill files and distribution