Persistent Memory and Multi-Agent Collaboration in Agent Frameworks

    This article breaks down three capabilities that turn a stateless chatbot into a working agent system: persistent memory, a reusable skill system, and multi-role collaboration. It explains layered memory design (working, episodic, semantic, and procedural), how to decide what to write to memory and how to retrieve, deduplicate, and resolve conflicts between entries, how to define and govern skill packages, and how to structure roles, collaboration topologies, shared context, and termination conditions. It closes with engineering practices for stability, observability, cost control, least privilege, and evaluation, plus common pitfalls and guidance on which capability to build first.

    1. Introduction: The Shift from “Holding a Conversation” to “Getting Work Done”

    Early AI coding tools mostly operated in a one-question-one-answer mode: the user described a requirement, and the model returned a snippet of code or an explanation. The fatal flaw of this interaction is that it is stateless—every session is an island, and once the context window overflows or the process restarts, all prior agreements, preferences, and project knowledge reset to zero. The industry has therefore converged on a shared conclusion: a genuinely usable agent framework must close the gaps in three dimensions.

    1. Persistent memory: retain user preferences and project facts across sessions and processes;
    2. A skill system: turn domain knowledge from ad-hoc prompts into reusable, versionable capability packages;
    3. Multi-role collaboration: let multiple agent instances with different responsibilities and constraints divide and coordinate work on the same task.

    These three capabilities are not independent; they form a closed loop: memory supplies the factual foundation, skills supply the methodology, and multi-role collaboration supplies the organizational form. This article breaks down the design points and engineering implementation of each in turn.

    2. Persistent Memory: Keeping an Agent from “Losing Its Mind When Powered Off”

    2.1 Why Memory Needs Layers

    Stuffing all historical conversation into the context is neither economical nor reliable. The layered structure commonly adopted in the industry is:

    • Working memory: the short-term context of the current session, released when the session ends;
    • Episodic memory: records tasks, decisions, and outcomes as discrete “events,” retrievable by time;
    • Semantic memory: abstracted, stable facts, such as the project’s tech stack, coding conventions, and API contracts;
    • Procedural memory: executable sequences of operations and preference policies, such as “always run formatting and static checks before committing.”

    The value of layering is that write and retrieval strategies can differ per layer: working memory pursues low latency, semantic memory pursues high accuracy and low redundancy, and episodic memory must strike a balance between preserving detail and controlling size.

    2.2 Writing to Memory: Not Everything Should Be Remembered

    The most common failure mode in practice is “memory pollution”—writing one-off temporary information as a long-term fact. A recommended decision order:

    1. if information has cross-session reuse value and is stated stably:
    2. write to semantic memory
    3. elif information describes the process and result of one specific task:
    4. write to episodic memory (with timestamp and task identifier)
    5. elif information is only valid in the current session:
    6. keep in working memory
    7. else:
    8. discard

    Memory entries must also carry source, confidence, and invalidation conditions. For example, information like “uses a specific runtime version” should carry a timestamp so that stale facts do not mislead later decisions over the long term.

    2.3 Retrieving and Updating Memory

    Retrieval typically uses a hybrid strategy of “vector similarity plus structured filtering”: first narrow the scope with keywords or tags, then run semantic ranking within the candidate set, and finally re-rank by confidence and freshness. Updates require two mechanisms:

    • Deduplication and merging: consolidate semantically equivalent entries, keeping the most informative phrasing;
    • Conflict resolution: when a new fact contradicts an old one, decide whether to overwrite, keep both, or mark as pending confirmation based on source credibility and recency.

    For persistence, general-purpose cloud capabilities can carry the load: object storage holds memory snapshots and skill package archives, a logging service records the audit trail of memory reads and writes, and monitoring and alerting set thresholds for memory size growth and retrieval failure rates. That way, even if a compute instance restarts, memory can still be restored from the persistence layer.

    3. Skill System: Turning Domain Knowledge into Reusable Assets

    3.1 The Abstraction Boundary of a Skill

    A well-designed skill package should contain four parts: applicability description, prerequisites, execution steps, and acceptance criteria. The “applicability description” is especially critical, because it determines whether the scheduler can select the skill at the right moment; too broad a description causes false triggers, while too narrow one means it never matches.

    An illustrative skill declaration:

    1. skill:
    2. name: db-migration-review
    3. when: "database schema changes targeting the production environment"
    4. requires: ["schema-diff", "rollback-plan"]
    5. steps:
    6. - generate a before/after schema diff
    7. - verify the rollback script is executable
    8. - output a risk list and canary rollout recommendations
    9. acceptance: "the risk list covers all destructive changes"

    3.2 Skill Curation and Governance

    Skill packages need to be governed like code: semantic versioning, changelogs, review processes, and regression cases. It is recommended to keep the skill repository separate from the business code repository and reference skills by version number, avoiding uncontrolled behavior drift when a skill is upgraded. For high-risk skills, add a “requires human confirmation” gate that keeps the final decision on the human side.

    3.3 How Skills and Memory Relate

    Memory answers “what are the facts of this project,” while skills answer “how should this class of problem be handled.” Only combining the two avoids two extremes: memory alone turns the agent into a reference library that just follows the material at hand; skills alone turn it into a general-purpose tool that lacks project context. In practice, a skill can read from and write to memory before and after execution, forming a positive cycle of “execute—capture—reuse.”

    4. Multi-Role Collaboration: From a Monolithic Agent to Orchestrated Organization

    4.1 Principles for Dividing Roles

    More roles is not better. Effective division is usually based on orthogonal responsibilities plus different constraints: for example, a planner focuses on goal decomposition and prioritization, an implementer on runnable code, a reviewer on conventions and security, and a verifier on test coverage and regression results. Each role has its own prompt constraints, subset of available skills, and output format, which reduces mutual interference.

    4.2 Collaboration Topologies

    Three common topologies:

    • Serial pipeline: plan → implement → review → verify; simple structure and easy to trace;
    • Central dispatch: one coordinator distributes tasks and aggregates results, suited to scenarios with clear task boundaries;
    • Peer negotiation: multiple roles discuss a proposal over several rounds before converging; suited to design trade-off problems, but costly and requiring strong constraints to prevent divergence.

    4.3 Context Isolation and Sharing

    The hardest part of collaboration is not the division of labor but how information flows between roles. If all roles share the full history, the context swells quickly and cross-contaminates; if it is fully isolated, duplicated work results. The compromise is a shared “task blackboard” that holds only structured conclusions (decisions, API contracts, to-dos, blockers), while raw process stays in each role’s private context and is retrieved on demand.

    4.4 Conflict and Termination Conditions

    Arbitration rules and termination conditions must be defined in advance, for example: when the reviewer and the implementer disagree, the acceptance criteria prevail; if two consecutive rounds produce no new conclusions, force convergence; if the cumulative cost of a single task exceeds a threshold, abort and escalate. Multi-role systems lacking these constraints often end up “lively discussion, zero delivery.”

    5. Engineering Implementation: Stability, Observability, and Cost Control

    1. Separate state from compute: externalize session state, memory, and skill packages to the persistence layer, and keep compute instances stateless for easier elastic scaling and failure recovery.
    2. End-to-end observability: for every role invocation, record an input summary, skill matches, elapsed time, and result status to form a traceable call chain; use the logging service and monitoring alerts to locate anomalies.
    3. Asynchrony and decoupling: move time-consuming validation and build tasks to a message queue so long-running work does not block the main path.
    4. Cost guardrails: set budget caps and degradation policies per session, per task, and per role; on exceeding a cap, switch to a simpler flow or hand off to a human.
    5. Least privilege: a role can only access the code directories, data scope, and skill subset its responsibility requires; write and release operations need explicit authorization.
    6. Evaluation loop: maintain a fixed task set and regression baseline, and automatically compare pass rate and elapsed time after any skill or prompt change to prevent capability regression.

    6. Common Pitfalls and Selection Guidance

    • Pitfall 1: treating long context as memory. Context length is a capacity problem; memory is a governance problem. The two cannot substitute for each other.
    • Pitfall 2: the finer the skill packages, the better. Overly fine granularity creates scheduling ambiguity and maintenance overhead; the minimum unit should be “independently acceptable.”
    • Pitfall 3: more roles means more intelligence. Adding roles raises coordination cost exponentially; get the serial pipeline working first, then evolve step by step.
    • Selection guidance: if the team’s pain point is repeatedly explaining project background, build semantic memory first; if the pain point is groping through the same class of task again and again, build the skill library first; only if a single role cannot cover everything should you introduce multi-role orchestration. For the implementation path, you can rely on Baidu AI Cloud’s container platform to host stateless compute, object storage to hold memory and skill assets, a message queue for task decoupling, and the logging and monitoring system for observability—using a combination of general-purpose cloud products to support a complete agent engineering system.

    7. Conclusion

    Persistent memory solves “remembering,” the skill system solves “doing it right,” and multi-role collaboration solves “working together.” Only when the three stack up does an agent move from a demonstration tool to sustainable, production-grade infrastructure. The real difficulty lies not in the concepts but in seemingly plain engineering details—memory governance, skill version management, and collaboration constraints—which determine whether the system can run stably over the long term in real projects.