Optimizing Agent Architecture: Reconstructing Memory and Core Documents
This article describes how LLM agent systems can move from generic orchestration frameworks to self-controlled execution by rebuilding memory into a four-layer pipeline that distills experience into skills, and by using core documents (AGENTS.md, SKILLSPYRAMID.md, YINYANG.md) as explicit process, skill-layer, and decision-boundary constraints.
When building large language model agents, teams often start with off-the-shelf tools or orchestration frameworks to stand up a prototype quickly. As scenarios grow more complex, those native execution architectures often cannot support fine-grained control. Drawing on practical architecture evolution, this article examines how a deep reconstruction of the memory system and core documents can produce a logically consistent, reliable agent architecture.
Architecture evolution: from external dependency to autonomous control
Early agent setups commonly pair a core scheduling framework with helper components. The core owns overall logic; helper agents are invoked only as specialized modules. Roles are clear, but flexibility is limited. As stability requirements rose, we stripped dependence on an external core framework and made the agent itself the center of the execution architecture.
Two changes were decisive: a memory system that can iterate and accumulate, and a strict core-document system that constrains and guides behavior.
Memory reconstruction: a dual loop of memory and skills
Memory determines whether an agent stays consistent and can improve across long, multi-turn work. Native memory is often a three-layer stack; in practice that leads to storing a lot and using little well. By integrating a general local memory plugin, we extended memory to four layers and redefined the processing flow.
Four-layer architecture and processing flow
The four-layer system is not stacked text. It is a pipeline: cluster conversation records → distill execution process → deep understanding (LLM) → convert to skills.
- Conversation clustering: Vectorize fragmented history, cluster by topic, and drop redundancy.
- Execution distillation: From clustered records, extract key paths, successes, and failures.
- Deep understanding: Use a large model to generalize those experiences into reusable patterns.
- Skills conversion: Freeze the result as executable skills or operating paradigms.
Memory–skill dual loop
This flow yields a dual loop of memory plus skills. Memory is no longer a static log; it is a source that can become skills. On new problems the agent retrieves memory and also writes successful paths back as new skills. The aim is to remember less but remember well: raw dialogue is not kept; only high-value patterns and skills remain.
Core documents: the foundation of the execution architecture
If memory is the agent’s “subconscious,” core documents are its “conscious” rules. Teams often over-index on scripts and skill files and under-build documents. At the architecture layer, writing core documents matters more than adding skills. Weak constraints produce hallucination or drift; tight constraints produce precise execution.
AGENTS.md: central control and process constraints
AGENTS.md is the hub of runtime logic—the system “constitution.” It should define:
- Execution flow and rules: A standard SOP from task intake to output, including a think–act–observe loop.
- Skill orchestration: Trigger conditions, call order, and conflict arbitration.
- Reporting format: Strict JSON or text structure so downstream systems can parse results.
- Memory architecture: How memory layers are laid out and how they are read and written.
- Fault tolerance: Fallback and retry when tools fail or the environment misbehaves.
SKILLSPYRAMID.md: a dynamic skill pyramid
Skills should not be a flat list. We layer them by call frequency and value:
- Base (55%): File operations, terminal commands, web access—daily capabilities that must be highly stable.
- General (30%): Debugging, planning, code review—cross-project work that needs reasoning.
- Specialized (15%): ML data handling, creative design, operations on a specific codebase—used in particular scenes.
- Experimental (5%): New or draft skills for trial and exploration.
Promotion rules keep the library from freezing:
- Experimental → specialized: called more than three times in 30 days and confirmed usable by human review.
- Specialized → general: successfully reused in more than three different project types, with potential to be parameterized.
The pyramid keeps the base solid and leaves room at the top for innovation.
YINYANG.md: dynamic decision boundaries from set thinking
Rules cannot enumerate every case. Using a set-theoretic idea, we keep a growing table of decision boundaries (a “yin-yang table”).
The idea: the user states intent P (what they want) → the agent infers not-P (what to avoid / the boundary) → write it to the table → later queries resolve immediately.
- Not static dogma: The table is a growing record, not preset philosophy. P and not-P are semantic opposites, not absolute good and bad.
- Reverse lookup: If a user later prefers the former not-P, the corresponding P is demoted to the new not-P. No extra rows; state is inverted.
After each correction the agent summarizes the boundary into the table and avoids the same error next time—self-evolution in practice.
Conclusion
Whether an agent is merely usable or actually good depends less on stacking tools than on whether the execution architecture is internally consistent and able to evolve. A four-layer memory–skill dual loop lets the agent accumulate experience. Documents centered on AGENTS.md, SKILLSPYRAMID.md, and YINYANG.md give clear, dynamic growth boundaries. Reconstructing from this layer is the path from “it works” to “it works well.”
