Persistent Agents That Improve Over Time: Self-Evolution and a Three-Layer Engineering Design

    This article explains how persistent AI agents differ from one-shot chat systems, and why “self-evolution” should mean auditable changes to memory, workflows, and tools—not silent model weight updates. It covers prompt engineering as a behavior contract, context engineering for trusted state and experience, and harness engineering for reliable execution, plus a controlled release loop for reusable lessons, evaluation, and safety.

    From answering questions to finishing work over time

    Typical conversational systems are built around a single request: take input, assemble a prompt, call a model, and return a result. Even when they support multi-turn chat, the usual goal is coherence in the current thread—not long-lived task state, accumulated execution experience, or proactive handling of pending work.

    A persistent agent is different. It must keep necessary information across interactions, resume unfinished work after process restarts, and—when authorized—call tools, run plans, and handle scheduled events.

    Quality is therefore not only “does the reply sound fluent.” It also includes whether the agent:

    • Actually completes the task, rather than only suggesting actions
    • Distinguishes facts, guesses, preferences, and operational outcomes
    • Knows which experience is worth keeping and which information should expire
    • Recovers after failure instead of repeating the same mistakes
    • Stays inside permission, cost, and risk boundaries

    “The longer it runs, the more capable it becomes” holds only if experience is filtered, validated, and reused correctly. Otherwise, long running time can mean more bad memories, stale rules, and useless operations.

    Analyzing these systems should shift attention from the model alone to three cooperating engineering layers: prompt engineering, context engineering, and execution-framework (harness) engineering.

    Draw a technical boundary around “self-evolution”

    Inference-time adaptation is not a parameter update

    In common agent architectures, model weights do not change because of one tool call or one user correction. Improvement usually happens outside the model:

    • Record preferences the user has explicitly confirmed
    • Turn successful tasks into reusable steps
    • Store failure reasons and when they apply
    • Adjust retrieval content and tool-selection policy
    • Evaluate candidate workflows and then update versions

    These mechanisms change later inputs, procedures, and available knowledge. They do not directly change model parameters.

    When weights are actually updated, that needs separate data governance, training, validation, and release. It must not be mixed with everyday memory writes.

    Split self-evolution into an auditable loop

    A reasonable loop is:

    task execution → evidence collection → candidate experience → validation and evaluation → controlled release → later reuse → outcome monitoring.

    The easiest step to skip is validation and evaluation. If the system writes a model summary into long-term memory as soon as a run ends, it may treat a lucky success as a general rule, or freeze a wrong explanation as future policy.

    For example, a file job may succeed only because the input happened to meet a special condition. If the system then infers “this class of files never needs checking,” the so-called evolution reduces reliability.

    Experience records therefore need more than “what we did.” They should include “under what conditions it worked,” “what evidence we have,” and “when it does not apply.”

    Prompt engineering: roles, boundaries, and a behavior contract

    The core job of prompt engineering is not to make the model “sound like a persona.” It is to make it follow clear, stable rules on complex tasks.

    Split prompts into layers with distinct duties

    A practical layout:

    Stable rules: system duties, safety constraints, permission principles, and how to treat information credibility.

    Task goals: current objective, inputs, constraints, and acceptance criteria.

    Execution guidance: when to call tools, when to ask for confirmation, when to stop, and how to handle failure.

    Dynamic information: retrieved memory, tool returns, and current task state. These must be labeled by source and must not automatically share the authority of stable rules.

    Layering reduces rule conflicts in long prompts and makes independent maintenance and testing easier.

    Replace vague instructions with acceptance criteria

    “Help me organize the materials” is hard to judge as done. A more reliable task description includes:

    • Input scope: which materials are in scope
    • Output requirements: what structure the result must have
    • Quality bar: whether key conclusions need evidence
    • Action boundaries: whether original files may be modified or deleted
    • Failure handling: stop, ask, or emit a missing-item list when materials are insufficient

    Clearer acceptance criteria make the next step easier for the agent and easier for external programs to verify.

    Do not put access control in the prompt

    A prompt can say “confirm before delete,” but it cannot replace real access control.

    For deletes, message sends, config changes, and similar actions, the execution framework must enforce permissions, approval status, and resource scope. Even if the model emits a non-compliant call, the execution layer must be able to refuse.

    Prompts express rules; programs enforce them. They work together; they do not replace each other.

    Context engineering: give the model the right information

    Context engineering is about supplying enough, relevant, trustworthy, and not-stale information in a limited input window.

    Separate task state, long-term memory, and reusable experience

    These three should not share one undifferentiated store.

    Task state records current progress: completed steps, pending items, tool results, and checkpoints. Its main use is resume.

    Long-term memory holds information that remains valuable across tasks, such as user-confirmed output preferences. It must support edit, invalidation, and deletion.

    Reusable experience records how a class of tasks is handled: applicability conditions, pre-checks, steps, failure modes, and verification.

    Chat logs are closer to raw event material. They should not be injected as long-term knowledge without filtering.

    Writing memory needs more governance than reading it

    A memory record should typically include at least:

    • Content and category
    • Source and traceable evidence
    • Created time and last verified time
    • Scope of applicability
    • Expiry or invalidation conditions
    • Verification status
    • User or tenant ownership

    Model-generated confidence can be a hint. It is not a calibrated probability of truth and cannot replace external evidence.

    Sensitive information needs separate authorization, storage protection, and access policy. “Might be useful later” is not a default reason to keep it.

    Retrieval cannot rely on semantic similarity alone

    Similarity is only part of candidate retrieval. Whether to use a hit should also consider:

    • Whether it belongs to the current user and task
    • Whether it is still valid
    • Whether it has been confirmed
    • Whether it is compatible with the current environment
    • Whether a newer version exists
    • Whether it conflicts with higher-trust evidence

    A historical lesson can look similar to the current problem and still be inapplicable after the environment changed.

    Compression must not erase critical constraints

    Long tasks usually need history compression, but summaries should preferentially keep goals, constraints, confirmed facts, key decisions, open issues, and evidence references.

    Do not compress “the tool returned a result” into “the task is complete.” Call success and business success are different.

    For amounts, identifiers, permission status, and other precise fields, keep structured data or pointers to original records so repeated summarization does not distort them.

    Harness engineering: make actions actually happen reliably

    Execution-framework engineering—also called harness engineering—connects model decisions to a real runtime. It covers state progression, tool execution, permission checks, error handling, budget control, and result verification.

    Use explicit task state, not guesses from chat

    Tasks can be waiting, running, waiting for confirmation, completed, failed, or canceled, with legal transitions defined.

    State changes and tool results should be written to durable storage. After an outage, the system can resume from checkpoints instead of reconstructing everything from dialogue.

    For operations with external side effects, record operation IDs and outcomes so recovery does not replay them.

    Every tool call needs a full execution contract

    Each tool should specify:

    • Input types and required fields
    • Output shape and error classes
    • Whether it has external side effects
    • Required permissions
    • Timeouts and cancellation
    • Whether it is idempotent
    • How to verify results after the call

    “Request accepted” is not “goal achieved.” An async tool may only return an accepted status; the agent still needs a completion event or an active status query.

    Retries must depend on error type

    Transient network faults may warrant limited retries. Parameter errors should be fixed first. Insufficient permission should stop and request authorization. Unmet business conditions need replanning.

    For non-idempotent operations, a timeout must not immediately become another call. Confirm whether the previous attempt already took effect, or you may send duplicate notifications or writes.

    Persistent operation does not mean the model is always running

    A long-lived system can be driven by schedulers, event listeners, and task queues. The agent is invoked when a trigger fires.

    That is easier for cost control, concurrency, and incident localization. Scheduled jobs should also consider time zones, catch-up after missed runs, overlapping jobs, and a per-run budget.

    Treat experience extraction as a controlled release process

    Suppose an agent regularly processes a batch of materials and learns that a certain input type must be encoding-checked first, or later parsing may fail.

    It can generate a candidate lesson, but should not immediately promote it to a default rule for all tasks. A reasonable flow is:

    1. Save related input features, failure logs, and post-fix verification results
    2. Limit the lesson to a clear material type and processing path
    3. Check effectiveness on independent samples
    4. Confirm it does not break other inputs
    5. Publish a versioned experience record
    6. Monitor later outcomes and keep a rollback path

    The following pseudocode only illustrates the flow; it is not a specific API:

    1. run the task
    2. save tool results and verification evidence
    3. if there is reusable experience:
    4. generate a candidate lesson
    5. check privacy, provenance, and applicability bounds
    6. evaluate on independent samples
    7. if release criteria are met:
    8. save a new version
    9. mark the applicability scope
    10. else:
    11. keep it as pending verification

    Lessons that touch permissions, production configuration, or high-risk operations usually still need human approval even after automated evaluation. An agent must not enlarge its own privileges by “learning.”

    Evaluation and safety: stop the system from drifting as it runs

    Use outcome metrics to test whether evolution is real

    Track task success rate, repeated-failure rate, human-intervention rate, wrong tool-call rate, average latency, and resource use.

    Evaluation samples should cover different input conditions. Avoid using only the data that generated the lessons as the sole test set, or the system may merely memorize existing cases.

    Also pin or record model, prompt, experience, and tool versions. Without versions, it is hard to tell where an improvement came from.

    Keep untrusted content from polluting instructions and memory

    Files, messages, and tool returns may contain text that asks the model to ignore rules, leak information, or change permissions.

    That content is data to analyze, not system instructions. Memory writes need independent checks so one malicious input cannot become a long-lived behavior rule.

    Keep a complete, protected audit trail

    Audit records should link tasks, tool calls, approvals, verification results, and experience updates. Content should be redacted and access-limited so logs themselves are not a leak path.

    On anomalies, the system should be able to pause tasks, roll back experience versions, disable high-risk tools, and resume from a confirmed state.

    A rollout path: reliable execution first, then accumulated experience

    Implementation can proceed in three stages.

    Stage 1: a controllable single-task loop.
    Put permission boundaries, tool contracts, result verification, timeouts, and tracing in place before adding complex memory.

    Stage 2: durable state and limited memory.
    Support resume. Prefer user-confirmed facts and well-evidenced lessons. Add retrieval, invalidation, and deletion.

    Stage 3: candidate evaluation and versioned release.
    Give experience updates tests, approval, monitoring, and rollback, then gradually widen automation.

    The core value of a persistent agent is not the impression that “the system is getting smarter by itself.” It is turning valid evidence from each run into assets the next task can use safely.

    Prompt engineering defines the behavior contract, context engineering manages information supply, and harness engineering makes action reliable. Only when the three form a verifiable, auditable, rollback-capable loop is “self-evolution” an engineering capability rather than a slogan.