Memory and Skills Closed Loop for Self-Improving Agents

    Agents often perform well in a single session, then lose context when it ends. This article explains a closed loop of bounded memory, post-task skill distillation, and review scheduling so reusable facts and procedures persist across sessions without unbounded logs.

    Agents often look competent in a single session. When the session ends, context is wiped. The next similar task starts from scratch: environment conventions must be re-asked, deployment order re-learned, tool quirks retried. For individual developers that is repeated labor. For organizations it means knowledge cannot be reused across people and tasks. The gap is not whether the agent can call tools, but whether it leaves anything reusable after the work is done.

    A learning loop usually splits into three capabilities that are independent yet must work together: memory of facts and preferences, skills that capture operating procedures, and scheduling that compresses and distills at the right time. Missing any one of them means permanent amnesia, an ever-growing handbook, or material that is never reviewed.

    Why unbounded append fails

    An intuitive approach is to append every conversation summary, error log, and verbal user convention into one large note. In the short term the record looks complete. After a few months it becomes a tens-of-thousands-of-lines monster: retrieval is a full read or a crude truncation, stale entries mix with live facts, and model attention is diluted by noise.

    A more stable approach treats memory as a working notebook with a capacity limit, not an archive. Finite capacity forces compression: keep only dense, still-valid facts; outdated items are squeezed out instead of piled at the end of a file. That is similar to a human assistant’s pocket notebook—if it is too thick, it cannot travel, so it must be periodically rewritten as shorter points.

    In practice, memory can also be split by object. One class records environment and engineering facts: runtime, project conventions, differences in tool behavior. Another records a model of the user: communication style, decision preferences, work rhythm. Keeping them separate makes it easier to inject system prompts by role and avoids mixing “this person prefers concise replies” with “this service must push images before rolling out” into unmaintainable prose.

    The character cap need not be an exact magic number; the point is tightness. Too loose is append in disguise. Too tight drops necessary context. A common engineering pattern is: freeze a snapshot into the system prompt at session start, allow the entry list to be written, deleted, or edited during the session, then merge and compress to the cap at the end. That avoids mid-session prompt jitter and gives the next turn a compressed, stable view.

    A schematic structure is two parallel states: a live entry list and an opening snapshot. Implementation can be plain text with clear delimiters between entries; a vector store is not required up front. Vector retrieval fits large document collections; for a few dozen hard constraints that must always be present, it can miss items or rank unstably. Constrained text memory forces the model to choose when it writes.

    Skills: from handwritten manuals to after-the-fact distillation

    Memory answers what is true and what is preferred. Skills answer how this class of work is done and which step is easiest to get wrong. Many agents treat skills as human-written docs: they know only what was written. That is clear at cold start, but it puts all learning cost on people and does not scale.

    Another path is: after a task, the agent distills reusable skills from that trajectory—failure causes, successful order, prerequisites that must be met—into a short handbook that can be invoked next time. The longer it is used, the less similar problems start from zero. That is a different design philosophy: one is fed by humans; the other lets the system grow under constraints.

    Boundaries matter. Automatic distillation without review and deduplication can turn a one-off workaround into a “standard process,” or freeze expired commands. The skill layer typically needs naming and classification, conflict detection against existing skills, expiry, and human confirmation when needed. Memory should be short and factual; skills should be stepwise, executable, and versionable. Do not dump both into one unbounded file.

    For coding and efficiency work, skills are especially valuable. In containerized release, “build and push the image before rolling the workload,” once written as a skill, need not be reconstructed from a long chat. Skills should document failure modes, not only the happy path; otherwise the loop only reinforces surface success.

    Review scheduling: without a trigger, nothing is revisited

    Even with a memory file and a skill catalog, if nothing triggers “think afterward,” the system still drops experience when the session ends. A light scheduler is needed: after success or failure, idle time, or a given number of turns, remind the model to check whether stable facts belong in memory, whether a skill should be captured, and whether stale entries should be deleted.

    This layer should not be a high-frequency background job. Too frequent writes noise into memory and burns quota. It is more reasonable to bind it to the session lifecycle: one compression at the end, and an extra targeted distillation on failed trajectories when needed. Scheduling should be configurable, with an audit log so organizations can track how the system changed its own knowledge.

    The three subsystems form a loop: do work → review → compress into memory or skills → retrieve and invoke next time. Memory supplies lasting context, skills supply transferable procedures, scheduling makes the loop actually run. Without scheduling, the other two layers are static configuration.

    Capacity, safety, and roles at implementation time

    Capacity policy determines quality. Give memory a hard cap and each skill a soft cap (too long means it was not distilled). On write, prefer dropping recoverable detail and keep constraints and preferences. Simple heuristics help: recent hit count, whether the system prompt still cites the item, whether the user explicitly rejected it.

    On safety, automatic writes must resist injection. Untrusted web pages or raw email should not be stored wholesale in long-term memory, or later sessions will be polluted. Distinguish user-confirmed preferences from facts claimed by the outside world; down-rank the latter or require review. Commands and scripts in skills should be sandboxed so a dangerous one-off is not turned into a default callable capability.

    On roles, memory fits personal assistants and long-lived projects; skills fit repeatable engineering and office workflows; scheduling fits resident assistants, not one-shot Q&A. Business users who do not write code need the same loop packaged as a product: they describe tasks in natural language; the system reviews and compresses in the background; the UI exposes remembered preferences and one-click repeatable flows, not file paths and internal module names. In the cloud, memory and skill objects can live in object storage, writes can be audited with logs, and compression failures or over-limit conditions can be monitored—generic capabilities, not a vendor-specific story.

    Difference from an assistant that only calls tools

    Leaderboard ranks change. The transferable difference is whether knowledge still exists after the session, and whether it exists as retrievable facts or as executable skills. Pure append looks loyal and becomes unusable. Pure handwritten skills look controlled and cannot grow with use. Capacity-limited memory, post-hoc distilled skills, and restrained review scheduling together turn “it knows you better over time” from a slogan into an architecture.

    When introducing this to a team, you need not ship everything at once. Start with dual-file memory and cap-based compression, then semi-automatic skill capture on frequent failures (model drafts, humans confirm), then end-of-session review. Each step alone reduces repeated questions and repeated mistakes. The core principle stays: remember what should be remembered, forget what should be forgotten, and turn work already done into a callable capability—not another log nobody will ever finish reading.