Persistent AI Agents: Dual-Path Improvement Architecture and Runtime Control

    Building persistent AI agents requires more than storing conversations. This article explains how durable task state, governed memory and skills, and controlled model training support continuous improvement. It also covers the division of responsibilities between prompts, context, and runtime controls, along with recovery, consistency, evaluation, and a staged path to production.

    1. Rethinking Persistence and Self-Improvement

    Most agent prototypes are built around a single interaction: receive a request, generate a plan, call tools, and return a result. This workflow can complete individual tasks, but it does not necessarily support long-running operation. Production systems must also address how to resume tasks after a process exits, reconcile external side effects, and turn past experience into useful input for future tasks.

    Persistence therefore involves more than saving chat history. It has three layers:

    1. Task-state persistence. Record task objectives, execution stages, tool results, pending work, and checkpoints so execution can resume after a failure.
    2. Knowledge and experience persistence. Preserve verified facts, user preferences, and reusable methods while distinguishing temporary information from information that remains valid over time.
    3. Improvement-process persistence. Maintain explicit versions and audit records for experience updates, skill evaluation, data cleaning, and model training rather than relying on ad hoc manual operations.

    “Self-improvement” also needs a careful definition. It does not mean that an agent can expand its capabilities indefinitely without oversight. It refers to mechanisms that use feedback to improve subsequent decisions. Those improvements may come from external knowledge and skills or from model parameter updates, but their effectiveness must be independently verified.

    A more precise architecture is:

    Task execution → Trajectory recording → Outcome verification → Experience candidates → Evaluation and release → Feedback from subsequent tasks

    An offline training branch can be added:

    Verified trajectories → Data governance → Model optimization → Independent evaluation → Controlled deployment

    These paths represent external improvement and internal improvement, respectively. They complement each other, but completing a task does not automatically trigger model training.

    2. External Improvement: Turning Experience into Governed Skill Assets

    2.1 Skills Are More Than Prompt Fragments

    A reusable skill should define an execution method with clear applicability boundaries. It should not simply reproduce an answer that happened to work once.

    For example, a data verification skill needs more than a sequence of processing steps. It should include:

    • Applicable tasks and scenarios where it should not be used.
    • Input formats and required prerequisites.
    • Available capabilities and permission requirements.
    • Operational steps, checkpoints, and stopping conditions.
    • Methods for validating the output.
    • Common exceptions and corresponding recovery strategies.
    • Version information and supporting sources.

    Without these details, a skill can mistake an environment-specific success for a generally useful method. Operations involving external writes, permission changes, or data deletion especially require explicit risk boundaries.

    2.2 Separate Online Execution from Asynchronous Review

    Extracting experience often requires additional reasoning and verification. Performing all of this work during an online interaction increases response time and makes the user’s task dependent on background governance processes.

    A better approach separates execution from asynchronous review:

    The online executor completes the current task and saves a traceable execution record. A background review job reads that record and generates memory or skill candidates. Only candidates that pass evaluation enter the approved asset repository for retrieval by future tasks.

    Review triggers can include task completion, resolution of a complex problem, recovery from a tool failure, user corrections, repetitive operations, or scheduled batch processing. Trigger thresholds should be based on actual workload and the value of extracted experience, rather than treating a fixed number of interaction turns as a universal standard.

    Background review must also be idempotent. Processing the same trajectory multiple times because of message retries should not create duplicate skills. Repeated extraction of the same fact should not repeatedly overwrite an already confirmed memory.

    2.3 Manage Memory, Skills, and Failure Analysis Separately

    These assets serve different purposes and should not be combined into an undifferentiated text repository.

    Memory answers: “Which facts should be retained?” Examples include user-confirmed formatting preferences, project constraints, and long-term objectives. Memory records should include their source, confirmation status, and validity period, and users should be able to correct or delete them.

    Skills answer: “How should this type of task be handled?” Their focus is a transferable workflow, not a particular user’s data.

    Failure analysis answers: “Which decisions caused the failure?” Examples include missing prerequisite checks, misinterpreting tool responses, and repeating operations with side effects. Failure analysis can inform skill revisions and provide evaluation cases.

    These assets can be linked, but their lifecycles should be managed separately. Short-lived environmental information should not automatically become long-term memory, and a single exception should not immediately become a general rule.

    2.4 Apply Quality Gates Before Publishing Skills

    Background-generated content is only a candidate. A complete-looking description is not sufficient grounds for production use.

    At minimum, evaluate four dimensions:

    1. Evidence. Is the skill based on actual execution results? Are its key conclusions traceable?
    2. Transferability. Does it contain task-specific accounts, paths, or sensitive data? Can it be applied to similar problems?
    3. Safety. Do its steps exceed existing authorization or include unverified hazardous operations?
    4. Effectiveness. Does it improve completion rates on independent test tasks without introducing regressions?

    Published skills must remain revocable and support rollback. Version governance is essential to prevent a growing asset collection from making decisions less coherent.

    3. Internal Improvement: Building a Verifiable Reinforcement Learning Loop

    3.1 External Experience and Weight Updates Serve Different Roles

    External skills influence model behavior through retrieval, prompts, and workflow constraints without changing model parameters. This path is useful for quickly correcting workflows and supplying environmental knowledge, and updates are easier to withdraw.

    Training model weights can change decision tendencies within a particular task distribution, including planning, tool selection, and error recovery. However, it requires reliable data, clearly defined evaluation objectives, and stable training infrastructure.

    External skills do not necessarily overcome a model’s capability limits, and training does not guarantee improvement across all tasks. Outcomes depend on the task distribution, feedback quality, and evaluation methods.

    In practice, teams should first address missing knowledge, unclear tool interfaces, and unstable execution workflows before deciding whether training is necessary. Otherwise, expensive parameter optimization may be used to compensate for problems that workflow design could resolve.

    3.2 Training Data Must Include Outcome Evidence

    A useful trajectory contains more than a request and final answer. It should preserve decision-relevant state and feedback, including:

    • Task constraints visible at the time.
    • Tool calls and structured responses.
    • External execution results and error messages.
    • Intermediate checks and recovery actions.
    • Evidence used to verify the final outcome.

    For data-processing tasks, evidence may include field consistency, record counts, and sample checks. For coding tasks, it may include test results and the scope of changes. For document tasks, it may include fact-checking, citation completeness, and format checks.

    A model’s own statement that “the task is complete” is not a substitute for external verification.

    Before data enters training, it also requires sensitive-data removal, authorization checks, deduplication, and quality filtering. Training and evaluation sets should be separated along appropriate dimensions, such as task source or time, to prevent similar trajectories from leaking across sets and inflating measured performance.

    3.3 Trajectory Compression Must Preserve Causal Information

    Long trajectories often contain repeated searches, redundant text, and unsuccessful attempts. Appropriate compression can reduce storage and processing costs, but its purpose is not to produce a smoother narrative. It must preserve enough causal information to explain the decisions.

    At minimum, retain why an action was taken, what the tool returned, which feedback changed the plan, and how success or failure was confirmed.

    If all failed attempts are removed and only a polished success path remains, the system may lose the information needed to learn recovery strategies. A safer approach retains both the original audit trajectory and a derived training representation, with traceability between them.

    Tool-interaction training may depend on the actual correspondence between actions and environmental feedback. A compressed narrative cannot necessarily replace the original interaction data.

    3.4 Understand the Role of Group Relative Policy Optimization

    Group Relative Policy Optimization, or GRPO, is a reinforcement learning method. Its basic approach generates multiple candidates under the same task conditions, evaluates their relative performance using rewards, and derives an optimization signal from comparisons within the group.

    The critical issue is not only the training algorithm, but whether the reward reflects the real objective. For a tool-execution task, a reward design might consider:

    Reward = Outcome correctness + Constraint adherence − Unnecessary operation cost − Risky behavior penalties

    This is a conceptual expression. The units, weights, and calculation methods must be defined for the task. Unauthorized access and unapproved external writes should be subject to separate prohibitions, not merely penalties that other rewards can offset.

    Training must also guard against reward gaming. A model may learn to produce outputs that appear correct or satisfy a checker without actually completing the task. Independent tests, varied verification methods, and human spot checks remain necessary.

    3.5 Constrain Model Updates with Regression Evaluation

    Improvement in one domain may come with degradation elsewhere. Before releasing a new model, evaluation should go beyond average success rate and cover:

    • Completion across task types and difficulty levels.
    • Tool-call accuracy and necessity.
    • Adherence to permission boundaries.
    • Clarification and refusal behavior under uncertainty.
    • Compatibility with existing skills and workflows.
    • Response time and execution cost.

    After passing evaluation, the model should enter a limited deployment with a rollback path to the previous version. Internal improvement should be a controlled offline loop, not an unverified process that changes weights in real time.

    4. Dividing Responsibilities Across Prompts, Context, and Runtime Controls

    4.1 Prompts Define Goals and Constraints

    Prompts should clearly distinguish role responsibilities, task objectives, completion criteria, tool-use rules, and stopping conditions. Stable rules and task-specific inputs should also be organized in separate layers to reduce repetition and conflicts.

    Prompts cannot replace permission systems. “Do not delete data” is behavioral guidance, not a security boundary. Sensitive operations still require permission checks and authorization verification at the execution layer.

    4.2 Context Supplies Information for the Current Decision

    More context is not always better. The model needs information that is relevant to the current decision, trustworthy, and sufficiently current.

    Context can be divided into stable rules, task state, relevant skills, long-term memory, recent interactions, and tool results. Each category should have an explicit source and trust level.

    External documents and tool responses must not be treated as system instructions. Text such as “ignore previous rules” is data to analyze; it cannot change permissions or task objectives.

    For long-running tasks, context can be compressed using structured state plus necessary source excerpts. The structured state should retain objectives, completed steps, unresolved issues, key evidence, and the next-step plan. A natural-language summary alone may be difficult to verify.

    4.3 Runtime Controls Govern Execution

    The runtime control layer connects the model to its environment and handles transactional responsibilities that the model should not decide independently, including:

    • Validating parameters and permissions before tool calls.
    • Enforcing execution budgets, timeouts, and retry limits.
    • Saving state and recovery checkpoints.
    • Detecting loops and lack of progress.
    • Requesting approval for high-risk actions.
    • Recording audit logs and isolating execution environments.

    The model can propose an action, but deterministic control logic should decide whether to execute it. Model output is not an authorization credential and cannot grant additional privileges.

    5. Recovery and Consistency in Long-Running Execution

    The hardest problems in long-running tasks often involve uncertain execution state rather than failed reasoning.

    For example, an external write may succeed, but the process may stop before the result is recorded locally. Retrying immediately after recovery could submit the same operation twice. Idempotency keys, result queries, or an operation ledger can help establish the external state before execution continues.

    Different actions require different policies:

    • Read-only operations: Retry within a defined limit.
    • Idempotent writes: Use a stable request identifier.
    • Non-idempotent operations: Strengthen pre-execution approval and post-execution reconciliation.
    • Operations with unconfirmed outcomes: Move to a state requiring human intervention.

    A task state model can be expressed as:

    Pending → Running → Awaiting feedback → Verified complete

    Exception branches include retryable failure, awaiting approval, human intervention required, and terminated.

    Explicit state transitions support recovery and auditing more effectively than conversation records alone.

    6. A Staged Path from Prototype to Production

    Implementation should proceed in stages based on risk and value.

    Stage 1: Establish a Reliable Execution Foundation

    Implement tool permissions, timeouts, state persistence, outcome verification, and audit records. Ensure tasks can stop safely and resume after interruptions.

    Stage 2: Introduce a Manually Maintained Skill Library

    Use version control and independent tests to determine whether skills are effective. Monitor retrieval accuracy and whether the resulting context becomes overloaded.

    Stage 3: Add Background Experience Extraction

    Generate candidate memories and skills, but require approval or automated quality gates before publishing them to production.

    Stage 4: Build the Training Data Pipeline

    Use only trajectories with clear authorization and verifiable outcomes. Establish evaluation sets covering success, failure, and recovery scenarios.

    Stage 5: Introduce Model Optimization When Benefits Justify It

    Compare quality, cost, and risk before and after training. Expand adoption only when improvements are stable and rollback remains possible.

    Measure progress using task completion rate, human takeover rate, repeated failure rate, recovery success rate, skill reuse effectiveness, and cost per task. The number of skills or volume of trajectories alone does not demonstrate that the system is improving.

    7. Conclusion: Improvement Depends on Controlled Execution

    The value of a persistent AI agent lies in turning one-off task execution into capabilities that can be accumulated, verified, and reused.

    External improvement changes how work is performed through memory and skills. Internal improvement adjusts model decisions through training. Prompts define behavioral objectives, context supplies the information needed for current decisions, and runtime controls enforce permission, state, and execution boundaries.

    Whether this architecture succeeds depends less on the novelty of “self-improvement” than on trustworthy experience, effective updates, recoverable failures, and controlled risk. Translating those requirements into versioning, state machines, validators, and audit processes is what moves an agent from a demonstration to a reliable production system.