Layered Memory and Skills Design for AI Agents

    A practical look at evolving agents from add-on components to primary executors, then integrating four-layer memory, core constraint docs, a skills pyramid, and a decision-boundary table so long-horizon tasks stay constrained, reusable, and stable.

    Architecture: from add-on to primary executor

    Many teams first attach an agent under an existing coding tool or workflow engine. The host owns scheduling and interaction; the agent is a callable component. That “primary–secondary” split is reasonable for a proof of concept: cheap to wire up and fast to close the loop.

    As execution chains lengthen and task types grow, the limits show quickly:

    • Unclear context ownership. Host and agent each keep session state, so context is injected twice and instructions overwrite each other.
    • Blurred capability boundaries. The same job could be done by either side, so routing becomes guesswork.
    • Memory that never settles. Results scatter across both systems and cannot be structured or fed back into later decisions.

    Once the execution architecture itself can plan, call tools, and self-check, it is a natural next step to promote the agent to primary executor and treat the original framework as an optional external tool. The payoff of that role reversal is a single place for constraints: rules, memory, and skills live in one set of documents and directories, with no semantic alignment between two systems.

    Memory: from three layers to four

    Native memory is often three layers: raw session retention, summary compression, and vector recall. That covers “store it and find it,” not “use it.” A local memory plugin can extend this into a four-stage pipeline:

    1. Conversation clustering → Execution extraction → Deep understanding (LLM) → Skills
    2. Raw layer Structure layer Semantic layer Behavior layer

    Roles and failure modes:

    Layer Input Output Common issues
    Conversation clustering Full sessions Topic clusters, timelines Cluster granularity out of control; noise piles up
    Execution extraction Operation sequences in a cluster Steps, tools, results, failure points Conclusions stored without the path
    Deep understanding Structured extraction Intent, constraints, preferences, boundaries Over-generalization into wrong rules
    Skills Repeatedly validated understanding Reusable skills and call conventions Skill bloat and overlapping duties

    The real gain is not the plugin itself but connecting the memory layers to core constraint documents. Semantic “understanding” is no longer only a retrieval snippet; it is written into docs as hard constraints for the next run. That creates a dual loop of memory and skills:

    • Memory → skills. Repeated successful paths become skills, cutting repeated reasoning cost.
    • Skills → memory. Skill outcomes and deviations flow back into the semantic layer and keep correcting understanding.

    The closed loop aims at remember less, remember firmly: not full retention, only information that will change the next action.

    Core documents first: constraints before skills

    A counterintuitive but important point: at the execution-architecture level, a solid core document matters more than creating skills. Skills are capability increments; documents are behavioral boundaries. Without boundaries, more capability means further drift.

    The core document should cover at least five sections:

    1. # AGENT_CORE.md (structure sketch)
    2. ## 1. Execution flow and rules
    3. - Task tiers: query / change / high-risk change
    4. - Confirmation points and minimum verification per tier
    5. ## 2. Skill orchestration
    6. - Single-skill tasks: call directly
    7. - Multi-skill tasks: serial vs. parallel criteria and how to declare dependencies
    8. ## 3. Report format
    9. - Conclusion first → key changes → verification → open risks
    10. ## 4. Memory architecture
    11. - When each of the four layers writes, and how to deduplicate
    12. ## 5. Fault tolerance
    13. - Retry caps, rollback triggers, degradation paths

    Fault tolerance is the piece most often skipped. Without it, the agent retries the same failing action. With explicit retry limits and rollback conditions, a failure becomes a recorded negative sample and enters the decision-boundary table.

    Skills pyramid: dynamic layers by frequency and value

    As skill count grows, retrieval and selection cost can exceed the benefit. Layer by call frequency and value:

    Layer Share Examples Usage
    Base ~55% File ops, terminal, web access High-frequency, stable
    Common ~30% Debug, planning, code review Frequent
    Specific ~15% ML pipelines, creative design, repo collaboration Scenario-specific
    Lab ~5% New or draft skills Experimental

    The pyramid is a dynamic analysis view, not a static label. The same skill can sit at different levels in different projects, so promotion and demotion must be decidable:

    1. Lab → specific: ≥ 3 effective calls in 30 days and human rating “useful”
    2. Specific → common: used in ≥ 3 distinct projects and a generalizable interface
    3. Any layer → lab: N consecutive call failures or overlap with an existing skill

    Directory and metadata can stay simple:

    1. skills/
    2. base/ # high-frequency, stable; changes need review
    3. common/
    4. specific/
    5. lab/ # rough implementations allowed; not in default routing
    6. skills/lab/xxx/SKILL.md # purpose, I/O, failure log, call count

    Skills that drop into base are managed assets: interface changes need review so experimental edits do not break high-frequency paths.

    Decision-boundary table: corrections as constraints

    The user gives a goal P; the agent must infer “not P”—what not to do and where the boundary is. That inference happens every time and should not start from zero. The decision-boundary table records it:

    1. User gives P → AI infers not-P (boundary / taboo) → execute and correct → write the table → lookup next time

    Minimum record shape:

    1. - id: B-017
    2. goal: Batch restructure directories
    3. forbidden:
    4. - Delete original directories without confirmation
    5. - Batch writes while uncommitted
    6. reason: Previously caused unrecoverable file loss
    7. scope: All change-class tasks
    8. created_at: 2026-08-14
    9. hits: 6

    This is not doctrine; it is a growing log of decision boundaries. Each user correction is summarized as a forbidden item and hit count. High-hit, general entries should rise into the core document as hard rules. Long-unhit entries can be archived so the table does not become a new noise source.

    Practice notes and common mistakes

    1. Documents before skills. Adding skills without constraints only amplifies uncontrollability.
    2. Subtract from memory. Before write, ask whether the fact will change the next action; if not, do not store it.
    3. Layers must be measurable. Promotion and demotion need countable criteria, not gut feel.
    4. Negative samples matter as much as positive ones. Fuller failure paths make fault tolerance and boundaries more stable.
    5. Periodic recycle. Lab skills and the boundary table both need archival so the structure does not rot.

    The core is not a plugin or framework but three engineering principles: constraints before capability, memory in service of behavior change, and layers that stay dynamically decidable. With all three, an agent on long-horizon work can remember less, remember firmly, and run stably.