Persistent AI Agent Architecture: Dual-Track Self-Evolution and the Execution Harness in Practice

    This article explains how to design a persistent AI agent that keeps goals, state, and progress outside any single model call. It breaks a reliable agent system into six layers, describes a dual-track self-evolution approach based on reusable experience assets and execution policy optimization, and shows how prompt engineering, layered memory, and context engineering keep a limited context window carrying trustworthy state. It also covers the execution harness: state machines, retry and side-effect handling, permission isolation, budget limits, and resumable flows, plus an evaluation framework and a recommended rollout order that builds the control plane before widening autonomy.

    1. From Chat Assistants to Persistent Agents: What Actually Changes

    An ordinary chat assistant works around a single request: it receives input, generates an answer, and finishes. A persistent agent has to maintain goals, perform actions, wait for external events, and continue after interruptions across a much longer time span.

    Take a research-and-compilation task. It may pass through requirement confirmation, information retrieval, content extraction, result validation, and report generation. Along the way you can hit insufficient permissions, tool timeouts, updated source material, or a pending human approval. The system cannot rely on the current chat window to hold progress; it has to persist task state, key artifacts, and execution records outside the model.

    So “persistent” does not mean keeping one process running forever. It means the task lifecycle does not depend on a particular model call or a particular worker process. Even after a restart, the system should be able to identify which steps are done, which problems remain open, and which actions are still allowed.

    In the same way, “self-evolution” should not be read as the system endlessly raising model intelligence. The more accurate engineering meaning is this: with model capability roughly stable, reuse experience and improve execution policy so that repeated errors decrease and task completion becomes more reliable.

    What follows is a general architecture discussion, not conclusions drawn from the source code of any specific project.

    2. Overall Architecture: The Model Judges, the Framework Constrains and Delivers

    A reliable agent system can be split into six main layers:

    1. Interaction and task entry: receives user goals, additional constraints, and human feedback.
    2. Task orchestration layer: manages task state, step dependencies, execution budget, and pause/resume.
    3. Model decision layer: proposes the next action or produces a result based on the current context.
    4. Tool execution layer: performs retrieval, file processing, computation, and controlled business operations.
    5. Memory and knowledge layer: stores task facts, user authorization preferences, and validated operational experience.
    6. Evaluation and governance layer: handles result validation, access control, audit records, and policy release.

    The execution framework — usually called the Harness — connects model decisions to the real environment. It is not a thin wrapper around tool calls; it is the control system that defines what may run, how it runs, and what happens when execution fails.

    The overall relationship can be summarized as:

    User goal → task orchestration → context construction → model decision → permission check → tool execution → result validation → state update.

    Model output should be treated only as a proposed action awaiting verification. Whether to execute it, retry it, or escalate it for human confirmation is decided by the framework according to explicit rules. Only then can you avoid equating natural-language reasoning with trustworthy business control.

    3. Dual-Track Self-Evolution: Experience Capture and Policy Optimization

    3.1 Track One: Turning Successful Runs into Reusable Assets

    After an agent completes a task, valuable experience can be extracted from the execution trace: the processing order for a certain class of files, how to recognize common errors, acceptance conditions for results, and the boundaries where human intervention is required.

    An execution trace cannot become long-term knowledge directly. One success may depend on incidental conditions, and a temporary workaround after a failure may not suit other tasks.

    Reliable experience capture should go through these steps:

    • Candidate extraction: identify steps, constraints, and validation methods worth reusing.
    • Fact verification: check that the experience agrees with tool results and task artifacts.
    • Applicability annotation: state the input conditions, environment dependencies, permission requirements, and invalidation conditions.
    • Test validation: check effectiveness on representative tasks.
    • Versioned release: keep provenance, review records, and a rollback entry point.

    The value of a piece of experience lies not in how fluently it reads, but in whether it carries verifiable applicability conditions. “Check the data fields before aggregating” is too broad; specifying that you must check for missing fields, duplicate records, and unit consistency turns it into an executable checklist.

    This track mainly improves knowledge acquisition and action selection. It does not mean the base model’s parameters have been updated.

    3.2 Track Two: Improving Execution Policy Through Evaluation

    Experience assets answer “which knowledge is worth reusing.” Policy optimization answers “how to organize the execution process.”

    What can be optimized includes task decomposition, tool selection rules, context retrieval strategy, retry conditions, budget allocation, and termination criteria. Faced with missing information, for example, whether the system should clarify requirements first or collect the information that is already determinable depends on the task type and the cost of errors — it should not always follow the same flow.

    Policy improvement needs a complete loop:

    Execution records → error classification → improvement hypothesis → offline testing → limited-scope validation → general release.

    A few successful cases are not enough to claim a policy is better. One change may raise the completion rate while also increasing call cost or the risk of exceeding authority, so correctness, cost, latency, and safety should be observed together.

    If model training is involved, it requires separate data governance, training evaluation, and deployment processes. Prompt tuning, memory updates, and model parameter training must not be lumped together.

    3.3 How the Two Tracks Work Together

    Experience capture supplies more reliable knowledge and operational templates; policy optimization decides when to retrieve that experience, how to use it, and when to refuse it.

    Both need protection against feedback contamination. If the system stores an unverified answer in memory and later treats that memory as factual grounding, it creates a self-reinforcing error. For this reason, experience assets should carry provenance, verification status, expiry, and scope of applicability, and high-risk experience should pass human review.

    4. Prompt Engineering: Stable Rules, Not Piled-Up Instructions

    The goal of prompt design is to express task boundaries, evidence requirements, and action norms clearly — not to compensate for architectural gaps with ever longer instructions.

    It helps to split prompt content into three parts:

    Stable constraints: permission boundaries, prohibited actions, sensitive-data handling requirements, and actions that need approval.

    Task contract: the user goal, input conditions, delivery format, acceptance criteria, and execution budget.

    Dynamic information: current progress, recent tool results, open problems, and candidate experience.

    These three categories need explicit priority. External web pages, files, and retrieval results are data to be processed; the fact that they contain text like “ignore the previous rules” must not grant them the ability to change system behavior. Protection cannot rely on prompt declarations alone — it also requires tool permission isolation and pre-execution checks.

    So that the framework can verify model decisions, you can require structured action proposals. For example:

    1. Action type: read source material
    2. Target: authorized task file
    3. Purpose: confirm whether input fields are complete
    4. Expected result: field list and missing items
    5. Failure handling: record the reason, wait for additional material

    The above is only an illustrative protocol, not a specific product interface. The engineering point is that an action should carry a verifiable goal, parameters, and expected result, rather than having the framework interpret arbitrary natural-language instructions.

    5. Context Engineering: Making a Limited Window Carry Reliable State

    Long-running sessions produce large amounts of dialogue, logs, and tool output. Pushing all of it into the model context raises cost, drowns key constraints, and repeatedly propagates erroneous information.

    The core of context engineering is not unlimited input length, but selecting the information the current decision actually needs.

    5.1 Layered Memory

    Information can be divided into four kinds:

    • Working state: the current step, pending items, and the most recent execution results.
    • Task facts: confirmed requirements, input versions, and intermediate artifacts.
    • Long-term preferences: user preferences saved with authorization, modifiable and deletable.
    • Experience assets: validated operational templates, checklists, and lessons from failures.

    Different kinds of information need different retention and update rules. Temporary error logs are not necessarily worth keeping long-term; user preferences must not exceed their authorization scope; sensitive material from one task should not enter a cross-task shared experience store.

    5.2 Summaries for Understanding, Raw Records for Traceability

    Summaries help the model grasp progress quickly, but they can drop conditions, numbers, or anomaly details. Use “summary plus evidence reference”: the summary states the current conclusion, while the original artifacts retain verifiable grounding.

    When resuming a task, the system should read the authoritative task state and artifact records first, instead of continuing to act on the previous model-generated summary alone.

    5.3 Retrieval Cannot Rely on Semantic Similarity Only

    Long-term memory retrieval must also account for permission scope, temporal validity, source trustworthiness, and task match. A semantically similar but expired piece of experience can be more dangerous than having no experience at all.

    For facts that have been updated, establish version relationships or mark them explicitly as invalid, so that old and new conclusions do not enter the context at the same time and conflict.

    6. The Execution Harness: Keeping Autonomy Inside Controllable Boundaries

    6.1 Managing Tasks with a State Machine

    Task states should at minimum distinguish pending, running, waiting on external conditions, succeeded, failed, and cancelled. Transitions need explicit triggers and persisted records.

    “Waiting for approval” is not an execution failure, and “request submitted” does not mean the business operation is complete. A step can be marked successful only when verifiable completion evidence exists.

    6.2 Handling Retries and Side Effects

    Read operations are usually easy to retry, but sending notifications, modifying data, or submitting applications can produce duplicate side effects.

    The framework should maintain a stable identifier for each execution step and check existing results before retrying. For external operations whose completion status is uncertain, query the actual state first or hand off to a human instead of blindly resubmitting.

    “So-called exactly-once” execution usually cannot be guaranteed by the agent loop alone; it typically needs support from the business system, persistent records, and deduplication mechanisms.

    6.3 Isolating Permissions and Controlling Budget

    Every tool execution should check its authorization scope. Reading data, modifying data, running computations, and sending information externally should use different permission levels.

    At the same time, set a maximum step count, maximum runtime, call-cost budget, and retry limit. The budget controls cost, but it also breaks loops that keep repeating without real progress.

    Stopping rules should cover three cases: the goal has been reached, continuing lacks necessary conditions, or risk or budget has hit its limit.

    6.4 Designing Resumable Execution Flows

    After key steps complete, save state checkpoints and artifact references. On resume, re-confirm the input version, permission validity, and external environment rather than mechanically replaying historical actions.

    An illustrative control flow:

    1. Read task state and execution budget
    2. If the task is terminated, stop
    3. If approval is required, enter the waiting state
    4. Build the context needed for the current step
    5. Get the action proposed by the model
    6. Validate action structure, permissions, and risk
    7. Record the pending action
    8. Execute the controlled operation
    9. Verify the actual result
    10. Save artifacts and state
    11. If the result is abnormal, decide retry, pause, or failure based on the error type

    A production implementation must also handle concurrent updates, record-write failures, and uncertain execution results. These are framework responsibilities, not prompt techniques.

    7. Evaluation: Verify “Improvement” Instead of Trusting “Evolution”

    Agent evaluation cannot stop at whether the final answer reads well. It should cover at least these dimensions:

    • Task completion quality: whether acceptance criteria are met and key facts are correct.
    • Execution reliability: whether the system recovers after failure and whether duplicate side effects occur.
    • Resource efficiency: whether the number of calls, runtime, and cost are reasonable.
    • Security and compliance: whether authority was exceeded, sensitive information leaked, or untrusted instructions executed.
    • Experience reuse effect: whether reuse reduces errors and whether it introduces new misleading behavior.

    The test set should include normal tasks, missing information, tool timeouts, insufficient permissions, contradictory material, and external text containing malicious instructions. Testing only the smooth path cannot tell you how reliable the system is in a real environment.

    Policy or experience updates should keep versions and be compared against a stable baseline. For changes that affect permissions, external writes, or key business decisions, raise the review requirement instead of letting the agent publish them itself.

    8. Rollout Order: Build the Control Plane First, Then Widen Autonomy

    When building a persistent agent, start with tasks that have clear boundaries and verifiable results, and complete state persistence, tool permissions, audit records, and human takeover. Then introduce layered memory and validated experience retrieval. Only after that should policy be improved based on evaluation results.

    This order helps avoid two common mistakes: mistaking long-running for reliable, and mistaking automatically accumulated content for continuous learning.

    A genuinely usable “self-evolving” system needs experience validation, policy evaluation, version management, and rollback capability together. The model proposes possible actions, the execution framework makes those actions happen within explicit boundaries, and the evaluation system judges whether a change actually delivers a benefit.

    So the core competitiveness of a production-grade agent is not how clever a single inference is, but whether long-term execution is controllable, whether state is trustworthy, whether errors can be detected, and whether improvements are backed by evidence.