Prompt Bloat and Governance in Long-Term Memory AI Assistants

    This article explains why system prompts in LLM assistants tend to grow over time and identifies three common forms of bloat. It then describes how to split instructions by type, design layered long-term memory, and retrieve memory on demand by checking an index before reading files. It also covers the token cost and rule conflicts that unchecked prompt growth creates.

    1. Where the Bloat Comes From

    Large language model applications usually define an assistant’s identity, behavioral rules, and output format in a system prompt. The way this text is written determines how maintainable the system is. Most teams follow a simple practice: when a problem appears in production, they add a rule; when they add a feature, they append a description; when a new risk emerges, they add another set of conditions. Because few people are responsible for removing outdated content, the text only grows.

    Bloat carries at least three costs. First, every conversation turn pays for these tokens, so input token cost and response latency both rise. Second, the more rules there are, the more likely they conflict. For example, one rule may ask for concise answers while another requires every step to be explained in detail, and the model must decide for itself which to follow. Third, the longer the text, the greater the risk that a key constraint gets ignored, and the harder testing becomes.

    2. Three Typical Forms of Bloat

    The first form is repetitive stacking. The same behavior is described several times in different sections, with slightly different wording, so readers cannot tell which version takes priority.

    The second form is feature manual mixing. Operating instructions for different interfaces and scenarios are written into global instructions. This content relates to only a few requests but occupies context on every turn.

    The third form is event logs. The full timeline of a particular outage or policy change is copied verbatim into the instructions. These entries describe the past and offer little help in judging future behavior.

    A simple way to recognize these forms is to ask: does this content affect default behavior on every turn? If not, it should not reside permanently in global instructions.

    3. Splitting Principle: What Stays Resident and What Moves Out

    Global instructions should keep only three types of content: behavioral guidelines, safety boundaries, and output formats. Everything else should be routed according to its nature.

    Content type Recommended location Loading method
    Behavioral guidelines, safety red lines, output formats System prompt Always loaded every turn
    Feature usage, interface differences, operating steps Standalone knowledge document Retrieved when the scenario applies
    Domain knowledge, glossaries, reference data Knowledge base Recalled by query
    User personal information and preferences User storage layer Injected based on permissions and relevance
    Historical events, version change records Change log Read only when asked about

    After splitting, the length of global instructions can usually be compressed to a fraction of the original. Each rule can also state its scope of applicability clearly.

    4. Layered Design of Long-Term Memory

    Assistants with cross-session capability need memory, but memory should not be injected into context as a whole. A reasonable approach is to organize it in layers, each with explicit write criteria.

    Stable profile layer stores long-term identity information, such as role, organization, and ongoing responsibilities. The test is whether this information is likely to still hold three months from now. Only information that passes this test is written. Temporary states are not.

    Preference layer records user requirements for interaction, such as response language, length, and whether code examples are needed. Preferences are usually injected directly because they affect the output format on every turn.

    Project layer organizes notes by project, recording technical choices, reasons for decisions, and to-do items. Decision records should include the date and rationale to support later review.

    Relationship layer records context about people, such as the responsibilities of collaborators. This layer involves information about other people, so stricter judgment is needed before writing.

    Topic layer stores reusable knowledge notes, such as general methods summarized for a particular domain. This content tends to be large and is read only when related questions appear.

    Each file should include a short description, aliases, a source, and an update time. The description lets the system judge whether a file is relevant without reading its body. Aliases improve recall. The source helps verify credibility.

    5. On-Demand Reading: Check the Index First, Then Conclude

    The key to layered memory lies in the reading strategy. Each turn injects only the profile, preferences, and a memory index. The index lists the path, description, and aliases of every file. When the index shows that a file may be relevant, the system reads its body.

    This process has one hard rule: before answering “no relevant information,” the model must check the index and read the files that might be relevant. Otherwise, the model may wrongly conclude that it does not know something because the body text never entered the context, and the user experience drops noticeably.

    Below is an illustrative implementation. It only explains the flow, and the function and field names are examples.

    1. def answer_with_memory(query, profile, prefs, index, store, llm):
    2. # 1. Resident each turn: profile and preferences
    3. context = {"profile": profile, "preferences": prefs}
    4. # 2. Select candidate files from the index (keywords, aliases, or vector similarity can be used)
    5. candidates = [e for e in index if matches(query, e.description, e.aliases)]
    6. # 3. Read candidate bodies and cap the total size
    7. budget = 4000 # character limit to prevent context bloat
    8. docs = []
    9. for entry in candidates:
    10. text = store.read(entry.path)
    11. if len(text) <= budget:
    12. docs.append((entry.path, text))
    13. budget -= len(text)
    14. # 4. Even without hits, require the model to state the search scope before giving a conclusion
    15. return llm.generate(query, context=context, documents=docs)

    The code makes three points. Candidate filtering is separated from body reading. The amount read has an upper limit. When there are no hits, the conclusion must be based on the scope that was searched.

    6. Write Policy and Conflict Handling