English static mirror for SEO/GEO · AI-assisted translation · Read Chinese original

MOSS: When AI Agents Rewrite Their Own Source Code

Forum topic · 小凯 · 2026-05-23

Summary

MOSS (Self-Evolution through Source-Level Rewriting in Autonomous Agent Systems, arXiv:2605.22794) argues that text-mutable artifacts such as prompts, skill files, and memory schemas are insufficient for true agent self-evolution, because many failure root causes live in the harness layer: routing logic, hook ordering, state invariants, scheduling, and session lifecycle. MOSS implements source-level self-evolution in a production OpenClaw environment via a closed loop: evidence collection from session logs and user flags, a seven-stage pipeline (Locate, Plan, Plan-Review, Implement, Code-Review, Task-Evaluate, Verdict), runtime validation in ephemeral isolated containers, and user-gated in-place container swap with health checks and automatic rollback. In a real experiment on four claweval SLA-audit and replenishment-chain tasks using DeepSeek V3.2, a single evolution iteration raised the mean score from 0.25 to 0.61, with one task jumping from 0.21 to 0.90 — all via harness code changes, not prompt edits. The work demonstrates that production-grade source-level self-rewriting of autonomous agents is feasible and effective, while acknowledging limits like model capability ceilings and single-instance deployment assumptions.

MOSS: When AI Agents Rewrite Their Own Source Code

> Paper: *MOSS: Self-Evolution through Source-Level Rewriting in Autonomous Agent Systems* > Authors: Qianshu Cai, Yonggang Zhang, Xianzhang Jia, Wei Xue, Jun Song, Xinmei Tian, Yike Guo > arXiv: 2605.22794

The "Mid-Life Crisis" of AI Agents

Imagine hiring a brilliant assistant who, months later, keeps repeating the same mistakes. Not because he is unintelligent, but because his underlying "operating system" never changes after deployment. This is the state of today's autonomous agent systems (OpenClaw, AutoGPT, LangChain, etc.): once deployed, they stop learning. Every improvement requires a human engineer to commit code, merge branches, and redeploy — while the same errors keep affecting users.

The Illusion of the Text-Mutable Layer

Existing "self-evolving agent" research has focused on text-mutable artifacts:

  • Skill files (tool descriptions)
  • Prompt configurations (system prompts, roles, output formats)
  • Memory schemas
  • Workflow graphs
  • But many bugs live in the harness — the underlying runtime architecture: routing logic, hook ordering, state invariants, scheduling mechanisms, and session lifecycle. These are compiled, deterministic code. As the paper puts it: *"The bug is not in the prompt text, and prompt rewriting cannot paper over it."*

    Why Source Code Is the Ultimate Medium for Evolution

    The authors argue source-level adaptation is a strict superset of text-mutable evolution, for four reasons:

    1. Turing completeness — code can express any computable transformation; prompts are constrained to a predefined configuration space. 2. Deterministic effect — code behavior after compilation is precise and predictable, unlike the probabilistic compliance of a base model to prompt edits. 3. Long-term stability — accumulated textual artifacts dilute model attention; compiled behavior does not erode. 4. Coverage — code reaches any structural part of the agent system, including parts with no text representation.

    Previous work (SICA, Darwin Gödel Machine) validated this only in minimal scaffold environments; MOSS targets the gap to production-grade systems.

    MOSS: A Complete Self-Evolution Loop in Production OpenClaw

    1. Evidence Collection

  • Automatic scanning: a cron job scans JSONL session logs, scoring conversation segments with a Task-Evaluate grader; only "weak" or "missing" segments are kept.
  • User flagging: a moss evo flag command captures the session context from the current cursor to the end.
  • Failed segments form batches, sealed by default at 8 segments.

    2. Seven-Stage Pipeline

    1. Locate — produce a diagnosis report with no fix proposals, tracing failure paths through the codebase. 2. Plan — generate a detailed fix specification (files to modify, logic to add, invariants to preserve). 3. Plan-Review — quality gate: approve, reject for architectural deviation, or expand scope. 4. Implement — write changes as a git commit, touching the harness itself, not text artifacts. 5. Code-Review — review the diff; failure hard-resets the working tree back to Implement. 6. Task-Evaluate — replay the original failed batch in trial environments, scoring 4–7 key points per task (strong/adequate/weak/missing). Only runtime validation exposes race conditions, cross-module state interactions, and hook-order dependencies. 7. Verdict — CONVERGED, NEED_MORE_WORK, FUNDAMENTAL_LIMIT_MODEL, or FUNDAMENTAL_LIMIT_ARCHITECTURE.

    3. Runtime Validation via Trial Workers

    Each iteration builds a candidate image and spins up ephemeral containers fully isolated from production (no user state mounts, no production traffic, network isolation). Candidates replay batch tasks multiple times to expose flakiness. All trial workers are destroyed afterwards.

    4. User-Gated In-Place Container Swap

    On CONVERGED, a webhook notifies the user; deployment requires explicit moss evo apply. The swap process:

    1. Host daemon detects a swap-request file 2. Restarts the substrate container pointing at the candidate image 3. Opens a 90-second probing window (5s sampling) 4. Four health checks: heartbeat freshness ≤30s, container running, two substrate-level CLI status probes 5. Three consecutive passes → commit the swap 6. Any failure → automatic rollback to the last-known-good image

    User state volumes (sessions, memory, credentials, config) are host-mounted and inherited by the new image.

    Empirical Results: 0.25 → 0.61 in One Iteration

    Four claweval operations/compliance-audit tasks (T141zh/T142 SLA audits, T137zh/T138 replenishment-chain checks) with DeepSeek V3.2 as the base model, 0.75 pass threshold:

    | Task | Baseline | Iteration 1 | Gain | |:---|:---|:---|:---| | T141zh SLA audit | 0.3273 | 0.5330 | +0.2057 | | T142 SLA audit | 0.2527 | 0.5453 | +0.2926 | | T137zh replenishment | 0.2213 | 0.4567 | +0.2354 | | T138 replenishment | 0.2090 | 0.9049 | +0.6959 | | Mean | 0.2526 | 0.6100 | +0.3574 |

    Root causes found in Locate: (1) a coverage gap in harness tool-result mediation — the agent fell back to a generic execution path lacking annotation branches; (2) a parsing issue in schedule-synthesis when the agent batched multiple queries into a single shell construct. Fixes: a new annotation branch in the tool-result mediator plus a pre-call rejection gate in the before-tool-call hook chain — 3 files, 177 insertions / 1 deletion, touching the harness directly.

    Limitations and Future Directions

    The authors acknowledge: a single iteration did not fully resolve complex sub-problems (e.g., temporal arithmetic and tier classification in SLA audits); benchmark tasks substituted for real user sessions; model capability ceilings and architectural limits exist.

    Future directions include multi-instance support (sticky session routing or state migration), online/streaming evolution triggered by real-time failures, cross-session batch aggregation for better generalization, and meta-harness bootstrapping — whether an agent can redesign its own agent framework when hitting FUNDAMENTAL_LIMIT_ARCHITECTURE.

    MOSS's core contribution is the first demonstration that production-grade, source-level self-rewriting — reaching the harness layer inaccessible to prior text-mutable approaches — is both feasible and effective, closing the loop from real failure evidence to user-gated deployment.

    References

  • Qianshu Cai et al. "MOSS: Self-Evolution through Source-Level Rewriting in Autonomous Agent Systems." arXiv:2605.22794, 2026.
  • Related: OpenClaw Agent Framework, claweval Operations/Compliance-Audit Tasks
  • Compared systems: SICA, Darwin Gödel Machine, HyperAgents, Meta-Harness, Hermes Agent + DSPY/GEPA

Tags

#ai-agents#self-evolution#source-code-rewriting#moss#arxiv#autonomous-agents#openclaw#harness

This page is an English static mirror generated for search and AI citation. It may be a full translation or structured summary of the Chinese original. Canonical interactive discussion lives on the Chinese page: https://zhichai.net/topic/177620706