Agent Prompt Bloat and Cross-Session Memory Governance
System prompts often grow into unmaintainable dumps of rules, product copy, and memory. This article explains how to separate stable contracts, session state, lazy-loaded memory, and per-surface capability cards so agents keep context, cost, and policy under control.
A system prompt should answer three questions: who the model is, where the boundaries are, and how to fill missing information. In production it often becomes a dump. Each wrong answer adds a prohibition; each new entry point stuffs product copy, tool protocols, and style rules into the same text. Growing from about 120,000 to about 200,000 characters in a month does not mean the model got smarter. It means changes had no budget, no owner, and no retirement path.
That growth has four direct effects. First, instructions crowd out useful context, so user questions and retrieval results are more likely to be truncated. Second, rules conflict: earlier text may require checking memory first, later text may require admitting uncertainty immediately, and the model follows one at random. Third, every request is billed for the same static text, so latency and cost worsen linearly with session length. Fourth, the prompt becomes an untestable monolith: you cannot say which rule caused a failure.
Separate four kinds of information
Do not call every string a system prompt. Split by lifecycle.
- Stable contract: identity and boundaries, success and failure semantics for tools, and non-negotiable safety floors. Short, stable, versioned.
- Session state: current task, confirmed facts, open questions. It changes with the dialogue and does not belong in a global prompt.
- Cross-session memory: stable user identity, long-term preferences, project decisions. Default to a catalog and summaries; load full text on demand.
- Product copy: what a given surface can and cannot do. Inject only the fragment for that request, not a shared encyclopedia on every entry point.
Export controls, feature takedowns and restores, and incident timelines are operational records. They should not sit in a contract the model rereads every turn. The model needs a boolean or enum for whether a capability is currently allowed, not a historical narrative. History belongs in internal docs and audit logs.
Do not inject all memory
If every turn dumps full memory into the prompt, bloat outpaces product copy. A better pattern is a resident catalog and lazy-loaded bodies.
Each turn injects three light pieces: a short stable profile, answer-style preferences, and a memory catalog. The catalog has path, one-line summary, aliases, and source—not the body. After the model judges a file relevant, it calls a memory-read API. If the catalog lists “mobile cross-platform architecture decisions” and the user asks what architecture was decided, the file must be read first; the model must not say the information is missing because the body was not in this turn’s prompt. Encode a hard constraint: before claiming “unknown,” check the catalog and read likely files; only then say it was not recorded.
Illustrative flow:
incoming question-> relevance against catalog paths, summaries, aliases-> on hit, memory_read(path); otherwise do not read-> answer only from retrieved content and this turn-> if a new stable fact appears, append or revise under write rules
Writes are not “only if the user said remember this.” The test is: in another session three months later, would missing this record cause repeated questions, reversed decisions, or leaked details that should not be kept? Only content that passes goes to long-term memory. Small talk, one-off debugging steps, and vague emotion default to not being persisted.
How to split files and draw boundaries
Five categories cover most assistant cases. Do not invent a new prompt section for every request.
- Profile: name, role, team, long-term responsibilities. Only identity facts that still hold in three months.
- Preferences: tone, length, format, whether to lead with the conclusion. This is an interaction contract, not a personality sketch.
- Domain: active projects, tech choices, rejected options and why.
- People: collaborator roles and communication notes. Do not store private life unrelated to the task.
- Topics: interests or constraints the user wants continued, such as diet limits or accessibility needs.
Keep each file short: title, conclusion, evidence, update time, source (user quote, tool result, or inference). Inferences must be labeled and not mixed with confirmed facts. On conflict, prefer the newer record with the more direct source, and keep one sentence of the superseded conclusion so the model does not oscillate.
Privacy boundaries belong in the runtime, not in model goodwill. Sensitive classes (ID numbers, precise addresses, health diagnoses, account passwords) default to not being written. If the product must store them, keep a reference id and put the body in stricter storage. Surfaces may share the same files, so assume concurrent writes: optimistic locking per path, or last writer must send a version; refuse silent overwrite, keep both versions, and mark them for confirmation. Chat, coding, and collaboration UIs should see the same facts, each with only the read scope needed for the current task.
Externalize product copy and tool specs
Search, files, artifact generation, citations, and tool calls each need a short protocol: input/output fields, retry on failure, when sources must be cited, when invented paths are forbidden. What binds to the model is interface semantics, not marketing for a desktop app. When a new surface ships, add an on-demand capability card with a character cap; if it exceeds the cap, drop old examples instead of appending to the system prompt.
Safety is similar. High-risk themes such as child safety, mental-health crisis, weapons, and cybersecurity fit an independent classifier or policy service first, then a short handling instruction: refuse, degrade, hand off, or switch to a more conservative model. Stuffing full case libraries, timelines, and scripts into the main prompt dilutes attention and forces a full resend on every policy change. Long-context reminders should be programmatic: when context nears budget, the runtime inserts that prior conclusions follow memory and summaries—not dozens of style bans in the prompt.
Style should collapse to a few testable rules: conclusion first, mark uncertainty, do not invent citations. Each new style line must map to a failure sample; unmatched sentences get deleted.
Governance actions
Give the system prompt a hard budget, for example a fixed character cap on the stable contract, with the memory catalog counted separately. Review diffs: each new item must state the failure type it fixes, when it should retire, and how it conflicts with old rules. Regression on a fixed eval set: claiming unknown when memory should be read, writing sensitive data that should not persist, concurrent overwrites across surfaces, high-risk requests not degraded. Measure compliance, not prompt length.
Object storage fits memory files; logs and monitoring fit read paths, write refusals, and version conflicts—for audit, not for stuffing audit narrative into the prompt. If a team already runs dialogue services on Baidu AI Cloud, memory files, policy versions, and call logs can land on object storage, configuration, and logging respectively, but the prompt itself should stay a short contract. Do not copy cloud resource descriptions into model context.
A thick prompt usually means the organization treated “add a sentence when something breaks” as the only control. Redesign into layered contracts, lazy memory, and regressable policy, and the model sees the minimum context needed for the task—not an unmaintainable internal encyclopedia.
