LLM System Prompt Bloat: Designing a Layered Memory Architecture

    In agentic AI applications, the system prompt acts as the underlying operating system injected into every conversation turn, defining the model's role, rules, and tool use. This article examines a real-world case where a large model's system prompt grew from roughly 120,000 to 200,000 characters in about a month — driven largely by a persistent memory file system. Rather than judging a specific product, it analyzes, from an engineering perspective, why system prompts bloat, the four costs of keeping everything resident, and how a two-tier architecture of resident loading plus on-demand reading can manage the content. It also covers memory organization and write criteria, concurrency and privacy constraints, and how to govern system prompts as runtime configuration through versioning, rule prioritization, evaluation, and observability.

    LLM System Prompt Bloat: Designing a Layered Memory Architecture

    Introduction: A system prompt that grew by nearly 70% in a month

    In agentic (Agent) applications, the system prompt is the “underlying operating system” injected into every conversation turn. It defines the model’s role, rules, how it should use tools, and the boundaries of its output. According to public discussion, one large-model assistant’s system prompt grew from roughly 120,000 characters to about 200,000 within roughly a month — an increase of nearly 70%. The largest single addition among the disclosed content was a persistent memory file system specification spanning more than 200 lines. It also included notes on routing high-risk requests to a fallback model, and the practice of writing a particular compliance policy’s takedown-and-restoration timeline directly into the prompt. Because this prompt is passed in again on every request, the cost and behavioral impact of the bloat are multiplied.

    This article does not evaluate the merits of any specific product’s design. Instead, it treats this case as a representative sample and answers three questions from an engineering standpoint:

    • Why do system prompts bloat?
    • What does the bloat cost?
    • How can a layered architecture bring this content under control?

    1. Where the bloat comes from: a “patch-style” growth curve

    From the disclosed content, the additions fall roughly into seven categories:

    Category Typical content Engineering essence
    Memory file system Read/write timing, directory structure, file format, privacy boundaries, conflict handling A built-in persistent state mechanism
    Model tiering and fallback Routing high-risk requests from a lighter model to a more capable one Routing inference resources by risk
    Multi-product descriptions Coding assistant, collaborative office tools, browser extension, spreadsheets and slides, design tools, etc. Multiple entry points sharing the same underlying model
    Tool and output specs Retrieval, file read/write, structured content outputs, citations, tool calls Unified calling conventions for external capabilities
    Safety details Child safety, mental health, weapons, cybersecurity, very long conversations Formalized rules for risk scenarios
    Compliance event timeline The takedown and restoration of a particular policy Behavior constraints for a specific period
    Style and interaction rules Tone, length, format Constraints for output consistency

    Laid out together, a clear through-line appears: whenever a new problem shows up, another prompt rule is appended; whenever a new product form or tool ships, another block of capability description is added. This is a classic “patch-style” governance model:

    • Increments come from the demand side. As the product covers more scenarios — a coding assistant, an office assistant, a browser extension, spreadsheet and slide tools, design tools — they may all share the same underlying model. To keep behavior consistent, the differences between entry points get written into a single prompt.
    • Patches come from the incident side. After every bad-case review, the easiest action to land is “add one more sentence.” That sentence usually has no expiration and won’t be removed even after the scenario recovers. Writing a compliance policy’s takedown-and-restoration timeline verbatim into the prompt is a textbook example of a short-term rule lingering indefinitely.
    • Coordination comes from the tiering side. The same assistant may connect to models of different capabilities behind the scenes. Because model capabilities differ, more boundary explanations are needed to smooth out those differences. When a fallback mechanism like “route high-risk requests to a stronger model” is introduced, the explanatory text goes into the prompt too.

    The root problem isn’t that “a lot was written.” It’s the implicit assumption in how it’s written: that prompt length is free, and that old rules will never expire.

    2. Why you can’t keep stuffing: four costs of long context

    Long-context capability solved the “can it fit” problem, but not the “should everything go in just because it fits” problem. Keeping everything resident in the prompt carries at least four costs.

    1. Cost scales linearly per request

    The system prompt is a fixed overhead re-sent on every request. Roughly estimating at about 4 English characters per token, 200,000 characters is around 50,000 tokens — and that excludes the memory body, conversation history, and tool results. Assume 100,000 requests per day, each carrying a 50,000-token system prompt: just this portion means processing about 5 billion tokens per day. Even with prompt caching, the first-write cost still exists, and the cache hit rate depends on how frequently the version changes.

    2. Rule conflicts and attention dilution

    Hundreds of mutually constraining rules easily contradict one another. For example:

    • “Confirm with the user when uncertain” and “don’t interrupt the user on steps you can complete autonomously” may both apply in a given situation.
    • A style rule demanding “be concise” pulls against a safety rule demanding “warn about risks thoroughly,” and the length requirement gets caught in between.
    • When a general tool-calling convention conflicts with a specific office tool’s dedicated instructions, which rule wins? The prompt often doesn’t specify a priority.

    The finer the rules, the more implicit assumptions there are — and the model can’t tell which assumptions still hold in the current conversation.

    3. Short-term rules lingering long-term

    Event-driven rules are inherently time-bound, yet they’re often treated as permanent. The model may repeatedly bring up a policy timeline that has already ended during ordinary conversation, and apply an outdated restriction to the current exchange. Rules should have a lifecycle like code: a trigger condition on the way in, and a way to recognize and retire them when they end.

    4. Poor engineering maintainability

    A prompt that “only grows, never shrinks” can’t answer several key questions:

    • Who introduced a given rule, and to solve what problem?
    • After a change, did performance go up or down?
    • Which rules have never been triggered?

    Without version history, evaluation, and reference links, the prompt is just a piece of text that can’t be regression-tested.

    It’s worth stressing that layered loading isn’t about cutting functionality. A good system prompt should be “thick but structured”: replacing “everything resident” with “index resident, body on demand” lets you keep all capabilities while controlling the resident cost.

    3. Core design: resident loading + on-demand reading

    The most important point about the disclosed memory mechanism is that it separates “memory” from “the directory of memories.” Each turn, the system prompt injects only three things:

    • <profile>: the body of the identity memory file;
    • <preferences>: the user’s preferences for how answers are given;
    • <memory_listing>: the path, description, alias, and source of every memory file.

    Other memory files appear only in the listing; their bodies aren’t loaded. Once the model judges that a file might be relevant, it fetches the full text through a read tool. Take the example “what architecture did my cross-platform UI project decide to use earlier” — even if the answer isn’t in the prompt body, the model should first read /areas/ui-project.md from the listing, rather than directly answering “there’s no such information.” So the prompt must explicitly state: before saying “there’s no such information,” the model must check the listing and read any potentially relevant file.

    This idea can be generalized into a universal “two-level loading” pattern and extended to other parts of the system prompt.

    1. Resident layer: stable, concise, with an index

    Content suited to the resident layer has three traits: it’s generally applicable across scenarios, rarely changes, and affects behavior globally. It typically includes the role definition, safety baselines, general tool-calling conventions, and indexes to various resources. The index itself must stay lightweight — for example, each entry keeps only a path, a one-line summary, an alias, and a source. Aliases exist so that different phrasings like “architecture decision,” “tech selection,” and “ADR” all point to the same file.

    2. On-demand layer: detail-heavy, fast-changing, locally effective

    Product-specific instructions, detailed handling for high-risk scenarios, and knowledge specific to a business are all suited to the on-demand layer, organized as “documentation” or “knowledge files.” They’re retrieved and loaded by the model when needed, or explicitly injected by upper-layer orchestration logic.

    A schematic structure looks like this (illustrative only, not any specific implementation):

    1. / # Resident layer: the system prompt
    2. role.md # Role and goals
    3. safety.md # Safety baseline (red-line rules stay resident)
    4. tools.md # General tool-calling conventions
    5. memory.md # Memory read/write spec (write conditions, format, privacy boundaries)
    6. index/ # On-demand layer index (metadata only, no bodies)
    7. profiles.md
    8. knowledge.md
    9. products.md
    10. /memory/ # On-demand layer: memory bodies
    11. profile.md # Stable identity info
    12. preferences.md # Answer-style preferences
    13. areas/ui-project.md # Project area: architecture decisions, progress
    14. people/partner.md # Person info
    15. topics/diet.md # Topic: dietary preferences and restrictions

    It’s worth stressing that here “resident” means passed in with each request, and “on-demand” means the model explicitly reads it via a tool call — both are application-layer concepts, unrelated to how attention is allocated within a single inference pass. The resident layer can also be split into a “static part” and a “dynamic part”: the static part contains nearly-invariant content like the role and safety rules, which can be paired with the platform’s prompt caching to reduce repeated processing overhead; the dynamic part keeps only user preferences and the index. Reducing the size and change frequency of the dynamic part improves cache utilization on its own.

    3. Write key rules as executable actions

    A rule like “check the listing before answering” works because it describes a concrete action, not an abstract principle. One workable phrasing:

    1. Before answering any question that depends on personal background, do the following:
    2. 1. Check <memory_listing> and find 1–3 potentially relevant paths;
    3. 2. Call memory_read(path) on the most relevant file;
    4. 3. On a hit, answer based on the file's content and cite the source path;
    5. 4. Only after checking the listing and finding no relevant file may you say "there's no such information."

    Such rules should be validated with an evaluation set. In a test scenario where “the memory exists but its body wasn’t injected,” a single instance of the model “directly saying it doesn’t know” shows the rule hasn’t truly taken effect.

    4. Organizing and writing memory: when to remember

    The resident mechanism solves “how to read”; the memory spec must also solve “what to remember and how.” The disclosed content shows memory organized by file category, where /profile.md stores stable identity, such as name, title, organization, and long-term responsibilities. The judgment can be summed up in one sentence: only write information that will still be useful three months from now into long-term memory. This principle can be broken into four criteria:

    Criterion Write to long-term memory Keep only in the session context
    Timeliness Long-term stable One-off, fast-changing
    Derivability Can’t be derived from existing context Can be directly inferred from known information
    Privacy sensitivity General personal info the user accepts being retained Highly sensitive info like ID documents, accounts, health
    User intent Explicitly asked to remember, or clearly prefers long-term retention A temporary agreement for the current task only

    At the same time, “memory is a tool, not a rule.” Cross-project preferences (like preferring concise answers) are suited to long-term storage; an agreement specific to one project should go into that project’s memory file, avoiding contamination of global preferences.

    Memory can use Markdown with metadata, so it’s easy for both machines and people to handle:

    1. ---
    2. id: areas/ui-project
    3. updated: 2026-03-01
    4. source: compiled from conversation
    5. ---
    6. # Cross-platform UI project
    7. - Architecture: layered architecture, with the UI layer separated from the business logic layer
    8. - Rationale: enables multi-platform reuse and independent testing
    9. - Status: reviewed and approved

    For reading, a schematic snippet describes the loading flow:

    1. def load_context(query: str, index: list[dict], injected: set[str]) -> str:
    2. """Assemble the context in the order: resident injection -> index match -> on-demand read."""
    3. parts = [render_injected(injected)]
    4. for entry in rank_by_aliases(index, query)[:3]: # rank by path, summary, and alias
    5. if entry["path"] not in injected:
    6. parts.append(f"[reference memory] {entry['path']}")
    7. parts.append(read_memory(entry["path"]))
    8. return "\n".join(parts)

    For a memory store with many entries, vector or keyword retrieval can be added as a supplement, but the index itself should stay structured, readable, and auditable.

    5. Sharing, concurrency, and privacy: three hard constraints on the memory system

    The disclosed content also mentions that different interfaces may share the same set of memory files and even modify them simultaneously. This imposes three constraints the memory system must confront head-on.

    Concurrent consistency. When multiple sessions write to the same file at once and each session reads only the old version in its own context, you get “last write overwrites first,” causing memory loss. Engineering options include:

    • Optimistic concurrency control: maintain a version number per file; writes carry the version that was read, and on a mismatch, re-read, merge, and commit again.
    • Field-level merging: update different fields like preferences and project status independently, avoiding whole-file overwrites.
    • Visible conflicts: content that can’t be merged automatically is kept as “candidate memory” for a later session or the user to confirm.
    1. def merge_memory(current: dict, incoming: dict) -> tuple[dict, list[str]]:
    2. """Merge memory by key; keys present in both versions with different values go into a conflict list for confirmation."""
    3. merged = dict(current)
    4. conflicts = []
    5. for key, value in incoming.items():
    6. old = current.get(key)
    7. if old is None or old == value:
    8. merged[key] = value
    9. else:
    10. conflicts.append(key)
    11. merged[key] = {"latest": value, "previous": old, "status": "pending"}
    12. return merged, conflicts

    Permission and privacy boundaries. Memory may contain identity information, work details, and highly sensitive personal data all at once, so the system must ensure:

    • Minimal necessity: record only the information needed to complete the task.
    • Sensitivity classification: sensitive fields don’t enter long-term memory by default, or only a de-identified summary is stored.
    • Access isolation: memory is isolated by default across entry points and users; cross-domain reads require explicit authorization.
    • Queryable and deletable: users can view, modify, and delete their stored memory.

    Expiration and correction. Memory goes stale, so the system needs an expiration mechanism and correction rules:

    • Attach a validity period to time-sensitive memory; once it expires, mark it for review.
    • When new user information contradicts old memory, confirm with the user first, then update or delete the old memory.
    • Memory is reference only; it can’t replace the current instruction. When it conflicts with the user’s current request, the current request wins.

    6. Govern the system prompt as “runtime configuration”

    Whether or not a layered memory approach is adopted, the “patch-style” growth problem persists. The more fundamental fix is to treat the system prompt as a software asset that needs ongoing operation.

    1. Versioning and change review. Put the prompt under version control; record the reason, impact scope, and related issue for each change. Reviews should focus on dependencies and conflicts between rules.

    2. Establish priority for rules. Borrowing from control-tiering ideas in the security field, define a clear conflict-resolution order:

    Priority Category Description
    P0 Safety and compliance baseline Cannot be overridden by other rules
    P1 Platform-level constraints Tool-calling format, output structure, etc.
    P2 User preferences Tone, length, format, etc.
    P3 Default style Fallback when no clear preference exists

    3. Distinguish resident from on-demand. Split by stability and scope: red lines and general conventions stay resident; scenario details and product instructions load on demand.

    4. Build an evaluation set. Cover dimensions like instruction-following, memory hit rate, style consistency, and safety boundaries, and run a comparative regression before and after each change.

    5. Clean up regularly. Periodically audit each rule’s trigger frequency and related-issue status: retire rules whose issues are closed, and merge or delete rules with zero hits over a long period.

    6. Stay observable. Record how often each rule is triggered, the system prompt size per request, and the cache hit ratio, using data to drive optimization.

    If you need the model to route traffic across capability tiers by risk, the general approach is to put a lightweight pre-judgment in front, escalating to stronger handling only for requests judged high-risk or high-complexity. This judgment should be linked with both business rules and the observability system, rather than hanging a static description on the system prompt indefinitely.

    In related technical practice at Baidu, the Qianfan general-purpose Agent platform from Baidu AI Cloud provides a toolchain covering development, debugging, deployment, and online runtime monitoring. Similar applications can likewise draw on these general capabilities for configuration management, evaluation, and observability, so that the system prompt and memory spec are both traceable and measurable.

    Conclusion

    Growing from over 100,000 characters to 200,000, the change in the large-model system prompt reflects an inevitable shift in agentic applications — from “able to converse” toward “able to work over the long term.” The core problem isn’t too much content, but that the organization is still stuck at “everything resident, only grows.” Four steps — layered loading, clear write criteria, handling concurrency and privacy, and governing the prompt as configuration — can turn the system prompt from an ever-accumulating burden into a maintainable, testable, iterable engineering asset. For teams building agentic applications, the earlier this governance mechanism is established, the more controllable the cost of each future capability expansion will be.