AI Agent Memory and Skill Self-Evolution: Making Agents Understand You Better Over Time
This article explains how to build AI agents that retain context across sessions instead of resetting to a stranger state after every conversation. It covers a three-layer memory model (facts, preferences, workflows), active memory curation driven by periodic nudges with a four-field entry schema and conflict detection, automatic skill capture from completed multi-step tasks, versioned skill iteration with guardrails and rollback, confidence-based user profiling segmented by task type, and engineering practices such as layered storage, retrieval over full injection, memory pollution protection, privacy compliance, observability metrics, and cold-start handling.
1. The Problem: Why “More Usage” Doesn’t Mean “Better Understanding”
Most agents revert to a “stranger” state after the second turn of a conversation: the context window is cleared, and the preferences summarized in the previous turn, the output formats you settled on, and the workflows that already ran successfully are all lost. Users are forced to repeat the same background over and over, and the experience decays linearly. What really determines long-term experience is not single-turn reasoning ability, but the ability to carry state across sessions. This can be broken into three layers: the fact layer (who the user is, what the project constraints are), the preference layer (answer length, tone, technology stack tendencies), and the workflow layer (the standard sequence of actions for a given class of task). If these three layers rely only on stacking raw conversation history, they are quickly drowned out by noise. An active curation mechanism is therefore required rather than passive storage.
2. Memory Management: From Passive Caching to Active Curation
The passive approach stuffs the entire history into the context. The result is high cost, inaccurate recall, and contradictory information coexisting at the same time. The key to active curation is turning “writing memory” into an action driven by the system’s own cadence, rather than waiting for the user to speak.
Periodic nudges are a common implementation: every few turns, the system inserts an internal prompt asking the agent to review recent interactions, extract entries worth keeping long-term, and deduplicate, merge, and discard outdated content. The interval is usually configured by turn count, for example triggering once every 10 turns by default. Too short an interval writes a large amount of low-value fragments; too long an interval leaves early critical information uncaptured before it is evicted from the window.
An actionable memory entry should contain four fields:
{"key": "output_preference","value": "Keep answers under 200 words by default; lead with the conclusion when expansion is needed","confidence": 0.72,"updated_at": "2026-08-11T09:15:00Z","source_turns": [12, 13, 27]}
confidence expresses uncertainty, and source_turns preserves traceable sources, making later correction and conflict resolution easier. Conflict detection is needed before writing: when a new value for the same key is semantically the opposite of the old one, do not overwrite it directly. Instead, lower the confidence of the old value and record a timeline, so subsequent behavior shows “gradual adjustment” rather than an abrupt reversal.
3. Automatic Skill Capture: Turning Proven Workflows into Reusable Assets
After an agent completes a multi-step complex task, the most valuable output is not the answer but the process. The approach to creating skills automatically is to trigger a self-review at the task’s closing stage, writing the goal, preconditions, step sequence, failure branches, and verification method into a structured document that similar future tasks can load directly.
skill: batch_log_triagetrigger: Need to group logs by error code and locate anomalous time windowssteps:- Pull logs for the specified time window- Aggregate by error code and take the Top N- Sample 20 raw records from the Top 1- Output conclusions and suspicious change pointsguards:- Run in batches when the time window exceeds 7 days- Explicitly state sample bias when fewer than 20 records are sampled
This mechanism is especially friendly to newcomers: users do not need to learn skill authoring conventions in advance. They only need to describe their needs as usual, and recurring patterns are automatically abstracted into skills. Common signals for judging whether something is worth capturing include: the task has been triggered multiple times, the step structure is stable, and the number of manual interventions is low. Conversely, one-off exploratory tasks should not be written into the skill library, or retrieval hit rates will be diluted.
4. Skill Iteration: Optimize During Execution, Not Idle in Documentation
A skill is not a static file frozen once written. The ideal state is that when executing a similar task, if a shorter path or a higher-success-rate approach is found, the revision is written back and the reason for the change is recorded. From an engineering standpoint, it is advisable to keep versioning and rollback capability so that a single bad optimization does not pollute all subsequent executions.
skill_version: v3change: Switched serial pulling to hourly parallelism; lowered the timeout threshold from 30s to 10sreason: 4 of the last 5 executions timed out at step 3rollback_to: v2
Guardrails are needed: a single revision may change only one dimension; two consecutive execution failures trigger an automatic rollback; and manual confirmation for critical skills cannot be skipped. This way, “practice makes perfect” becomes a controllable convergence process rather than unexplainable drift.
5. User Profiling: Progressive, Dialectical Understanding Instead of Fixed Labels
A user says “make the answer shorter,” then later says “this time it was too short.” The mechanical approach is to overwrite the label, and the result is behavior oscillating back and forth between the two extremes. A more reasonable approach is to model preferences as continuous values with confidence, stored in separate domains by task type: code tasks prefer complete runnable examples, while conclusion-style Q&A prefers concise summaries. Each piece of feedback makes only a small adjustment, while the context of the most recent several feedback items is retained, so the system can recognize “an exception is needed in a certain scenario.”
preference[code_task].verbosity = 0.8 # prefers detailpreference[quick_qa].verbosity = 0.2 # prefers brevitylast_feedback: "The architecture conclusion last time was too short and lacked tradeoff explanations"
6. Engineering Implementation and Common Pitfalls
- Layered storage: keep hot data in a session-level cache, persist long-term entries in durable storage, and put skill documents under version control for auditing and rollback.
- Retrieval over full injection: recall a small number of highly relevant entries based on the current task’s semantics to control context growth.
- Memory pollution protection: distinguish “explicit user instructions” from “model self-inference”; the latter must carry low confidence and be removable.
- Privacy and compliance: desensitize sensitive information before storing it, and provide entry points to view, export, and delete; deletion must cascade to derived skills.
- Observability: record memory hit rate, skill reuse rate, and revision rollback rate, and judge “whether it really understands you better” with metrics rather than feelings.
- Cold-start strategy: use explicit questions in the first few turns to fill in key facts, avoiding premature profile固化 when information is insufficient.
7. Conclusion
“Understanding you better over time” is not a side effect of model parameters, but the product of three engineering capabilities: actively curated memory, skills that can be captured and iterated automatically, and confidence-based progressive profiling. With the general-purpose capabilities of cloud platforms such as Baidu AI Cloud, durable storage, message queues, logging services, and monitoring alerts can be combined into this closed loop, and whether the loop is effective is ultimately determined by quantifiable metrics such as hit rate and rollback rate.
