๐Ÿงฌ Geneclaw โ€” Self-Evolving AI Agent Framework

Website Python License GEP Version Upstream

geneclaw.ai ยท GitHub ยท Protocol Spec ยท Quickstart

Built on nanobot โ€” adds closed-loop self-improvement via the Geneclaw Evolution Protocol (GEP)

--- **Geneclaw** extends the ultra-lightweight [nanobot](https://github.com/HKUDS/nanobot) AI agent with a **self-evolution engine** โ€” enabling the agent to observe its own failures, diagnose root causes, propose constrained fixes, and safely apply them behind a multi-layered gatekeeper. **Everything is dry-run by default. Nothing is applied without explicit human approval.** > ๐Ÿ“– Visit **[geneclaw.ai](https://geneclaw.ai)** for documentation, demos, and community resources. ## Key Capabilities | Capability | Description | |-----------|-------------| | **Observability** | JSONL event recording for every agent interaction (inbound, tools, errors, outbound) | | **Diagnosis** | Heuristic failure analysis + optional LLM-assisted root cause identification | | **Evolution Proposals** | Structured JSON proposals with unified diffs, risk levels, and rollback plans | | **Gatekeeper** | 5-layer safety validation (allowlist, denylist, diff size, secret scan, code pattern detection) | | **Safe Apply** | Git-branched patch application with automated test execution and rollback on failure | | **Autopilot** | Configurable multi-cycle evolution loop with risk-based auto-approve | | **Dashboard** | Read-only Streamlit web dashboard for evolution audit, timeline, and benchmark visualisation | | **Benchmarks** | Pipeline performance measurement with synthetic workloads and JSONL persistence | | **Event Store** | Append-only evolution lifecycle logging with secret redaction | | **Reporting** | Aggregated pipeline statistics (table + JSON output) | | **Doctor** | Read-only health checks with actionable suggestions | ## Architecture ``` Geneclaw Evolution Protocol (GEP v0) โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ Observe โ”€โ”€โ†’ Diagnose โ”€โ”€โ†’ Propose โ”€โ”€โ†’ Gate โ”€โ”€โ†’ Apply โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ recorder evolver evolver gatekeeper apply โ”‚ โ”‚ (JSONL) (heuristic (JSON + (5 checks) (git + โ”‚ โ”‚ + LLM) diff) pytest) โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ event_store โ”‚ โ”‚ (audit log) โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€โ”€ autopilot (multi-cycle controller) โ”‚ โ”œโ”€โ”€โ”€ dashboard (Streamlit read-only visualisation) โ”‚ โ”œโ”€โ”€โ”€ benchmarks (performance measurement) โ”‚ โ”œโ”€โ”€โ”€ doctor (health checks) โ”‚ โ””โ”€โ”€โ”€ report (statistics aggregation) โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ nanobot (upstream) โ”‚ โ”‚ agent/loop.py โ†โ†’ channels โ†โ†’ providers โ†โ†’ tools โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` ## Project Structure ``` Clawland-AI/Geneclaw โ”œโ”€โ”€ geneclaw/ # GEP v0 evolution engine โ”‚ โ”œโ”€โ”€ __init__.py # Package metadata (v0.1.0) โ”‚ โ”œโ”€โ”€ models.py # RunEvent, EvolutionProposal, EvoEvent โ”‚ โ”œโ”€โ”€ redact.py # Secret redaction (regex-based) โ”‚ โ”œโ”€โ”€ recorder.py # JSONL run event recorder โ”‚ โ”œโ”€โ”€ evolver.py # Heuristic + LLM proposal generator โ”‚ โ”œโ”€โ”€ gatekeeper.py # Safety validation (5 checks) โ”‚ โ”œโ”€โ”€ apply.py # Git-branched diff application โ”‚ โ”œโ”€โ”€ event_store.py # Append-only evolution event log โ”‚ โ”œโ”€โ”€ report.py # Statistics aggregation โ”‚ โ”œโ”€โ”€ doctor.py # Health checks โ”‚ โ”œโ”€โ”€ autopilot.py # Multi-cycle evolution controller โ”‚ โ”œโ”€โ”€ benchmarks.py # Pipeline performance benchmarks โ”‚ โ”œโ”€โ”€ cli.py # Typer CLI subcommands โ”‚ โ””โ”€โ”€ dashboard/ # Streamlit dashboard (read-only) โ”‚ โ”œโ”€โ”€ app.py # Streamlit entry point โ”‚ โ”œโ”€โ”€ loader.py # Data loading, filtering, redaction โ”‚ โ””โ”€โ”€ views/ # Overview, Timeline, Audit, Benchmarks โ”œโ”€โ”€ nanobot/ # Upstream agent framework (HKUDS/nanobot) โ”‚ โ”œโ”€โ”€ agent/ # Core agent loop + tools โ”‚ โ”œโ”€โ”€ channels/ # Chat platform integrations โ”‚ โ”œโ”€โ”€ providers/ # LLM providers โ”‚ โ”œโ”€โ”€ config/ # Configuration schema โ”‚ โ””โ”€โ”€ cli/ # Main CLI entry point โ”œโ”€โ”€ tests/ # 123 tests across 8 files โ”‚ โ”œโ”€โ”€ test_geneclaw_recorder.py โ”‚ โ”œโ”€โ”€ test_geneclaw_evolver.py โ”‚ โ”œโ”€โ”€ test_geneclaw_gatekeeper.py โ”‚ โ”œโ”€โ”€ test_geneclaw_doctor.py โ”‚ โ”œโ”€โ”€ test_geneclaw_events.py โ”‚ โ”œโ”€โ”€ test_geneclaw_autopilot.py โ”‚ โ””โ”€โ”€ test_geneclaw_dashboard.py โ”œโ”€โ”€ docs/ โ”‚ โ”œโ”€โ”€ specs/GEP-v0.md # Protocol specification โ”‚ โ”œโ”€โ”€ quickstart/Geneclaw-Runbook.md โ”‚ โ”œโ”€โ”€ ops/ โ”‚ โ”‚ โ”œโ”€โ”€ github-governance.md # Branch protection & PR checklist โ”‚ โ”‚ โ”œโ”€โ”€ release-runbook.md # Tagging & release process โ”‚ โ”‚ โ”œโ”€โ”€ llm-provider-setup.md # Secure LLM provider configuration โ”‚ โ”‚ โ”œโ”€โ”€ first-real-proposal.md # Guide: first non-no-op proposal โ”‚ โ”‚ โ”œโ”€โ”€ upstream-sync.md # Upstream merge strategy โ”‚ โ”‚ โ”œโ”€โ”€ dashboard-runbook.md # Dashboard operations โ”‚ โ”‚ โ””โ”€โ”€ first-live-run-*.md # Audit records โ”‚ โ””โ”€โ”€ devlog/ # Daily development logs โ””โ”€โ”€ .github/ โ”œโ”€โ”€ workflows/ci.yml # CI pipeline โ””โ”€โ”€ pull_request_template.md ``` ## Install **From source (recommended)** ```bash git clone https://github.com/Clawland-AI/Geneclaw.git cd Geneclaw pip install -e ".[dev]" ``` **With Dashboard support** ```bash pip install -e ".[dev,dashboard]" ``` **Add upstream remote** (for syncing with nanobot) ```bash git remote add upstream https://github.com/HKUDS/nanobot.git ``` ## Quick Start ### 1. Initialize ```bash nanobot onboard ``` ### 2. Enable Geneclaw Add or merge into `~/.nanobot/config.json`: ```json { "geneclaw": { "enabled": true, "redactEnabled": true, "allowApplyDefault": false, "allowlistPaths": ["geneclaw/", "docs/"], "denylistPaths": [".env", "secrets/", ".git/", "config.json"], "maxPatchLines": 500 } } ``` ### 3. Verify ```bash nanobot geneclaw doctor ``` ### 4. Chat (generates run events) ```bash nanobot agent -m "Hello, what tools do you have?" ``` ### 5. Generate evolution proposal ```bash nanobot geneclaw evolve --dry-run ``` ### 6. View statistics ```bash nanobot geneclaw report ``` ### 7. Launch Dashboard ```bash nanobot geneclaw dashboard # opens http://localhost:8501 ``` ## CLI Reference All commands are under `nanobot geneclaw`: | Command | Description | |---------|-------------| | `nanobot geneclaw doctor` | Health checks โ€” config, paths, permissions | | `nanobot geneclaw status` | Current state โ€” enabled, sessions, last run | | `nanobot geneclaw evolve --dry-run` | Generate evolution proposal (dry-run default) | | `nanobot geneclaw evolve --apply` | Generate and apply proposal (requires config) | | `nanobot geneclaw apply ` | Apply a saved proposal file | | `nanobot geneclaw report` | Pipeline statistics (table) | | `nanobot geneclaw report --format json` | Pipeline statistics (JSON) | | `nanobot geneclaw autopilot` | Multi-cycle evolution loop | | `nanobot geneclaw benchmark` | Pipeline performance benchmarks | | `nanobot geneclaw benchmark --save` | Run benchmarks and persist results to JSONL | | `nanobot geneclaw dashboard` | Launch Streamlit dashboard (read-only) | ### Autopilot Options ```bash nanobot geneclaw autopilot \ --max-cycles 5 \ --cooldown 10 \ --auto-approve low \ --dry-run \ --format table ``` | Option | Default | Description | |--------|---------|-------------| | `--max-cycles` | 3 | Maximum evolution cycles | | `--cooldown` | 5.0 | Seconds between cycles | | `--auto-approve` | low | Risk threshold for auto-approve (`none`, `low`) | | `--dry-run/--apply` | dry-run | Apply mode requires `allow_apply_default=true` | | `--stop-on-failure/--continue` | stop | Halt on first apply failure | | `--format` | table | Output format (`table`, `json`) | ### Benchmark Options ```bash nanobot geneclaw benchmark \ --event-counts 100,500,1000 \ --gate-iterations 100 \ --save \ --format table ``` ### Dashboard Options ```bash nanobot geneclaw dashboard \ --port 8501 \ --events /path/to/events.jsonl \ --benchmarks /path/to/benchmarks.jsonl ``` The dashboard provides four read-only views: **Overview** (KPIs, risk distribution), **Event Timeline** (charts with time filters), **Proposal Audit** (per-proposal metadata inspection), and **Benchmarks** (performance trends). ## Configuration The `geneclaw` section in `~/.nanobot/config.json`: | Field | Type | Default | Description | |-------|------|---------|-------------| | `enabled` | bool | `false` | Enable geneclaw observability + evolution | | `logMaxChars` | int | `500` | Max chars per event preview | | `redactEnabled` | bool | `true` | Redact secrets in all logs | | `allowApplyDefault` | bool | `false` | Must be `true` to allow `--apply` | | `allowlistPaths` | list | `["geneclaw/", "nanobot/", "tests/", "docs/"]` | Paths proposals may modify | | `denylistPaths` | list | `[".env", "secrets/", ".git/", "config.json"]` | Paths that are always blocked | | `maxPatchLines` | int | `500` | Maximum diff lines allowed | ## Safety Model Geneclaw enforces multiple layers of protection: ### 1. Dry-Run Default All commands default to `--dry-run`. Proposals are generated and validated but never applied without explicit `--apply` flag AND `allowApplyDefault=true` in config. ### 2. Gatekeeper (5 Checks) Every proposal must pass all five checks before application: | Check | What it does | |-------|-------------| | **Path Allowlist** | All `files_touched` must start with an allowed prefix | | **Path Denylist** | No file may match a denied path (`.env`, `secrets/`, etc.) | | **Diff Size Limit** | Line count must not exceed `maxPatchLines` | | **Secret Scan** | Diff is scanned for API keys, tokens, PEM keys | | **Code Pattern Scan** | Detects `eval()`, `exec()`, `os.system()`, `subprocess.call()` | ### 3. Git Safety - Creates a dedicated `evo/-` branch - Runs `git apply --check` before actual application - Executes `pytest -q` after patching - Automatic rollback on test failure (branch deleted, previous state restored) ### 4. Secret Redaction All event logs (run events + evolution events) pass through regex-based redaction before being written to disk. Patterns include API keys, tokens, passwords, PEM blocks, and Bearer tokens. The dashboard re-applies redaction at the display layer. ### 5. Recommended Allowlist Strategy Start minimal and expand only after successful, reviewed evolution cycles: | Phase | Allowlist | When | |-------|-----------|------| | **Bootstrap** | `geneclaw/`, `docs/` | Day 1 | | **Expanded** | + `tests/` | After 5+ reviewed proposals | | **Full** | + `nanobot/` | After 20+ reviewed proposals | See `docs/specs/GEP-v0.md` Section 10 for the complete strategy. ## Slash Command When chatting with the agent, use `/evolve` to trigger an in-conversation evolution analysis: ``` You: /evolve Bot: Evolution analysis started in background. Results will be posted shortly. Bot: [Evolution Proposal: ...] (always dry-run, never auto-applies) ``` ## Data Layout All runtime data lives under the nanobot workspace (`~/.nanobot/workspace/`): ``` ~/.nanobot/workspace/geneclaw/ โ”œโ”€โ”€ runs/ # Run event logs (per session, per day) โ”‚ โ””โ”€โ”€ / โ”‚ โ””โ”€โ”€ YYYYMMDD.jsonl โ”œโ”€โ”€ events/ # Evolution lifecycle events โ”‚ โ””โ”€โ”€ events.jsonl โ”œโ”€โ”€ proposals/ # Generated proposals โ”‚ โ””โ”€โ”€ proposal_YYYYMMDD_HHMMSS.json โ””โ”€โ”€ benchmarks/ # Performance benchmark results โ””โ”€โ”€ benchmarks.jsonl ``` ## Testing ```bash # Run all geneclaw tests pytest tests/test_geneclaw_*.py -q # Run full test suite pytest -q ``` Current test coverage: **123 tests** across 8 test files. ## Development ### Upstream Sync ```bash git fetch upstream git merge upstream/main --no-edit # resolve conflicts if any ``` See [docs/ops/upstream-sync.md](docs/ops/upstream-sync.md) for the complete strategy. ### Branch Naming | Prefix | Purpose | |--------|---------| | `feat/` | New features | | `fix/` | Bug fixes | | `chore/` | Maintenance | | `evo/-` | Auto-generated by evolution engine | ### Commit Convention ``` feat(geneclaw): add autopilot controller Evo-Event-ID: abc123 Risk-Level: low Tests: pytest tests/test_geneclaw_autopilot.py -q ``` ## Documentation | Document | Description | |----------|-------------| | [GEP v0 Protocol Specification](docs/specs/GEP-v0.md) | Core protocol design | | [Operator Runbook](docs/quickstart/Geneclaw-Runbook.md) | Day-to-day operations guide | | [Dashboard Runbook](docs/ops/dashboard-runbook.md) | Dashboard setup & usage | | [GitHub Governance](docs/ops/github-governance.md) | Branch protection & PR review | | [Release Runbook](docs/ops/release-runbook.md) | Tagging, releases, rollback | | [LLM Provider Setup](docs/ops/llm-provider-setup.md) | Secure API key configuration | | [First Real Proposal](docs/ops/first-real-proposal.md) | Generating your first proposal | | [Upstream Sync](docs/ops/upstream-sync.md) | Merge strategy for HKUDS/nanobot | | [First Live Run Audit](docs/ops/first-live-run-2026-02-18.md) | Audit trail | | [Changelog](CHANGELOG.md) | Release history | | [Development Log](docs/devlog/2026-02-18.md) | Daily engineering notes | ## Repository | | | |-|-| | **Website** | [geneclaw.ai](https://geneclaw.ai) | | **Origin** | [Clawland-AI/Geneclaw](https://github.com/Clawland-AI/Geneclaw) | | **Upstream** | [HKUDS/nanobot](https://github.com/HKUDS/nanobot) | | **Organization** | [Clawland-AI](https://github.com/Clawland-AI) | ## License MIT โ€” see [LICENSE](LICENSE).

Built by Clawland-AI ยท Powered by HKUDS/nanobot ยท geneclaw.ai