Agent Architecture Design for Self-Evolving Capabilities: Persistent Memory and Decoupling
This article explains why conversational agents lose context between sessions and how to fix it through three design dimensions: self-evolution, persistent storage, and architectural decoupling. You will see a three-step loop for turning successful task traces into reusable, parameterized skills, a three-layer memory model that separates stable facts, session history, and external knowledge, and a decoupled layout where scheduling, capabilities, memory, and models evolve independently. It also covers guardrails for automatic optimization, governance and metrics that keep memory from becoming a liability, and how the design maps onto general-purpose cloud building blocks.
1. The Starting Problem: Why Agents Keep “Meeting You for the First Time”
In the previous session, the agent had just helped you write a structurally complex deployment script. Close the window and reopen it, and it behaves as if it has never seen you, probing your tech stack, directory conventions, and preferences from scratch. This is not an occasional flaw of one particular model but a structural trait of mainstream conversational agents today: the reasoning process itself carries no long-term state, and once the session context is released, everything accumulated in that round disappears. In engineering terms, it is a nearly stateless function: context goes in, a result comes out, the call ends, and state resets to zero.
Escaping this “cyber amnesia” cannot be done by stretching the context window indefinitely. Context is a scarce resource: cost and latency both rise with length, and key information tends to get diluted inside long text. The workable path is to separate memory from the reasoning process and turn it into an external asset that is persistent, retrievable, and governable, while giving the agent a mechanism to distill successful experience into reusable capabilities. This article covers three dimensions: self-evolution, persistent storage, and architectural decoupling.
2. Self-Evolution: Turning One-Off Experience into a Reusable Asset
2.1 The Gap in the Traditional Execution Path
The typical agent runs in a linear fashion: receive an instruction, plan steps, call tools, return the result. The task finishes and the experience is cleared. Some open-source agent frameworks with mature ecosystems do offer a large set of extensible skills, but the creation, review, and iteration of those skills are still driven mainly by developers, so experience produced at runtime rarely flows back into the capability library automatically.
The gap is easy to locate: after “return the result,” there is no loop that solidifies process knowledge.
2.2 A Three-Step Loop: Extract, Solidify, Reuse
A practical self-evolution loop can be broken into three steps.
Step one, experience extraction. After a task succeeds, pull the key decision points out of the execution trace: why this approach was chosen, which preconditions had to hold, and which branches were ruled out. Keep only transferable abstract steps, and strip out temporary information tightly bound to this particular environment, such as one-off paths and temporary credentials.
Step two, capability solidification. Write the experience into a structured skill file, which typically contains five parts: trigger conditions, applicable preconditions, execution steps, verification method, and caveats. A skill is not a log but a callable asset with parameter templates:
---name: container_deploytrigger: need to build an image for a service and release it to a container platformparams: [image_name, tag, replicas]---1. Validate that params are complete and check that the base image is available2. Build the image and push it to the image registry3. Update {image_name}:{tag} in the deployment manifest4. Roll out progressively and watch readiness probes and error logsnotes: keep the previous tag for rollback; back up configuration before any change
Placeholders such as {image_name} and {tag} let one skill fit different projects and avoid the fragmented growth of “one script per task.”
Step three, reuse on demand. When a similar task comes up again, search the skill library first, load the matching entry, and execute it directly, skipping lengthy re-reasoning. This yields two kinds of benefit: lower response latency and better behavioral consistency, because the same class of task no longer produces wildly different approaches each time.
2.3 Automatic Optimization of Prompts and Skills, and the Necessary Human Guardrails
A further step is to extend the optimization target from code to the prompts, tool descriptions, and skill text themselves, rewriting them continuously through population-based search and feedback iteration, then keeping candidates based on the tradeoff between effectiveness and complexity. Methods like these usually require no model retraining and can iterate through API calls alone, so the engineering barrier is clearly lower than the reinforcement learning route.
Automatic optimization must have boundaries, otherwise goal drift is likely. Three practices are more robust in engineering terms: submit optimization output as a change request that a human reviews before merging; define a canary scope and a rollback version for each skill; and forbid automatic rewriting of skills that involve permissions, data deletion, or production releases, allowing human maintenance only.
3. Persistence: Three Memory Layers with Distinct Jobs
A single store can hardly satisfy three different needs at once: stable facts, historical detail, and external knowledge. A layered design is clearer.
The first layer is built-in long-term memory, which holds stable facts: tech stack, code conventions, directory layout, account and environment constraints. The data volume is small and reads are frequent, so key-value or document form works well. Writes need deduplication and conflict merging so that synonymous entries do not pile up repeatedly.
The second layer is session retrieval, which holds fragments of past interactions. Raw records are too large to inject in full, so the usual approach is to chunk and vectorize them first, retrieve a small number of the most relevant fragments by semantic similarity at query time, then rank with time decay and importance weights to keep the injected volume under control.
The third layer is external knowledge access, reading information from requirement documents, tickets, monitoring, and logging services through plugins or tools. Its value is handing the “freshness” of memory to authoritative data sources, reducing the interference of stale information in decisions.
The recommended collaboration order for the three layers is fixed: read long-term memory first to establish constraints, then retrieve sessions to fill in context, and finally access external data on demand to verify facts. Writes go the other way: only information verified as a stable conclusion is allowed to be promoted into long-term memory.
4. Architectural Decoupling: Let Capabilities, Memory, and Models Evolve Separately
If self-evolution and persistent memory are coupled inside a monolith, they quickly turn into a hard-to-maintain giant. The key to decoupling is splitting responsibilities: the scheduling layer handles task decomposition and orchestration; the capability layer registers, discovers, and invokes skills as units; the memory layer exposes a unified read/write interface; and the model layer stays replaceable.
The direct benefit of decoupling is controllable replacement cost. Swapping models does not require rewriting skills, and changing the memory strategy does not affect business orchestration. In practice, general-purpose cloud capabilities can carry the needs of each layer: a container platform hosts stateless execution units, object storage keeps skill files and version snapshots, a managed database stores structured memory, a message queue buffers long-running tasks, logging and monitoring with alerting provide observability, and a key management service holds credentials so sensitive information never lands in skill text.
Keep the interface contract minimal, for example:
class MemoryStore:def recall(self, query: str, top_k: int = 5) -> list[dict]: ...def remember(self, fact: dict, level: str = "session") -> None: ...class SkillRegistry:def match(self, task: str) -> dict | None: ...def promote(self, skill: dict) -> str: ... # returns a change request pending review
5. Governance and Metrics: Keeping Memory from Becoming a Liability
Memory and skills keep growing, and without governance the gains get eaten by noise. Four kinds of constraints are worth setting: capacity constraints, capping the number of long-term memory entries and the length of each; quality constraints, attaching success rate and call count to each skill and automatically downgrading and archiving entries that go unmatched for a long time or show high failure rates; security constraints, keeping credentials and personal information out of memory and skill text; and audit constraints, retaining change history so any automatic optimization can be traced to a specific version.
For metrics, watch three signals: whether average time for the same class of task drops, whether the repeated-question rate drops, and whether the first-attempt success rate after skill reuse rises. If time drops while success rate drops at the same time, the skill is usually over-generalized and the trigger conditions need tightening.
6. Conclusion
The essence of an agent “forgetting everything on restart” is the absence of a mechanism for state and experience accumulation, not insufficient model capability. Solidifying experience into parameterized skills, persisting facts across three layers, decoupling capabilities and memory from the model, and layering human review and capacity governance on top are what turn an agent from a one-off tool into a long-term collaborator that keeps accumulating, behaves consistently, and remains auditable. On Baidu AI Cloud, the design above maps directly onto a combination of general-purpose capabilities such as a container platform, object storage, a managed database, a message queue, and monitoring with alerting, and can be implemented without relying on any proprietary interface.
