Building Agents That Learn: A Practical Architecture for Long-Term Capability Growth
This article explains why conventional conversational agents lose all capabilities once a session ends, and how to fix it through three engineering changes: closed-loop learning that turns completed tasks into reusable skill artifacts, layered persistent storage that keeps state alive across sessions, and architectural decoupling of runtime, capability, and memory layers. It includes a three-part skill file structure with a parameterized example, a four-layer state model, consistency and privacy handling, common anti-patterns, and notes on building such systems on Baidu AI Cloud.
1. The Starting Problem: Why Capabilities Reset When the Conversation Ends
An agent that just helped you finish a complex deployment script degrades into a generic assistant the moment the window closes and a new session begins, with no knowledge of the prior context. The user has to restate environment constraints, naming conventions, and retry policies, paying the collaboration cost all over again. This is not a single reasoning failure but a structural trait of mainstream conversational agents: session state is treated as temporary cache and released when the task ends, and model parameters are fixed after training, unable to absorb experience from daily use.
Describing such systems as “stateless calculators” is accurate: inputs determine outputs, and history takes no part in the computation. Overcoming this limit requires changes at three levels at once — how capabilities are accumulated, how state is persisted, and how modules are coupled. Each is covered below, with engineering practices that can actually be implemented.
2. Closed-Loop Learning: Turning One-Off Tasks into Reusable Assets
2.1 Linear Execution vs. Closed-Loop Execution
A traditional pipeline is linear: receive the instruction, plan the steps, call tools, return the result, and terminate once the task succeeds. Closed-loop execution adds a return path at the end: on success, it triggers experience extraction, fixing the path that solved the problem into an externally readable capability file. On the next similar task, the capability library is searched first; a hit is loaded directly, and only a miss falls back to full reasoning.
The key judgment behind this change is that capabilities should not live only in weights, but in external artifacts that are version-controlled, reviewable, and rollback-able. Weight updates have long cycles, are hard to interpret, and are difficult to roll back; file-based skill artifacts can enter a code review process and are naturally traceable.
2.2 The Three-Part Structure of a Skill File
A usable skill file should contain at least three kinds of information, none of which can be omitted:
- Trigger conditions: describe the applicable scenario and preconditions to avoid false matches;
- Execution steps: a sequence of actionable atomic actions, including key decision branches;
- Caveats: known failure modes, environment dependencies, and rollback procedures.
An illustrative structure:
---name: container-image-publishtriggers: ["build and push an image", "release a new version"]vars: [image_name, tag, registry]---1. Verify that all vars are present; ask the user if any are missing2. Build the image with dual tags ({{tag}} and latest)3. Push to {{registry}}/{{image_name}}:{{tag}}4. Verify the remote digest matches; retry three times and alert on failurenotes:- Build time rises significantly when layer cache for large images is invalidated- Confirm quota and credential validity before pushing
2.3 Parameterization and Open Standards
A skill with hard-coded values has very little reuse value. With variable placeholders, one skill can fit different projects, namespaces, and version numbers, substantially raising the reuse rate. Going further, adopting an open skill description convention already used across the industry makes artifacts portable between different agent runtimes, so capabilities are not locked to a single runtime.
2.4 Automatic Optimization of Prompts and Skills, with a Human Gate
Once the skill library grows, the cost of manually tuning prompts exceeds the benefit. Evolutionary-style algorithms already exist in the industry for prompt optimization: an iterative generate-evaluate-select-mutate loop searches for better prompts, and the evaluation objective is expanded from a single accuracy metric to a multi-objective Pareto front (accuracy, step count, cost), balancing effectiveness against overhead. The more pragmatic engineering approach is to evaluate offline on a small regression set first, then roll out gradually.
One constraint must be stressed: automatically optimized output should be submitted as a change proposal and merged only after human review; the optimization process relies on model API calls and lightweight computation, with no need to build a training cluster. Without a human gate, an agent can easily drift away from its original intent during self-iteration, and such drift is very hard to detect over long-running periods.
3. Persistent Storage: Keeping State Alive Across Sessions
3.1 A Layered State Model
Splitting state into four layers is recommended, each matched to a different read/write profile:
| Layer | Content | Characteristics | Common Backing |
|---|---|---|---|
| Working memory | Current session context | High-frequency read/write, volatile | In-process cache |
| User profile | Preferences, habits, taboos | Low-frequency updates, strong consistency | Relational database |
| Skill library | Reusable process artifacts | Versioned, reviewable | Object storage + version control |
| Retrieval index | Historical fragment vectors | Batch writes, approximate search | Vector search service |
3.2 Consistency and Privacy Boundaries
Cross-session memory raises two problems that must be addressed head-on. The first is consistency: after a user changes a preference, the cache and index must be invalidated in sync, otherwise the odd behavior of “old habits overriding new instructions” appears; in practice, write-after-invalidation plus version-number checks work well. The second is privacy and compliance: memory content should support export by category and complete deletion, sensitive fields should be masked before storage, and permission boundaries should follow the least-privilege principle. On the deployment side, this typically relies on general-purpose cloud capabilities — for example, object storage for artifacts, a relational database for profiles, a message queue to decouple asynchronous writes, and logging plus monitoring and alerting services to observe pipeline quality.
4. Architectural Decoupling: Separating Capability, Memory, and Runtime
In a tightly coupled agent, any model swap ripples through all the logic. The goal of decoupling is to let three concerns evolve independently:
- Runtime layer: session orchestration, tool invocation, and permission checks;
- Capability layer: skill artifacts and tool descriptions, pure data, hot-loadable;
- Memory layer: stable read/write interfaces, replaceable storage backends.
User request↓Runtime (orchestration / permissions / rate limiting)├── Memory layer: read profile and historical index├── Capability layer: retrieve and load skill artifacts└── Tool layer: execute controlled actions↓Result returned + success event↓Learning loop: experience extraction → change proposal → human review → merge and activate
The direct payoff is replaceable models, portable skills, and migratable storage, while the evaluation system can also evolve on its own.
5. Implementation Essentials and Common Anti-Patterns
- Skill explosion: apply deduplication and merging policies, and periodically archive low-hit skills;
- Fixating on bad experience: only stably successful tasks may be distilled; failure samples go into a separate analysis set;
- Memory pollution: distinguish “explicitly stated by the user” from “inferred by the model” — the latter must never be written to the long-term profile;
- Missing regression evaluation: run a fixed regression set on every skill or prompt change to prevent capabilities from trading off against each other;
- Out-of-control permissions: high-risk actions in skills require a second confirmation and an audit trail.
6. Conclusion
The move from a passive tool to a growth-oriented digital twin does not depend on a longer context window, but on an engineering system that turns experience into managed artifacts: closed-loop learning produces experience, persistent storage carries it, architectural decoupling keeps it evolving, and human review guards the boundaries of intent. When building such systems on Baidu AI Cloud, you can reuse general-purpose capabilities directly — object storage, relational databases, container platforms, message queues, and monitoring and alerting — and concentrate effort on the two points that truly determine the quality of growth: skill specifications and the evaluation system.
