Self-Evolving AI Agent Architecture with Growth-Oriented Memory

    This article breaks down the architecture of self-evolving AI agents that keep improving across sessions. It explains why the industry is shifting from tool integration to a learning loop, then walks through four core layers: a persistent execution engine that runs outside an interactive terminal, a learning loop that turns execution traces into verifiable knowledge entries, layered user modeling that separates global rules from personal preferences, and a low-friction messaging channel for real collaboration. It also covers how these agents divide work with existing coding tools, what enterprises need for stability, security, and cost control, and the four metrics that indicate whether a persistent agent is mature.

    1. From Tool Calling to Continuous Growth: The Agent Paradigm Shift

    Over the past two years, most agent implementations focused on a single question: can the tools be wired up correctly? Reading files, executing commands, retrieving documents, calling APIs. But once these systems reach production, a harder problem appears: the agent acts like it is on its first day of work every single time. The session ends, the context is cleared; the configuration stays the same, and so does the behavior; a preference the user corrected once has to be explained all over again.

    As a result, the industry is shifting attention from stacking capabilities to closing the learning loop. A growth-oriented agent needs to satisfy at least four conditions:

    • A stable execution engine that can run in a persistent environment without an interactive terminal;
    • Persistent memory across sessions, able to turn process data into reusable knowledge;
    • User modeling that distinguishes general rules from individual preferences;
    • A low-friction messaging channel, so tasks can be initiated and collected in real collaboration scenarios.

    These four points should not be patched together with external plugins; they need to be designed coherently at the architecture level. The sections below unpack each layer.

    2. The Execution Engine: Letting the Agent Leave the Laptop

    In-repository coding tools are typically bound to a code repository. They are good at reading code, modifying code, running tests, and submitting changes, but their lifecycle follows the foreground session. To become persistent, the execution core must be separated from the interactive interface and reshaped into a managed service.

    A persistent execution engine usually consists of the following components:

    • Task scheduler: supports time-based, event-based, and condition-based triggers, with task descriptions maintained as declarative configuration;
    • Sandboxed runtime: isolation across filesystem, processes, and network, least-privilege permissions, and command allowlists;
    • Tool registry: a unified description of each tool’s name, input schema, side-effect level, and timeout policy;
    • State store: preserves task context, intermediate artifacts, and failure snapshots, supporting resume from breakpoints;
    • Observability: structured logs, distributed tracing, metrics, and alerts, with the full decision rationale recorded.

    An illustrative task declaration (pseudocode, structure only):

    1. task:
    2. name: nightly-repo-health
    3. trigger:
    4. cron: "0 2 * * *"
    5. runtime:
    6. sandbox: container
    7. network: egress-allowlist
    8. timeout: 30m
    9. steps:
    10. - tool: repo.scan
    11. - tool: test.run
    12. args: { scope: changed }
    13. - tool: report.publish
    14. args: { channel: ops_group }
    15. memory:
    16. read: [ "repo.conventions", "user.preferences" ]
    17. write: [ "task.history" ]

    The key design principle is controlled side effects: any tool capable of writing, deleting, or sending data externally must explicitly declare its risk level and match approval rules in the policy engine.

    3. The Learning Loop: Turning Execution into a Knowledge Asset

    The fundamental flaw of static configuration is that knowledge cannot grow automatically from practice. The goal of a learning loop is to convert every execution into a searchable, verifiable, and rollback-capable experience entry.

    A pragmatic loop has four stages:

    1. Capture: record the input, the plan, the tool call sequence, the result, and any points of human intervention;
    2. Distill: summarize the trace into a structured entry, such as “scene—action—effect—constraint,” annotated with a confidence score;
    3. Validate: run new entries in shadow mode first (suggest only, no execution) and compare their effect against existing policies;
    4. Promote or roll back: entries that pass evaluation gain confidence and enter the active set; those that fail are down-weighted or retired.

    Example entry structure:

    1. {
    2. "scene": "Build fails and logs show a dependency conflict",
    3. "action": "Pin the transitive dependency version and rebuild",
    4. "constraint": "Do not modify the major version number",
    5. "confidence": 0.82,
    6. "evidence": 12,
    7. "status": "active"
    8. }

    Engineering practice must prevent “experience pollution”:

    • Set source weights, with human confirmation ranked above automated induction;
    • Introduce conflict resolution, selecting the best strategy for the same scene by confidence and recent win rate;
    • Retain versions and diffs, so any policy change is auditable and reversible;
    • Periodically forget and compress, avoiding unbounded memory growth that increases retrieval noise.

    4. User Modeling: Separating General Rules from Personal Preferences

    The essence of an agent that “gets smoother with use” is the ability to tell which constraints come from team norms and which come from individual habits. A layered structure is recommended:

    • Global layer: organization-level security, compliance, and coding standards, which individuals cannot override;
    • Team layer: project conventions, directory structure, and release processes;
    • Personal layer: communication style, output granularity, and preferred tech stack;
    • Session layer: temporary context that expires when the session ends.

    Conflicts are resolved by “higher layer first, explicit first, most recent first.” Personal preferences must never break the global security boundary; this is a non-negotiable bottom line. For storage, preference entries should be readable, editable, and exportable, with users holding full control, which is also a basic requirement for compliance audits.

    5. Integrating a Messaging Channel: Handing Off Tasks with Low Friction

    A persistent agent needs a messaging channel equivalent to collaboration tools. Four points matter in implementation:

    • Prefer long-lived connections, avoiding dependence on a public inbound address and lowering the deployment barrier;
    • Cover all message types, with text, images, audio, and files uniformly abstracted as an “input pack”;
    • Session routing, distinguishing visibility and permissions between direct and group chats;
    • Idempotency and deduplication, preventing duplicate execution caused by redelivery.

    Unified input abstraction:

    1. @dataclass
    2. class InputPack:
    3. session_id: str # Direct or group session identifier
    4. scope: str # private | group
    5. parts: list[Part] # text / image / audio / file
    6. sender: str
    7. ts: float
    8. def handle(pack: InputPack, policy: Policy) -> Result:
    9. if not policy.allow(pack.scope, pack.sender):
    10. return Result.denied()
    11. plan = planner.build(pack, memory=store.recall(pack))
    12. return executor.run(plan, sandbox=policy.sandbox())

    On security, one point must be clear: the channel is only responsible for transport, and permission decisions must be made independently by the policy engine. In group chat scenarios, the automation level is lowered by default, and human confirmation is mandatory for write operations and external sends.

    6. Division of Labor with the Existing Toolchain

    The three types of tools are not substitutes but complementary layers: the in-repository coding agent handles “writing it right,” the persistent agent handles “running long,” and the messaging channel handles “reaching the right person.” A sensible combination is: the coding agent produces changes, while the persistent agent takes on scheduled inspections, regression validation, and result distribution, with both aligning on facts through a unified state store and logging service. Four metrics indicate whether a persistent agent is mature: task success rate, human intervention rate, policy reuse rate, and mean time to recovery.

    7. Enterprise Adoption: Stability, Security, and Cost

    In an enterprise environment, the engineering focus turns to controllability. The recommendation is to run the sandboxed runtime on a container platform, store artifacts and memory snapshots in object storage, use a message queue for peak shaving and delivery guarantees, build the observability foundation from logging, monitoring, and alerting, and issue short-lived credentials through a unified credential manager. On the cost side, model calls should be tiered: simple decisions go to smaller models, complex reasoning goes to larger models, and results for high-frequency repetitive tasks are cached.

    If you want to get started quickly with cloud-managed capabilities, Baidu AI Cloud offers corresponding products across general categories such as containers, storage, messaging, and observability. You can replace self-built components layer by layer as described above to reduce initial operations overhead.

    8. Conclusion

    The next stage of agent competition is not about the number of tools, but about whether the agent can grow. Make the execution engine a persistent service, turn process data into verifiable knowledge assets, turn preferences into a governable layered model, and turn the messaging channel into a low-friction entry point. With these four elements forming a closed loop, the system evolves from an assistant that needs to be re-briefed every time into a partner that understands you better the more you use it.