Design Philosophy of Long-Running AI Agents: Execution Foundation vs. Self-Improvement

    This article compares two core design philosophies for long-running AI agents that operate as persistent services rather than stateless assistants: an execution-foundation-first approach focused on determinism, sandboxing, and governance, and a self-improvement-first approach built around memory and reusable skills. It outlines a layered reference architecture, a four-tier memory design with gated write policies, a skill-distillation pipeline with replay validation, and engineering practices for isolation, orchestration, observability, evaluation, and cost control. Readers will learn how mature systems combine a controllable lower layer with an evolving upper layer, and how to choose a starting point based on stability, compliance, and task variability.

    1. Background: From Conversational Assistants to Long-Running Software Systems

    Early conversational assistants were mostly stateless: one request, one response, with context disappearing when the session ended. When an agent needs to stay online for a long time and continuously handle real business, its form is closer to a resident service process than a function call. Such systems usually provide four foundational capabilities: connecting to a large model for reasoning and planning, invoking tools and executing commands, connecting to messaging entry points for human interaction, and persisting memory to maintain continuity across sessions. On top of these, it can also handle scheduled triggers and long-running background tasks, pushing results back to users when tasks finish.

    As the foundational capabilities become homogeneous, what truly separates good designs from poor ones is design philosophy: where the system places complexity, and where it places the drive for growth.

    2. An Abstract Comparison of Two Design Orientations

    The first orientation can be called “execution foundation first.” It concentrates engineering effort on determinism: task orchestration, sandbox isolation, failure retries, observability, and access control. System behavior is predictable and auditable, with clear capability boundaries, making it suitable for production environments with high stability and compliance requirements.

    The second orientation can be called “self-improvement first.” It layers an experience loop on top of the foundation: it not only remembers user preferences, but also remembers how a certain class of tasks was completed before. After the agent hits a pitfall or is corrected by the user, it immediately turns that experience into a reusable skill. Its slogan-like expression is “growing together with users,” and its essence is productizing the learning loop.

    The two are not mutually exclusive. Growth without a foundation amplifies risk, while a foundation without growth remains a “collection of one-off scripts” over time. A mature solution is usually a two-layer structure: the lower layer ensures controllability, and the upper layer ensures evolution.

    3. A Layered Reference Architecture

    • Access layer: command-line interaction, messaging entry point adapters, scheduled triggers, and external event entry points.
    • Orchestration layer: task decomposition, plan scheduling, long-running task state machines, and resume-from-breakpoint.
    • Execution layer: tool invocation, command execution, file and data reads/writes, all running in an isolated environment.
    • Memory layer: short-term context, episodic memory, semantic memory, and procedural memory (skills).
    • Governance layer: identity and permissions, audit logs, metrics and alerts, and cost and quotas.

    An illustrative task state definition (pseudocode, structure only):

    1. class TaskState:
    2. id: str
    3. goal: str
    4. plan: list[Step]
    5. status: str # pending / running / blocked / done / failed
    6. artifacts: list[str]
    7. retries: int
    8. memory_refs: list[str]

    4. Memory System Design: Four-Tier Separation and Write Policies

    Memory should not be a single blob of ever-expanding text. A practical approach is to split memory into four tiers: session context (the current task window), episodic memory (what was done and what the result was), semantic memory (user preferences and domain facts), and procedural memory (executable skills). During retrieval, first recall by task type and temporal proximity, then rerank by relevance, and finally let the model decide whether to write to long-term storage.

    Writes must have a threshold; otherwise memory gets polluted by noise. Three trigger conditions are recommended: explicit user correction, the same task recurring with a stable path, and a successful task whose steps can be generalized. Each memory item should carry its source, confidence, expiration, and a revocable flag, and support a “forget” operation to meet privacy and compliance requirements.

    5. Skill Distillation: Turning Experience into Reusable Assets

    A skill is the concretization of procedural memory. It usually includes trigger conditions, prechecks, a step sequence, failure fallback, and acceptance criteria. A reliable distillation flow is: candidate extraction → structuring into a skill draft → replay validation in a sandbox → promotion to a formal skill after passing → periodic evaluation and retirement of invalid skills.

    1. skill:
    2. name: data reconciliation workflow
    3. when: task_type == "reconciliation" and data_source_count >= 2
    4. precheck: credentials valid, source tables readable
    5. steps: [pull snapshot, normalize fields, compare differences, generate report]
    6. fallback: switch to manual review when differences exceed threshold
    7. accept: report fields complete, differences explainable

    The key is “verifiable”: experience that has not passed replay validation should not enter the production execution path directly, otherwise errors get amplified by automation.

    6. Engineering Implementation: Isolation, Orchestration, and Observability

    Long-running presence means a long-term exposure surface. Command execution and file access should be confined to containers or sandboxes, combined with least-privilege accounts, read-only mounts, an outbound network allowlist, and resource quotas. Long-running tasks are managed with state machines and paired with a message queue for peak shaving and decoupling; failures are retried using idempotency keys, and when necessary enter a dead-letter queue for manual intervention.

    Observability requires three kinds of data: structured logs that record every tool call and a parameter summary, metrics that cover task success rate and latency distribution, and alerts for consecutive failures and abnormal costs. All sensitive information is redacted before being written to disk.

    7. Evaluation and Cost Governance

    The biggest risk for a growth-oriented system is “drifting further off course the more it is used.” A fixed evaluation set should be established, covering typical tasks and historical failure cases, with regression testing after every skill or prompt change, tracking success rate, average number of steps, and manual takeover rate. On the cost side, set token and invocation quotas, select models by task tier, and merge and cache high-frequency, low-value tasks.

    8. Selection Advice and Conclusion

    If the business emphasizes stability and compliance, build the foundation first and then talk about growth. If the business changes rapidly and has many long-tail tasks, prioritize building the memory and skill loop, but you must simultaneously complete the sandbox and audit capabilities. In a general cloud environment, a container platform carries isolated execution, object storage holds artifacts, a message queue handles asynchronous tasks, and logging services plus monitoring and alerting form the governance loop. General capabilities provided by cloud vendors such as Baidu AI Cloud can serve as the hosting foundation for this kind of architecture. In the end, there is only one criterion: whether the system, within controllable boundaries, turns every correction into the next correct action.