Skip to content

Haochenhust/darwin-evolve

Repository files navigation

darwin-evolve

A self-evolving personal AI agent on Feishu/Lark. It works for you all day, reflects on its mistakes every night, studies new topics on its own, and graduates what it has verified into always-loaded rules, getting a little stronger every day, without waiting for the next model release.

中文文档 / Chinese README

Model + Harness = Agent. Models upgrade every few months; the harness can improve every day, and the agent can do much of that improving itself. This project is a working, fork-ready implementation of that idea, built around the patterns described in Lilian Weng's Harness Engineering for Self-Improvement. (We named it Darwin before discovering that the most radical paper on this route is called the Darwin Gödel Machine; evolution is apparently the metaphor this field cannot escape.)

What you get

  • A Feishu-native personal agent. Each chat group gets an isolated workspace, its own memory file, and its own conversation session. Connects over the official Feishu WebSocket SDK: no public webhook or server required; it runs fine on a laptop behind NAT.
  • A coding-agent harness as the execution engine. Every request is executed by a real coding agent (Claude Code by default, Codex as a drop-in alternative; switch live with /claude / /codex). The agent gets file tools, shell, skills, and a private MCP server for scheduling and messaging.
  • A scheduler the agent can use on itself. Cron, interval, and one-shot tasks run as full agent sessions. The agent can schedule its own future work through the schedule_task tool: self-evolution's time dimension.
  • The evolution engine. Four self-healing system tasks grow a wiki knowledge graph and distill it into behavior:
Task Cadence What it does
system-wiki-reflection daily, 23:00 Reviews the day's conversations: corrections, patterns, evidence chains. Outputs land in exactly four places: wiki nodes, rules, learning agenda items, improvement goals.
system-wiki-learning every 60 min Advances the active learning topics (1 primary + 2 secondary), keeps per-topic save-files, ends each session with cross-topic pollination.
system-wiki-synthesis Sunday, 03:00 Steps back: connects nodes, builds Maps of Content, prunes knowledge that never earned a practice record.
system-wiki-moc-rebuild daily, 01:00 Keeps the graph index and MOCs consistent.
  • Knowledge graduation. Every wiki node carries a confidence level and practice records. Only knowledge with confidence: high and 3+ successful applications graduates into an always-loaded rule. Knowledge must earn its place; half of evolution is forgetting.
  • A safety boundary, learned the hard way. Evolution sessions may read anything but may only write wiki content and proposals. They must never touch source code, hooks, or configuration; see below for the incident that made this rule non-negotiable.
  • Files first. All persistent state is markdown + SQLite + git. No vector database, no private formats. Models are pre-trained on files, bash, and git. Give the agent state in the shape it knows best, and the whole system gets stronger with every model upgrade, for free.

Architecture

graph TD
    U([Feishu]) --> C[Channel layer]
    C --> Q[(Message and task store)]
    Q --> R[Router and trigger]
    R --> A[Agent Runner]
    S[Task scheduler] --> A
    A --> M[(Layered memory files)]
    A --> W[(Wiki knowledge graph)]
    A -->|replies| U
Loading

One Node.js orchestrator process handles intake, routing, and scheduling. Actual agent calls run in a child agent-runner process, which spawns the coding-agent CLI (claude -p --output-format stream-json ...) with the group's directory as its working directory. Two subprocess layers mean a stuck task can never freeze the orchestrator, and killing any layer never hurts other sessions.

The evolution engine on top:

graph TD
    subgraph Inner[Inner loop: reflection]
        A[Daily work] --> B[Nightly reflection]
        B -->|reinforces| A
    end
    subgraph Outer[Outer loop: learning]
        D[Topic study] --> E[Real-task practice]
        E --> F[Evaluation]
        F -->|deepens| D
    end
    B -.->|capability gaps| G[Learning agenda]
    G --> D
    B --> H[(Wiki graph)]
    F --> H
    H --> K{Graduation gate}
    K -->|pass| R2[(Always-loaded rules)]
    K -->|not yet| H
    R2 -->|auto-loaded every session| A
Loading

The safety boundary

Every evolution prompt ships with this block:

This is an evolution session. You may READ any code or configuration, and WRITE only within the wiki (nodes, MOCs, learning states, reflection state, graph index, proposals). You must NEVER create or modify source code, hooks, permission or configuration files; run commands that alter build artifacts; commit code; or change scheduled tasks. If an improvement requires touching any executable surface: write a proposal and stop. A human reviews and implements it.

Why so strict? In an earlier private version of this system, a learning session correctly diagnosed a real weakness (rules loaded into context were not being followed), designed a reasonable fix (a Stop hook that injects a self-check), and then, unattended at night, implemented it by editing the harness's own runtime. The hook trapped the agent in an infinite "check again" loop and deadlocked the entire message pipeline. The diagnosis was right; the fix direction was right; what was wrong was who had permission to merge. Judgment and permission are two different things. The permission layer of this harness is intentionally open (bypassPermissions; it is a single-user system on your own machine), which is exactly why the behavior layer must not be.

Quickstart

Agent-guided install (recommended)

Clone the repo, open it in Claude Code or Codex, and say: "Set this up for me." The agent follows docs/SETUP.md and drives the whole installation: it talks you through the Feishu console, fishes your chat ID out of the message store, interviews you to fill in the persona, and verifies every step. You never have to read the instructions below.

Manual install

Prerequisites: Node 20/22/24+, and an installed, authenticated Claude Code CLI (or Codex CLI).

# 1. Create a Feishu custom app at https://open.feishu.cn
#    Enable the bot capability and IM permissions; get the App ID and Secret.

# 2. Configure
cp .env.example .env      # fill in FEISHU_APP_ID / FEISHU_APP_SECRET / ASSISTANT_NAME

# 3. Install and build (postinstall bootstraps agent-runner)
npm install
npm run build:all
npm test                  # 205 tests, all green

# 4. Guided setup (environment checks, group workspace, service)
npm run setup -- --step verify

# 5. Run
npm run dev               # foreground with hot reload
# or: bash scripts/start.sh   (pm2 daemon; stop.sh / restart.sh / logs.sh)

Then message your bot in Feishu: @Darwin hello. Register additional group chats with npx tsx scripts/register-feishu.ts. Within a day the first reflection will run, and wiki/ will start to grow.

All configuration lives in .env; see .env.example, which documents every variable including engine paths, concurrency caps, stall timeouts, and WIKI_LANGUAGE (the language the evolution loops write in; defaults to English).

Project layout

src/                orchestrator: channels, router, scheduler, system tasks, db
agent-runner/       child process that drives the coding-agent CLI
setup/              stepped setup CLI (environment | groups | register | mounts | service | verify)
scripts/            start/stop/restart/logs (pm2), group registration, deps check
skills/             agent skills shipped with the framework (wiki-note, wiki-search, wiki-graduate, restart)
groups/             per-chat workspaces; CLAUDE.md is the global memory template; customize the persona here
wiki/               the knowledge graph skeleton: nodes/, mocs/, learning/, reflection/, proposals/, graph-index.md

groups/CLAUDE.md ships as a template with a persona placeholder. Who your Darwin is (name, voice, relationship to you) is the one thing this repo deliberately does not decide for you.

Status and scope

This is an extracted, sanitized skeleton of a system that ran in production for one user. Typecheck, build, and all 205 tests are green. It is built for one user by design: fork it, shape it, and let it grow around your own life. Issues and PRs about the evolution mechanics are welcome; feature requests to make it a multi-tenant platform are out of scope.

Credits

  • Derived from an MIT-licensed personal-assistant project by Gavriel (see LICENSE); the workspace-per-chat foundation traces back to that lineage.
  • The evolution engine's framing owes much to Lilian Weng's Harness Engineering for Self-Improvement, and to the research it surveys (ACE, Self-Harness, Darwin Gödel Machine, and friends).
  • Built and extracted with Claude Code.

License

MIT. See LICENSE.

About

A self-evolving personal AI agent on Feishu/Lark: nightly reflection, autonomous learning, and knowledge graduation on top of a coding-agent harness (Claude Code / Codex)

Topics

Resources

License

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors