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:
Conversation clustering → Execution extraction → Deep understanding (LLM) → SkillsRaw 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:
# AGENT_CORE.md (structure sketch)## 1. Execution flow and rules- Task tiers: query / change / high-risk change- Confirmation points and minimum verification per tier## 2. Skill orchestration- Single-skill tasks: call directly- Multi-skill tasks: serial vs. parallel criteria and how to declare dependencies## 3. Report format- Conclusion first → key changes → verification → open risks## 4. Memory architecture- When each of the four layers writes, and how to deduplicate## 5. Fault tolerance- 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:
Lab → specific: ≥ 3 effective calls in 30 days and human rating “useful”Specific → common: used in ≥ 3 distinct projects and a generalizable interfaceAny layer → lab: N consecutive call failures or overlap with an existing skill
Directory and metadata can stay simple:
skills/base/ # high-frequency, stable; changes need reviewcommon/specific/lab/ # rough implementations allowed; not in default routingskills/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:
User gives P → AI infers not-P (boundary / taboo) → execute and correct → write the table → lookup next time
Minimum record shape:
- id: B-017goal: Batch restructure directoriesforbidden:- Delete original directories without confirmation- Batch writes while uncommittedreason: Previously caused unrecoverable file lossscope: All change-class taskscreated_at: 2026-08-14hits: 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
- Documents before skills. Adding skills without constraints only amplifies uncontrollability.
- Subtract from memory. Before write, ask whether the fact will change the next action; if not, do not store it.
- Layers must be measurable. Promotion and demotion need countable criteria, not gut feel.
- Negative samples matter as much as positive ones. Fuller failure paths make fault tolerance and boundaries more stable.
- 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.
