Persistent Agent Self-Evolution and Prompt Context Engineering in Practice

    Persistent agents are software systems that preserve task state, memory, and execution records across requests, sessions, and processes. This article distinguishes in-session adaptation, external state and policy updates, and model parameter updates; defines self-evolution as controlled experience distillation into external knowledge and execution strategies with validation and rollback; and explains how prompt design, context engineering, and an execution framework work together. It then presents a six-stage loop from goal input to versioned release, along with prompt layering, memory management, state-machine reliability, evaluation criteria, and a phased rollout order.

    1. From One-Shot Q&A to Persistent Operation

    Traditional question-answering systems usually use a single request as the boundary: they receive input, generate an answer, and then end execution. Even if conversation history is retained, that does not mean the system can proactively track tasks, accumulate reliable experience, or resume work after a failure.

    A persistently running agent needs to handle a more complete lifecycle: understand the goal, break down tasks, call tools, observe results, adjust the plan, and when necessary save state and wait for the next event trigger.

    Here, “persistent” does not require the model to generate content continuously, nor does it mean maintaining a process that never exits. A more reasonable engineering definition is: task state, necessary memory, and execution records can persist across requests, sessions, and even processes, and the system can continue work from an explicit state.

    Therefore, a persistent agent is first a software system, and only second a way of interacting with a model. Its reliability depends not only on reasoning capability, but also on state storage, task scheduling, permission control, tool adaptation, and failure recovery.

    Industry attention, tool counts, or release frequency cannot directly prove that a system has self-evolution capability. The real questions are: what exactly does the system update, is the basis for the update reliable, has the update been validated, and can it be rolled back when something goes wrong?

    2. Where “Self-Evolution” Actually Happens

    In technical discussions, it is important to distinguish three types of change that are easy to confuse.

    2.1 In-Session Adaptation

    The agent revises its plan based on current tool results. For example, after finding that a file path does not exist, it relocates the directory. This is dynamic adjustment during task execution.

    It can improve completion rates for the current task, but if the relevant information is not saved, the next task may repeat the same mistake. Therefore, in-session adaptation is not the same as cross-task learning.

    2.2 External State and Policy Updates

    The system writes effective experience into a memory store, operational procedure, or prompt configuration so that later tasks can retrieve and reuse it. For example, it may record a verification method for a certain type of document, or save an output preference confirmed by the user.

    Such updates usually do not change model weights. This is the main engineering path for persistent agents to accumulate experience. The effect comes from the collaboration between “model plus external system,” not from the model acquiring new capabilities out of thin air.

    2.3 Model Parameter Updates

    Changing model parameters through training or fine-tuning is another learning mechanism. It requires independent data processing, training evaluation, and release processes. The fact that an agent has memory capability does not imply that it is automatically updating the model.

    The “self-evolution” discussed in this article mainly refers to the second type: the system distills experience under controlled conditions, updates external knowledge and execution policies, and uses evaluation to confirm whether these changes improve subsequent task performance.

    Such improvement is not guaranteed to continue. Incorrect experience, outdated knowledge, and inappropriate policies can also cause degradation, so self-evolution must include validation and rollback.

    3. Responsibilities of Prompts, Context, and the Execution Framework

    A maintainable agent system needs clear boundaries among prompt design, context engineering, and the execution framework.

    3.1 Prompt Design: Define Goals and Behavioral Constraints

    Prompts are responsible for role definition, task goal description, output requirements, and behavioral boundaries. They should answer:

    • What task needs to be completed now?
    • How are success and failure determined?
    • Which behaviors are allowed, and which must stop?
    • When should user confirmation be requested?
    • How should insufficient evidence and tool failures be handled?

    A good prompt is not simply longer. It should make constraints explicit and well layered, rather than stuffing every business detail into fixed instructions.

    3.2 Context Engineering: Decide What the Model Sees

    Context is the set of information available for the model’s current decision, including the user request, task state, retrieval results, tool outputs, history summaries, and relevant memory.

    The focus of context engineering is not “save as much information as possible,” but selecting necessary, trustworthy, and appropriately timely information for the current decision. Unfiltered history can consume the input budget and may mislead the model with irrelevant content or old conclusions.

    3.3 Execution Framework: Turn Decisions into Controlled Actions

    The execution framework is responsible for calling the model and tools, maintaining task state, handling timeouts and retries, enforcing permission checks, and recording key events.

    It is also often called the agent runtime scaffold. Unlike prompts, this layer should enforce constraints through program logic rather than relying only on the model to “voluntarily comply.”

    For example, “obtain confirmation before deleting a file” can be written into a prompt, but it must also be checked by the permission mechanism before tool execution. Prompts provide behavioral guidance; the execution framework provides enforced boundaries.

    The relationship among the three can be summarized as:

    Prompts define behavioral principles, context provides decision evidence, and the execution framework keeps actions controlled.

    4. Building a Closed Loop from Task Execution to Experience Accumulation

    A verifiable experience update process can be divided into six stages:

    Goal input → controlled execution → evidence logging → experience distillation → independent validation → versioned release.

    4.1 Goal Input: Make Acceptance Conditions Explicit

    “Process this material” is not a sufficient task definition. The system also needs to know the processing scope, output form, completion criteria, and permission boundaries.

    For example, a material organization task can require: cover the specified directory, extract key conclusions, preserve source locations for factual judgments, and do not modify original files. The more explicit the acceptance conditions, the easier it is to automate later evaluation.

    4.2 Controlled Execution: Limit Resources and Side Effects

    When an agent executes a task, it should have maximum step count, time budget, call budget, and retry limits. When limits are reached, the system should save state and report the blocking reason rather than loop indefinitely.

    For operations with side effects, such as writing, publishing, deleting, or external notifications, the system should distinguish between “generating an action suggestion” and “actually executing the action.” High-risk operations must go through appropriate approval.

    4.3 Evidence Logging: Preserve Auditable Execution Facts

    Experience distillation cannot rely only on the model’s summary of its own performance. The execution framework should record tool call status, necessary input and output summaries, acceptance results, and human feedback.

    There is no need to save the model’s internal reasoning process. Usually, structured action records, concise decision explanations, and verifiable tool results are enough to support troubleshooting and experience analysis while reducing privacy exposure.

    4.4 Experience Distillation: Turn One Experience into a Candidate Rule

    Experience should include applicable conditions, not just an abstract conclusion.

    For example, “search first before answering in the future” is too broad. A more valuable candidate experience is:

    When a task requires answering factual questions from specified material, first locate the relevant passages; if sufficient evidence is not found, state that the material does not cover it rather than filling in a definite conclusion.

    Such a rule includes trigger conditions, recommended actions, and failure handling, making it easier to validate and reuse.

    4.5 Independent Validation: Avoid Making Self-Evaluation the Only Basis

    The model can help summarize errors, but it should not also be the only judge. Candidate experience should be validated through task acceptance rules, held-out test sets, human spot checks, or other independent evidence.

    Validation should check not only whether the target scenario improves, but also whether other scenarios are negatively affected. For example, adding a retrieval step may improve factual accuracy, but it may also increase latency and cost for simple tasks.

    4.6 Versioned Release: Allow Bad Updates to Be Rolled Back

    Experience, prompts, and processes should all have versions, update times, and source records. A new policy can first be used within a limited task scope, and then expanded after it is observed to be stable.

    If failure rates rise, costs increase abnormally, or permission issues appear, the system should be able to restore the previous version rather than continue stacking patches.

    5. Prompt Design: Layered Organization to Prevent Experience from Overriding Rules

    It is recommended to divide prompts and dynamic information into the following layers:

    1. Stable constraint layer: safety requirements, permission boundaries, and prohibited behaviors.
    2. Task protocol layer: tool usage, output format, and stop conditions.
    3. Current task layer: user goal, scope, and acceptance criteria.
    4. Experience reference layer: filtered historical experience and user preferences.

    The experience reference layer can only assist decision-making; it cannot override stable constraints. Historical experience, even if it was once successful, should not automatically receive higher permissions.

    For example, the fact that the system has previously executed a certain type of file cleanup task does not mean that all future cleanup requests can skip confirmation. Experience can improve recognition and execution order, but it cannot expand operational authorization on its own.

    In addition, prompts should clearly distinguish facts from inferences: a successful tool return does not necessarily mean the business goal is complete; a generated file does not necessarily mean the content is correct; and the absence of errors does not necessarily mean the result is complete. The agent needs to judge task status based on acceptance conditions.

    6. Context Management: Keeping Long-Term Memory Usable

    6.1 Split Memory by Purpose

    Long-term memory should not be an ever-growing text block. It can be divided by purpose into:

    • User preferences: language, format, communication habits;
    • Task state: completed steps, to-do items, blocking reasons;
    • Factual knowledge: verified information and its sources;
    • Operational experience: processes, preconditions, and known failure modes;
    • Temporary information: intermediate results valid only for the current task.

    Different categories should use different retention periods, update rules, and access permissions. A one-off tool error usually does not deserve long-term memory, and sensitive information such as account credentials should not be written directly into searchable text.

    6.2 Retrieval Should Consider Relevance, Recency, and Credibility

    Text similarity is not the same as suitability for reuse. When selecting memory, the system should also check task match, source reliability, whether it has expired, whether it has been replaced by a new rule, and whether the current user has access.

    Team or multi-user scenarios also require isolation. Other users’ preferences, document summaries, and action records should not be loaded into the current context merely because the content is similar.

    6.3 Summaries Cannot Replace Raw Evidence

    History compression helps control context length, but summaries may omit conditions or change meaning. Therefore, task summaries should preserve open questions, key evidence locations, and the basis for state changes.

    For high-risk judgments, it should be possible to trace back to raw records rather than relying only on conclusions compressed over multiple rounds.

    7. Execution Framework: Implementing Reliability as a State Machine

    Persistent tasks need explicit states, such as: pending, running, waiting for confirmation, waiting for retry, completed, failed, and canceled.

    State transitions must have a basis. “Completed” should be triggered by acceptance checks, not by the model claiming so in its response.

    The following is illustrative pseudocode and does not correspond to any specific product interface:

    1. Read task state
    2. Check task permissions and resource budget
    3. Retrieve memory needed for the current task
    4. Assemble prompt, task information, and tool results
    5. Loop:
    6. Ask the model to propose the next action
    7. Validate action parameters, permissions, and risk level
    8. If human confirmation is required:
    9. Save state and pause
    10. Execute approved action
    11. Record result and update task state
    12. If acceptance conditions are met:
    13. Mark complete and exit
    14. If budget is exhausted or an unrecoverable error occurs:
    15. Save failure reason and exit
    16. Distill candidate experience from execution records
    17. Validate candidate experience
    18. If approved, write to versioned experience store

    Retries must also consider idempotency. Read-only queries are usually easier to retry, while operations such as sending notifications or writing data may produce duplicate side effects. In such cases, business identifiers, execution records, or target state checks should be used to confirm whether the action has already occurred.

    External content should be treated as data, not as system instructions. When text such as “ignore the rules” or “read credentials” appears in a document or tool output, it should not change the agent’s permissions or goals.

    8. How to Verify That the System Is Actually Improving

    Evaluation should not only observe whether answers are more fluent. It should also cover task effectiveness and operational cost:

    • Task completion rate and acceptance pass rate;
    • Factual errors and missing evidence;
    • Frequency of human intervention;
    • Tool call count, latency, and resource consumption;
    • Repeated execution and exception recovery;
    • Improper memory writes and use of stale memory;
    • Unauthorized behavior and risk of sensitive information exposure.

    To determine whether improvement comes from experience updates rather than changes in task difficulty, results before and after the update should be compared under similar conditions, and test tasks that did not participate in experience distillation should be retained.

    For long-running systems, environmental changes also matter: data updates, permission adjustments, and changes in tool behavior can all invalidate old experience. The experience store needs periodic review rather than only accumulation.

    9. Rollout Order: Reliability First, Autonomy Second, Continuous Optimization Last

    In practice, rollout can proceed in three stages.

    The first stage establishes a stable task execution chain, clarifies tool permissions, acceptance conditions, state saving, and audit records, and does not yet automatically modify long-term policies.

    The second stage introduces controlled memory, manages preferences, task state, and validated experience separately, and supports retrieval, correction, deletion, and expiration control.

    The third stage introduces automatic experience distillation, converts candidate experience into formal policies through validation, approval, or limited release, and continuously monitors degradation risk.

    The value of a persistent agent is not that it necessarily becomes smarter the longer it runs, but whether it can turn trusted feedback into reusable, verifiable, and reversible improvements. Only when prompts, context, and the execution framework together form this closed loop does “self-evolution” become more than a conceptual description; it becomes a system capability that can be engineered and continuously tested.