Long-Term Agent Memory and Skill Solidification in Practice

    Why agents forget constraints across sessions, how to separate memory from skills and deterministic tools, and how to evaluate stability and token cost without treating accidental success as capability.

    Why Poor Memory Becomes a System Problem

    Many agents perform adequately in a single conversation. Across sessions, windows, or long runs, they repeatedly ask about known constraints, retry the same mistakes, and stuff the same preamble back into context. On the surface they “forgot what was said last time.” In practice, state was never engineered: experience stays in chat text and never becomes a retrievable, versioned, auditable asset.

    This usually shows up as three costs at once.

    • Repeated alignment cost: Permission boundaries, data definitions, and output formats for complex tasks must be restated every time, like continuous onboarding.
    • Token and inference cost: Failed traces, correction instructions, and repeated plans fill the context. Useful information density drops while bills and latency rise together.
    • Stability cost: The same input takes different paths on different turns. Success depends on that sample and the current page state, not on a repeatable process.

    Treating “good memory and self-learning” as the model suddenly becoming stronger is a detour. A safer goal is to remember preferences and constraints the user has already confirmed, turn repeatedly successful steps into skills, and move work that programs should do out of the model loop.

    The Pain Often Shares One Cause: Uncertain Processes for Certain Work

    High token use and unstable long runs often come from the same design choice: asking the model to finish deterministic work with low-quality, brittle tools. A typical case is web operation: observe the page, guess a control, click, fail, and replan. A small change in the DOM, a popup, or button copy sends the whole chain into retries. Every retry consumes context and raises the chance of interruption or lost connection.

    Separate two kinds of work first.

    Type Traits Suitable executor
    Deterministic steps Clear inputs and outputs, unit-testable, retryable and idempotent on failure Scripts, APIs, workflow engines
    Open-ended judgment Needs intent, tradeoffs on exceptions, and written explanation Model and planner

    If browser automation, ad hoc SQL, or “look in the terminal and then decide” becomes the main path, the agent spends most of its compute on environmental noise. A better split is: the model decomposes the goal, selects skills, and explains anomalies; stable interfaces handle queries, writes, and state changes.

    Memory Is Not an Ever-Longer Chat Log

    Useful memory has at least three layers so the full history is not replayed as-is.

    1. Preferences and constraints: Rules the user has explicitly rejected or confirmed, such as bans on certain high-privilege commands, a default output language, or data-masking requirements. Before writing them, trace each rule to the user’s words or an approval record. Do not let the model “summarize” bans that were never confirmed.
    2. Task state: The current goal, completed steps, blocking reasons, and identifiers returned by external systems. Store state in a structured form, not buried in long text.
    3. Reusable skills: Parameter sets, checklists, and call orders that have succeeded more than once. A skill is a process asset, not a copy of one conversation.

    On retrieval, filter by relevance and freshness and inject only the fragments the current step needs. The context window is a workbench, not an archive. The archive lives in external storage; the workbench holds only what this decision requires.

    An illustrative layout, independent of any product:

    1. memory/
    2. preferences.yaml # confirmed constraints, with source and time
    3. tasks/{id}.json # goal, step state, idempotency key
    4. skills/{name}/
    5. spec.md # when it applies, inputs and outputs, failure policy
    6. checks.yaml # success criteria

    Solidifying Skills: Lessons from Failure, Not Unlimited Self-Rewrite

    “Self-iteration” without gates will freeze a one-off success into a permanent process, or spread a bad preference to every task. Split learning into propose, verify, and publish.

    • Propose: Extract repeated patterns from execution logs, such as the same parameters being edited by hand many times, or the same class of error fixed by the same recovery action. A proposal must include trigger conditions and counterexamples.
    • Verify: Replay against a fixed sample set. Pass criteria include correct results, fewer steps, and no new privilege escalation—not “the model feels smoother.”
    • Publish: Skills enter a versioned store and are rollbackable by default. Proposals below the threshold stay drafts and are not injected into the live agent automatically.

    After a user says “do not use high-privilege commands,” write that into the preference layer and reject the matching calls in tool policy. Do not hope the next prompt still remembers. After parameters are tuned by hand, freeze them into the skill spec and configuration instead of letting the model guess at runtime.

    The boundary of self-correction must be explicit: check items and retry policy may be updated; tool privileges may not be widened on their own; safety policy may not be overwritten; a published skill may not be deleted without samples.

    Shrink the Trial-and-Error Loop with Deterministic Tools

    In practice, tighten the loop in this order.

    1. Give high-frequency actions stable interfaces. Queries, submissions, and status polls return structured results and error codes instead of asking the model to read unstructured pages.
    2. Define preconditions and an idempotency key for each skill so submissions are not duplicated and “looks failed, actually succeeded” does not happen.
    3. Classify failures: transient errors that may be retried, business exceptions that need human confirmation, and permission or data errors that must stop. Only the first class enters automatic retry, with configurable count and backoff.
    4. Demote page operations to a supplement. If they are required, lock a strategy for key elements, record failure screenshots or DOM summaries, and rewrite the path as an interface or script once it is stable.

    Planning calls then drop. Context no longer fills with repeated click logs, and a long task is less likely to fail entirely because the UI jittered once.

    Runtime Stability: External State, Recovery, and Observability

    Long tasks break because progress lives only in process memory or a single conversation. Recovery should meet these conditions:

    • After each step, persist state and the identifiers that tie it to external side effects.
    • On restart, continue from the last successful step instead of replaying operations that already had side effects.
    • Separate heartbeat, timeout, and disconnect detection from task state. A lost connection is not a failure; query the external system before deciding on compensation.
    • Logs, metrics, and alerts should cover skill hit rate, retry count, human intervention rate, and tokens per task. Attribute tokens to tasks and skills, or you cannot tell whether waste comes from repeated alignment or tool failure.

    On the deployment side, a container platform can host executors, object storage can hold skill packages and run artifacts, a message queue can decouple planning from execution, and logs plus monitoring alerts can show interruptions and retries. If a team already uses Baidu AI Cloud, those needs can be met by selecting and combining general cloud product categories, without tying business state to one chat session. This describes architectural roles only, not specific interfaces, quotas, or performance commitments.

    Evaluation: Prove “More Stable” Before Claiming “Smarter”

    Track at least these metrics before and after rollout, against a fixed task set:

    • Success rate and step variance when the same task is repeated
    • How often humans must add clarification
    • Tokens and retries per task
    • Preference violations (for example, proposing an operation that was already forbidden)
    • First-pass rate after a skill hit, and the share of calls to the wrong skill

    Without these metrics, “memory got better” is only a feeling. The evaluation set should include changed instructions, tool timeouts, and partial success, not only the happy path.

    A Practical Order of Adoption

    Do not jump to “fully automatic evolution.” A steadier order is: externalize task state and support resume from a checkpoint; then package high-frequency, low-risk flows as skills with checks; then record confirmed preferences and enforce them in the tool layer; only then open skill proposals from logs, and publish them only after human or automated evaluation passes.

    An agent’s advantage is not rediscovering the world every time. It is turning confirmed constraints, paths that already worked, and failure cost already paid into something deterministic the next run can reuse. Memory is for not forgetting, skills are for fewer trials, tools are for fewer hallucinations, and evaluation is for not mistaking a lucky success for capability. Together, long-running stability and token cost have a chance to fall at the same time.