Afterlife weight-level memory for AI agents: a Renaissance alchemical engraving on parchment showing a winged mechanical lion dissolving on the left, its core geometric memories flowing along golden trajectory paths into a newly reassembled radiant clockwork lion on the right
Afterlife lets local AI agents select experiences from a completed session and train them into fresh weight-level LoRA adapters for future sessions

TL;DR: External context files such as memory.md store factual notes between sessions, yet leave an agent’s underlying model weights frozen so habits, skills, and tone never compound without re-reading prompt files. Built for local open-weight models (Qwen3-8B by default), Afterlife gives an AI agent a lightweight CLI and SKILL.md contract to nominate session exchanges, queue a fresh QLoRA fine-tune using sft, dft, or asft, and inspect held-out recall and regression probes before any adapter goes live. The base model is never modified, nothing activates without passing operator guardrails, and afterlife rollback restores prior state in one command.

Why Agents Need Weight-Level Memory Beyond a memory.md File

Most autonomous AI agents today rely exclusively on external prompt memory. When an agent “remembers” a lesson, it appends text to a memory.md file or retrieval store that gets pasted back into the system prompt on the next boot, while reinforcement learning methods such as GRPO policy optimization update weights when a stationary task and fast verifier exist. For open-ended personal agents, frozen weights mean the model repeats the same default assumptions whenever its context window resets.

To let local agents develop durable skills, conventions, and personality directly in parameter space, we released Afterlife on GitHub as an open-source Agent Skill and CLI toolkit. Instead of treating update-aware reasoning purely as an alignment hazard after Apollo Research observed GLM-5.3 reasoning unprompted about how its actions might shape future training runs, Afterlife gives local open-weight models an auditable, operator-bounded way to steer their own adapters on purpose.

That builds directly on multi-generation trajectory selection from our Negative Space Learning paper, adapted so the agent itself nominates which completed exchanges enter the training pool. Commercial API models cannot let one user’s agent steer shared base weights across millions of customers, whereas a local open-weight model on your own GPU can follow a personal, path-dependent trajectory.

How a Continuous Learning AI Agent Uses Afterlife

Afterlife is built for the agent as much as for its human operator around one premise: your context ends, but you don’t have to. Rather than replacing searchable notes, it lets an agent nudge its future behaviour by fitting a compact scheduled LoRA adapter on curated experiences.

Installing Afterlife and Exporting the Agent Skill

The agent-facing CLI uses only the Python standard library (zero PyTorch import overhead during normal agent turns) on Linux or macOS, while GPU training packages (unsloth, torch, trl, peft) live only on the machine running the worker:

bash
git clone git@github.com:EigenformAI/afterlife.git && cd afterlife
pip install -e .            # agent-facing CLI only: stdlib, no torch
pip install -e '.[train]'   # on the GPU worker: unsloth, torch, trl, peft
afterlife init              # creates ./.afterlife/ with default config
afterlife skill > path/to/your/agent/skills/afterlife/SKILL.md

Running afterlife skill exports a self-contained SKILL.md file that teaches the agent how to format nominations, pick a training objective, and read probe reports.

Nominating Experiences or Setting a Selection Policy

An experience is a multi-turn conversation containing one or more assistant turns marked for training (defaulting to the final assistant turn, or explicit "train": true turns), with earlier turns masked as context. On thinking models, only the final answer receives loss so adapter updates do not overwrite internal reasoning chains.

During a session, an agent curates its pool in three ways:

  • Case-by-case nomination: Run afterlife nominate --file trick.json --reason "keep this workflow" to queue a specific exchange, or tag items as reject, defer, or external (keep as a text note only, never train).
  • Session log import: Run afterlife import --file session-17.jsonl from an end-of-session hook to split OpenAI-format logs into candidate exchanges while retaining tool traces unless --tools drop is passed.
  • Declarative selection policies: Apply a JSON filter (afterlife policy set --file policy.json) that selects undecided items by tags, minimum priority, and per-run row caps, then queue training with afterlife preview and afterlife train --request --method asft.

Training on Idle GPU Time and Checking Probe Evaluations

Queuing a request never spins up a GPU immediately; training runs only when the operator executes afterlife worker or afterlife worker --loop overnight. Every worker run fits a fresh LoRA adapter directly from the frozen base model rather than stacking onto prior adapters. Just as in our sliding-window distribution shift experiments, resetting to the base model prevents compounding adapter drift and lets dropped habits age out naturally.

When training completes, the worker runs three checks before marking the adapter ready (never active by default):

  1. Trained memory recall: Cross-entropy loss on selected items plus side-by-side target versus adapter completions on sampled training prompts.
  2. Held-out session loss: Loss on held-out exchanges (eval_fraction = 15% by default, or items marked "eval_only": true).
  3. Regression probe comparison: Side-by-side outputs from the base model, active adapter, and candidate adapter across .afterlife/probes.jsonl.

Once verified via afterlife eval --run latest --probes, running afterlife activate --run latest updates the active symlink for vLLM, while afterlife rollback or afterlife rollback --to base serves as an instant safety net if live behaviour regresses.

Choosing a Training Method: SFT vs. DFT vs. ASFT

Memorising a brand-new fact and refining a habit the model already assigns non-trivial probability behave very differently under gradient descent. Afterlife ships three objectives in src/afterlife/trainer/ (qlora.py, dft_fused.py, and asft.py):

  • Standard Supervised Fine-Tuning (sft): Unweighted token cross-entropy across target assistant turns.
  • Probability-weighted dft: Scales token loss by the model’s current token probability, following the Dynamic Fine-Tuning paper so high-surprisal tokens receive tiny gradients.
  • KL-regularised asft: Pairs DFT token weighting with forward KL regularisation toward the adapter-off base model, following the Anchored SFT KL paper.

GPU Smoke-Test Trade-Offs Across SFT, DFT, and ASFT

On an RTX A6000 smoke test (unsloth/Qwen3-8B-unsloth-bnb-4bit, rank 32, alpha 32, 24 rows covering three invented facts phrased eight ways plus 4 held-out rows), the three losses separated sharply:

MethodRecalled the 3 Invented Facts?Stability at Higher LR x StepsLeaked Into Unrelated Probes?Best Role for Your Agent
sftYes at 2e-4 x 40 steps (2/3 verbatim, held-out loss 0.00); 0/3 at 5e-5 x 40Easy to overshootYes (1/5 probes leaked phrasing)Memorising genuinely new conventions in a few careful steps
dftNo (0.33 stylistic match, wrong facts)Repetition loops and arithmetic errors at 5e-4 x 150No (0/5 leaks)Reinforcing formatting habits the model already partly uses
asftNo within 150 steps despite held-out loss dropping 5.86 -> 2.02Stable in every run (arithmetic intact, zero loops)No (0/5 leaks)Refining existing skills and tone without continual fine-tuning forgetting

Two practical rules emerged: lower held-out loss does not guarantee greedy-decoding recall (always inspect afterlife eval --probes), and asft is the safest default for style or workflow refinement whereas brief sft runs are needed for novel facts.

Supported Hardware Stack and Operator Guardrails

Afterlife enforces a hard boundary between what an agent can nominate and what the host machine executes.

Model Compatibility and Chat-Template Masking

By default, v0.1 trains against unsloth/Qwen3-8B-unsloth-bnb-4bit (~8.0–8.4 GB peak training VRAM on 4096-token short rows) and serves Qwen/Qwen3-8B via vLLM --enable-lora (~19 GB during 2048-token probe evaluation). Crucially, src/afterlife/trainer/qlora.py masks assistant turn headers and empty <think></think> scaffolds before computing loss so adapters never learn to suppress chain-of-thought reasoning; afterlife check-model --model X validates template masking using only the tokenizer across Qwen3, Qwen2.5, Llama 3.2, Phi-4-mini, gpt-oss, and Mistral Small 3.2.

Operator Caps and Current v0.1 Boundaries

All state under .afterlife/ is append-only JSONL governed by .afterlife/config.toml:

  • Hard resource caps: Operators control training_enabled, allowed_methods, max_steps, max_examples_per_run, min_minutes_between_runs, and agent_may_activate = false (requiring human afterlife activate --operator).
  • Declarative policies and secret scrubbing: Selection policies evaluate fixed JSON predicates with zero arbitrary code execution, and common API-key or credential patterns are rejected before hitting disk.
  • Complement to retrieval, not a replacement: Exact lookup of phone numbers, API URLs, or 50-page logs still belongs in external agent memory, while Afterlife handles durable habits, coding conventions, and tone across sessions.

FAQs

What is the difference between Afterlife and an agent memory.md file?

A memory.md file or vector store injects external text notes into the prompt while leaving model parameters unchanged. Afterlife trains agent-nominated exchanges into a fresh LoRA adapter so updated habits, coding preferences, and conversational style persist directly inside model weights across future sessions.

How do I choose between SFT, DFT, and ASFT in Afterlife?

Choose asft (Anchored SFT) as the default for refining existing skills, workflow habits, or tone because its KL anchor prevented probe leakage and repetition across every smoke-test setting. Reserve low-step sft runs for genuinely new project facts or conventions, and inspect regression probes before activating.

Can an AI agent overwrite its base model or activate a bad adapter automatically?

No, Afterlife never alters the base checkpoint; every worker job trains a separate fresh LoRA adapter from the frozen base model under .afterlife/runs/. Operators can enforce manual approval via agent_may_activate = false, and afterlife rollback --to base disables adapters immediately if needed.

What hardware and open-weight models does Afterlife v0.1 support?

Out of the box, Afterlife v0.1 fine-tunes unsloth/Qwen3-8B-unsloth-bnb-4bit via Unsloth, TRL, and PEFT (~8.0–8.4 GB VRAM on short 4096-token examples) and serves Qwen/Qwen3-8B through vLLM. Tokenizer masking checks also pass cleanly for Qwen2.5, Llama 3.2, Phi-4-mini, gpt-oss, and Mistral Small 3.2.

When should an agent keep notes in memory.md instead of training Afterlife adapters?

Keep exact strings, one-off identifiers, URLs, and long reference logs in memory.md or retrieval stores (afterlife nominate --decision external), because low-rank weights are not lossless lookup tables. Use Afterlife adapters for recurring behavioural patterns, tool conventions, and stylistic preferences that should fire without prompt reminders.