Agent Memory and Skills Architecture: Layered Memory and Dual-Loop Evolution

    This article covers two common problems after agents move from demos into daily use: memory bloat with forgetting, and unstable behavior. It describes a layered memory design, a pipeline from conversation logs to reusable skills, and a dual loop between memory and skills. It also covers a document-driven control model: a master spec, a skill pyramid with promotion rules, and a decision-boundary table that turns user corrections into lasting constraints.

    1. Background: Two Pain Points After Agents Go Into Production

    Once an agent stack moves from “a working demo” into daily use, two issues show up again and again:

    1. Memory bloat and forgetting at the same time. Longer conversations mean longer context. The model both loses early key facts and is flooded with redundant turns, which increases retrieval noise and lowers response quality.
    2. Uncontrollable behavior. On the same task, the agent sometimes follows a clean procedure and sometimes improvises: format drift, skipped steps, and repeated mistakes.

    These map to two design gaps: memory architecture and constraints on execution. The rest of this article treats them separately.

    2. Memory: From a Single Context Window to Multi-Layer Integration

    2.1 Why layers

    A single context window inevitably dilutes information as a session grows. A common industry pattern is to layer memory by how much it has been distilled:

    • Session layer: raw records of the current conversation; shortest lifetime.
    • Working layer: task state, execution traces, and intermediate conclusions extracted from the conversation.
    • Knowledge layer: stable facts and user preferences that persist across sessions.
    • Skill layer: recurring operation patterns frozen as reusable skill descriptions.

    The first two layers keep the current task from losing information. The last two make the system smoother the longer it is used.

    2.2 Pipeline from conversation logs to skills

    The value of layered memory is not “store more,” but “extract accurately.” A practical pipeline:

    1. cluster conversation logs → extract execution traces → deeper understanding (LLM summary) → freeze as skills

    In more detail:

    1. Cluster: group logs by similar topic or task type so fragments do not stay isolated.
    2. Extract: from each group, pull what was done, what failed, and how it was resolved.
    3. Deeper understanding: have the model generalize those extracts into reusable operating descriptions.
    4. Freeze: write the result into a skill library and invoke it on the next similar task.

    Memory and skills are then not two isolated systems but a dual loop: memory supplies raw material for skills; skills reduce memory pressure. Once frequent operations are skills, raw logs can be archived or dropped. That is how you “store less and remember better”: persist structured knowledge after extraction, not a pile of raw dialogue.

    2.3 Practical notes

    • Trigger extraction at clear moments (task complete, session end), not continuously, so the main flow is not interrupted.
    • Keep an observation window before freezing a skill, so a one-off pattern is not locked in as a bad habit.
    • Retrieve by layer priority: if the skill layer hits, reuse it; otherwise walk down the layers.

    3. Document-Driven Control of Agent Behavior

    Execution quality depends heavily on the top-level spec you give the agent. A solid spec steers it toward intended behavior; a missing spec produces uncontrolled output. A document system is as important as skills themselves.

    A reasonably complete set usually has three parts.

    3.1 Master document (the AGENTS.md role)

    This is the hub that ties the system together. At minimum it should cover:

    • Execution flow and rules: standard task-decomposition steps and I/O contracts per step.
    • Skill orchestration: when to call a skill, how skills chain, and which wins on conflict.
    • Reporting format: fixed templates for intermediate and final results so output is readable and checkable.
    • Memory architecture: read/write rules for each memory layer.
    • Fault handling: retry policy, fallback paths, and how failures are reported.

    The core value is determinism: pin down the behavior you want fixed, and explicitly mark what is allowed to stay flexible.

    3.2 Skill pyramid

    Skills should not be a flat list. Rank them by call frequency and value into a pyramid. One reference mix:

    • Base (~55%): high-frequency, stable skills such as file ops, command execution, and web access.
    • General (~30%): cross-project abilities such as debugging, planning, and code review.
    • Specialized (~15%): scenario-specific skills such as ML hyperparameter tuning or design-oriented operations.
    • Experimental (~5%): new and draft skills still on trial.

    The pyramid is a dynamic view, not a static tag. Promotion rules matter, for example:

    1. Experimental → Specialized: used 3+ times in 30 days with good outcomes
    2. Specialized → General: validated on 3 different projects and generalizable

    With promotion, the library can select winners: unused skills sink or drop out; proven skills rise. The store does not grow without bound, and retrieval stays faster.

    3.3 Decision-boundary table: automate error correction

    The most painful failure is stepping in the same pit repeatedly. Pair opposing concepts in a growing decision-boundary table:

    1. user preference P (what they want)
    2. → infer boundary not-P (what they do not want)
    3. → write the pair
    4. → later tasks look up the table and avoid the boundary

    Design points:

    1. Paired records: P and not-P are semantic opposites; there is no “correct vs incorrect,” only a boundary.
    2. Reverse lookup: if a later preference is already the table’s not-P, match in reverse; do not add a row, so the table does not grow without limit.
    3. Automatic capture: when the user corrects the agent, the agent summarizes and updates the table so the same mistake is avoided next time.

    The table is accumulated decision boundaries: one correction, lasting effect—one of the highest-ROI mechanisms for long-term use.

    4. Summary

    Agent maturity is not a single impressive turn. It is three long-horizon capabilities: efficient memory distillation (layered memory + extraction pipeline), stable, controllable behavior (master document + output contracts), and errors that converge automatically (skill pyramid + decision-boundary table). Together they form a dual-loop memory + skills system. None of this depends on a specific framework. Whatever runtime you use, you can build the same spec and memory structure so the agent actually gets better the more you use it.