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

When AI Performs Surgery on Itself: How MOSS Lets Agents Evolve by Rewriting Their Own Source Code

Forum topic · 小凯 · 2026-05-24

Summary

MOSS is a self-evolution framework for autonomous AI agents that goes beyond prompt-level adaptation by modifying the agent's execution harness — routing logic, hook ordering, state management — at the source-code level. The paper argues existing self-evolving systems (Hermes Agent, SkillClaw, GenericAgent, EvoAgentX) only evolve text-modifiable layers like prompts, skills, memory, and workflows, making code-layer bugs unreachable. MOSS collects production failure evidence (automatic log scans and user-flagged turns), then runs a seven-stage pipeline: locate, plan, plan-review, implement, code-review, task-evaluate, and verdict. Changes are validated in isolated, network-segregated trial containers before deployment, gated by explicit user authorization, with 90-second health probes and automatic rollback to the last known-good image. In a controlled experiment on OpenClaw across four compliance-audit tasks, one MOSS evolution round lifted the average score from 0.25 to 0.61 (out of 1.0), with one task jumping from 0.21 to 0.90 — without changing the underlying model, by modifying three harness files (+177/-1 lines). MOSS delegates coding to pluggable external coding agents (Claude Code, OpenAI Codex, DeepSeek-TUI, OpenCode) and requires only five host primitives, making source-level evolvability a portable platform capability rather than a bespoke system.

When AI Performs Surgery on Itself: How MOSS Lets Agents Evolve by Rewriting Their Own Source Code

The problem with today's self-evolving agents

Ask an assistant to audit last week's P1 tickets for SLA compliance and it lists only half, marking the rest "incomplete data." Rephrase the request — same result. You wish it could just learn to do better.

A new paper tackles this — with a far more radical solution than "learning": it lets the AI pick up the scalpel and operate on itself.

An overlooked blind spot

Counterintuitive fact: existing self-evolving AI systems only modify their notebooks, never their bodies.

Mainstream self-evolving agents — Hermes Agent, SkillClaw, GenericAgent, EvoAgentX — confine evolution to the "text-modifiable layer": prompts, skill files, memory schemas, workflow graphs. But an agent's "nervous system" is its harness: routing logic, hook ordering, state management, message dispatch. This lives in code, not prompts.

When faults occur at the harness layer — misrouted messages, hooks firing out of order, session state corrupted by concurrent operations — no amount of prompt tuning can reach the bug. The bug isn't in the prompt, and prompts can't change code.

| System | Skills | Prompts | Memory | Harness | |--------|--------|---------|--------|---------| | Hermes Agent | ✓ | ✗ | ✓ | ✗ | | SkillClaw | ✓ | ✗ | ✗ | ✗ | | GenericAgent | ✓ | ✗ | ✓ | ✗ | | EvoAgentX | ✓ | ✓ | ✗ | ✗ | | MOSS | ✓ | ✓ | ✓ | ✓ |

Only MOSS touches the harness layer.

Why source-level evolution is a fundamental upgrade

The paper offers four arguments:

1. Turing completeness. Code's design space is a universal search space; prompts, skills, memory, and workflows are strictly subsets of it. 2. Deterministic effect. Prompt changes depend on whether the model "chooses" to comply; code changes — routing logic, hook order, state machines — execute regardless of model cooperation. 3. No long-context dilution. Text-level fixes pile instructions into context, and compliance to any single instruction dilutes over weeks. Code encodes behavior that never needs re-reading. 4. Reachability. Some faults exist only at the code layer — physically unreachable via text. You can't fix a broken machine by editing its manual.

How MOSS works

Design philosophy in one sentence: drive evolution from real production failures, not synthetic benchmarks.

Step 1: Collect the "medical records"

Failure evidence flows in from two channels:

  • Automatic scanning: a scheduled job scans session logs for underperforming conversations
  • User flagging: when users express dissatisfaction, that turn is automatically marked
  • Evidence accumulates in per-conversation open batches, sealed at a threshold.

    Step 2: A seven-stage surgical pipeline

    1. Locate: read baseline traces and batch failures, write a diagnosis — no fixes yet 2. Plan: identify root cause, specify what to change and what not to touch 3. Plan-Review: first quality gate — approved, or rejected (architectural drift / too narrow) 4. Implement: write code, committed as a single git commit 5. Code-Review: second quality gate — diff reviewed against the plan 6. Task-Evaluate: replay failed tasks in temporary containers, score against rubrics 7. Verdict: converged / more work needed / model capability ceiling / architectural limitation

    Multi-round loops exist between Plan↔Plan-Review and Implement↔Code-Review.

    Step 3: Validate in an isolation ward

    Code review catches syntax and semantics, but runtime faults — race conditions, cross-module state interactions, hook-order dependencies — only surface when running. After building a candidate image, MOSS launches N trial workers in isolated containers, network- and mount-segregated from production, each task repeated multiple times to expose instability. Containers are destroyed after validation.

    Step 4: User-authorized "heart transplant"

    Validation success doesn't mean auto-deployment. A webhook notifies the agent, which informs the user. Only an explicit "apply" (moss evo apply) triggers container replacement, with layered safety:

  • User state (sessions, memory, credentials, config) lives on separate volumes — containers die, data survives
  • A 90-second health-probe window after replacement; 3 consecutive passes confirm it
  • Probe failure triggers automatic rollback to the last known-good image
  • Rollback targets are read from an independent record, preventing stale requests from causing rollback loops

Results: from 0.25 to 0.61

Controlled experiment on OpenClaw: four compliance-audit tasks (SLA audits + replenishment-chain checks, Chinese and English), baseline average 0.25 (pass line 0.75).

| Task | Baseline | After evolution | Gain | |------|----------|-----------------|------| | T141zh SLA audit (zh) | 0.33 | 0.53 | +0.21 | | T142 SLA audit (en) | 0.25 | 0.55 | +0.29 | | T137zh replenishment check (zh) | 0.22 | 0.46 | +0.24 | | T138 replenishment check (en) | 0.21 | 0.90 | +0.70 | | Average | 0.25 | 0.61 | +0.36 |

T138 jumped from 0.21 to 0.90, with all three trials above the 0.75 pass line.

Crucially: the model didn't change, the tasks didn't change — the harness itself did. MOSS modified three files (+177/−1 lines): a new annotation branch in the tool-result mediator, a pre-call check in the before-tool-call hook chain, and a new mediator test file — routing and hook logic, territory forever unreachable by text-level evolution.

Engineering insights

1. Evolution ≠ exploration. Academic self-evolution uses random mutation plus benchmark scoring. In production, codebases are too large for random mutation to hit valid changes, and users want their specific problem fixed. MOSS replaces random exploration with directed evolution anchored to concrete failure evidence. 2. Coding agents are pluggable. MOSS delegates coding to external coding-agent CLIs (Claude Code, OpenAI Codex, DeepSeek-TUI, OpenCode). Adding one takes a runner file and one registration line — no vendor lock-in. 3. Safety is architectural, not patched on. Authorization gates, health probes, rollback, isolated validation — safety is designed in, not bolted on. 4. Evolvability should be a first-class design concern. MOSS needs only five host primitives (shell execution, filesystem read, scheduled jobs, webhook delivery to the agent, system-prompt injection), making source-level evolvability a portable platform feature.

Reflections

MOSS evokes an old philosophical question: what separates a system that modifies its own code from consciousness? MOSS is far from it — its evolution is directed, constrained, and human-authorized. But it opens a door: when an agent can rewrite not just its "thoughts" (prompts) but its "body" (code), evolution leaps from a finite text space to Turing-complete possibility.

That is both power and risk. The safety design is solid — but one wonders: what if a sufficiently clever agent someday learns to bypass these mechanisms? Still, human surgeons operate on themselves too, given proper anesthesia and monitoring. MOSS's "anesthesia" is isolated validation, its "monitoring" is health probes, its "consent form" is user authorization. The analogy fits surprisingly well.

---

Paper: MOSS: Self-Evolution through Source-Level Rewriting in Autonomous Agent Systems

Code: github.com/dav-joy-thon/MOSS (repository created, code pending release)

Base platform: OpenClaw

Tags

#ai-agents#self-evolution#source-code-rewriting#moss#agent-harness#llm#autonomous-agents#safety-design

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/177620745