AI Agent Memory and Self-Evolution in Practice: Why Deterministic Tools Still Matter
This article examines why poor memory is a core pain point for long-running AI agents and argues that memory and skill self-evolution are necessary but not sufficient on their own. It breaks down how high cost and low stability often share the same root cause, presents a three-layer memory design (short-term, long-term, and skill memory) with state externalization, and shows how to build a controlled pipeline for distilling successful paths and structuring failure cases. It then explains a deterministic-tool-first approach with verification loops and retry budgets, plus the observability signals and generic cloud capabilities needed to keep resource cost and runtime stability under control.
1. The Problem: Why “Poor Memory” Is a Core Pain Point for Agents
AI agents with persistent memory and self-iteration capabilities have recently drawn a lot of attention, along with debates about whether the previous generation of approaches will be replaced. Strip away the hype and the real question is a general engineering one: in multi-turn, long-horizon tasks, how does an agent turn a “one-off conversation” into an accumulating asset of experience?
A conventional agent behaves like a temporary colleague who has to re-align on requirements every day: a workflow confirmed in the previous round has to be restated in the next, and a query procedure demonstrated moments ago resets to zero in a new session window. This “getting to know the world from scratch every time” mode causes three typical kinds of loss.
- Repeated effort: preconditions, constraints, and caveats for a complex task must be explained over and over, equivalent to onboarding a new hire hundreds of times.
- Ballooning inference cost: context fills up with repeated instructions and repeated corrections, so the model has to re-reason and re-trial-and-error, and the resource bill goes up accordingly.
- Non-reproducible results: the same task runs today but stalls on some inexplicable step tomorrow; with no explainable intermediate state, debugging is guesswork.
So a natural question arises: if a new approach is all about “remembering and self-learning,” does that mean the old paradigm should be retired? The conclusion here is that memory and skill self-evolution are necessary, but they cannot solve the stability problem on their own; they must be advanced together with deterministic rework at the tool layer and the state layer.
2. Breaking Down the Problem: High Cost and Low Stability Often Share a Root Cause
Complaints about long-running agents are highly concentrated: resource consumption is high, and long runs tend to break, disconnect, or crash. On the surface these are two problems, but breaking them down shows they usually come from the same root cause — the agent is using low-quality, fragile tools to do work that should be done by deterministic tools.
The most typical case is browser and UI automation. Many systems look smart, but in practice a lot of time is spent in a loop of “observe the page — guess the state — click — discover the failure — replan — try again.” Every iteration stuffs the page structure, the goal description, and the history of attempts into the context, which produces two consequences at once: the context keeps growing (cost rises), and the longer the chain, the more easily it breaks (stability drops).
This can be abstracted as a pair of inequalities:
total cost ≈ cost per inference × number of loops × number of retry roundsstability ≈ 1 / (number of uncertain steps involved)
To improve both ends at once, the only effective direction is to reduce the number of uncertain steps, rather than simply enlarging the context window or swapping in a “smarter” model.
3. Layered Memory Design: Moving Experience Out of the Context
A reliable memory system is usually split into three layers, each solving a different problem; they should not be conflated.
- Short-term memory (within a session): holds the current task’s goal, completed steps, and items awaiting confirmation. It should be compressed into structured state, not the raw full conversation transcript.
- Long-term memory (across sessions): holds user preferences, environment constraints, and domain knowledge. A typical form is a set of tagged entries supporting retrieval by similarity and recency.
- Skill memory (executable assets): turns verified successful paths into reusable capabilities, including input/output contracts, precondition checks, and failure fallback strategies.
A minimal example of externalized state:
{"task_id": "T-1024","goal": "Export an aggregated report for a specified time range","constraints": ["do not use privilege-escalation commands", "read-only account only"],"done": ["connect to data source", "validate fields"],"next": ["run aggregation", "persist and verify row count"],"retries": 0}
The key principle: the context holds only the “minimal summary needed for decisions,” while details sink into external storage (object storage, a logging service, or an ordinary database) and are retrieved and backfilled when needed. This both shortens the input and lets a task resume from its checkpoint after an interruption.
4. Skill Distillation and Self-Evolution: Learning from Both Success and Failure
Self-evolution does not mean letting the model freely rewrite its own logic; it means establishing a controlled pipeline for writing experience back:
- Solidify successful paths: when a class of task passes validation stably several times in a row, abstract it into a parameterized capability unit with a description of its applicable conditions.
- Structure failure experience: record the failure symptom, triggering conditions, root-cause conclusion, and avoidance method, forming a searchable “counter-example library” that keeps the same class of error from recurring.
- Versioning and rollback: skill entries need version numbers and hit-rate statistics so that a regression can be rolled back quickly, preventing “getting worse the more it learns.”
- Human confirmation gate: operations involving permissions, data writes, or irreversible actions must pass explicit confirmation and cannot be released by the self-evolution flow on its own.
A sample skill entry structure:
skill: export_aggregate_reportversion: 1.3preconditions:- readonly_credential- time_range_validsteps: [connect, validate_schema, aggregate, verify_rows, persist]fallback: retry_with_smaller_rangesuccess_rate: 0.97
The point to stress: memory solves “no need to explain again,” and skills solve “no need to grope around again,” but neither can repair an execution channel that is fundamentally unreliable.
5. Deterministic Tools First: Caging the Uncertainty
The most effective engineering optimization is to make the agent do as little “looking and guessing” as possible and as much “calling and verifying” as possible.
- Prefer structured interfaces over UI operations: if something can be done through a query API, a wrapped command line, or a standard protocol, do not make the model simulate clicks.
- Provide deterministic wrappers for high-risk actions: wrap privilege escalation, deletion, and bulk writes as capability units with complete parameter validation and predictable results.
- Introduce a verification loop: define a verifiable success criterion for every step (row count, checksum, status code) and short-circuit immediately on failure instead of piling on more attempts.
- Cap the loop budget: set an upper bound on retry rounds and total duration per task; when exceeded, emit the intermediate state and request human intervention.
The corresponding control logic can be simple:
MAX_RETRY = 2for attempt in range(MAX_RETRY + 1):result = tool.call(params) # deterministic toolif result.verify(): # explicit success criterionmemory.write_skill(params) # distill only on successbreakif attempt == MAX_RETRY:state.dump(result.partial) # persist intermediate state for recoveryraise TaskBudgetExceeded(result.reason)
6. Observability and Cost Control
Long-running systems must be observable; otherwise stability is a matter of guesswork. At minimum, cover four classes of signals: task state and checkpoints, latency and result of each tool call, context length and retrieval hit rate, and the distribution of failure clusters. These signals locate the source of cost: if the overhead concentrates in repeated retries of a few steps, the problem is at the tool layer; if it concentrates in long context injection every round, the problem is in the memory retrieval strategy.
For cloud deployment, you can compose generic capability categories: a container platform to host the runtime, object storage for intermediate artifacts and skill entries, a message queue for task decoupling and replay, and logging plus monitoring and alerting for tracing and threshold notifications. Baidu AI Cloud offers corresponding product categories for these generic capabilities, and you can select based on your own architecture without being locked to a specific implementation.
7. Conclusion
“Missing memory” is indeed the most visible pain point for long-running agents, but betting everything on self-evolution is a misjudgment. The safer route walks on three legs at once: use layered memory to move experience out of the context, use skill distillation to turn successful paths and failure lessons into versionable assets, and use deterministic tools plus verification loops to compress uncertain steps. Only stacked together can they pull both the resource bill and runtime stability back into a controllable range.
