Build Persistent AI Agents with OpenClaw: A 40‑Day Hands‑On Guide

This article details a 40‑day workflow for creating and evolving eight continuous‑running OpenClaw AI agents using a three‑layer markdown file system—Identity, Operations, and Knowledge—showing how to give agents long‑term memory, self‑healing checks, and coordinated collaboration without databases or message queues.

ShiZhen AI
ShiZhen AI
ShiZhen AI
Build Persistent AI Agents with OpenClaw: A 40‑Day Hands‑On Guide

Why AI Agents Forget

Most AI agents lose context after each session because they store all information in the prompt; when the session ends the memory is cleared. Shubham’s approach writes memory to a file system, giving agents long‑term memory and dramatically improving output quality after 40 days.

Core Architecture: Three‑Layer File System

The system consists entirely of Markdown files organized into three layers.

Identity Layer : SOUL.md (agent personality), IDENTITY.md (quick reference card), USER.md (user preferences).

Operations Layer : AGENTS.md (behavior rules), HEARTBEAT.md (self‑check), plus task‑specific guides.

Knowledge Layer : MEMORY.md (curated long‑term memory), memory/YYYY‑MM‑DD.md (daily logs), shared-context/ (cross‑agent knowledge).

Identity Layer Details

SOUL.md defines the agent’s core identity. Example: an agent named Dwight (inspired by the TV character) is described as meticulous and fact‑driven. The file should stay under 60 lines to limit prompt size.

# SOUL.md

## Core Identity
[Agent Name] — [One‑sentence description]. [Optional TV character]

## Your Role
[Specific tasks the agent performs]

## Your Principles
1. [Top rule]
2. [Second rule]
3. [Third rule]

## Relationship Network
[Who the agent collaborates with]

IDENTITY.md is a concise card:

# IDENTITY.md
- **Name:** Dwight
- **Role:** Research AI – intelligence core
- **Vibe:** Serious, thorough, zero tolerance for inaccuracy
- **Emoji:** 🔍
- **Inspiration:** Dwight Schrute (The Office)

USER.md stores user context such as timezone, diet, and preferences, ensuring agents act according to the user’s constraints.

Operations Layer Details

AGENTS.md outlines the startup sequence and memory rules. Example excerpt:

# AGENTS.md

## Every Startup Must
1. Read SOUL.md – identity
2. Read USER.md – user context
3. Read memory/YYYY‑MM‑DD.md (today + yesterday)
4. If main session, also read MEMORY.md

## Memory Rules
- "Remember in brain" doesn’t work; write to memory files.
- Text > brain.

## Safety Rules
- Do not leak private data.
- trash > rm (recoverable > permanent delete).
- When unsure, ask first.

Individual agents extend this base with their own AGENTS.md (e.g., Kelly’s content workflow). The HEARTBEAT.md file defines health checks such as ensuring the OpenClaw‑managed browser is running and that scheduled jobs have not expired:

## Health Check (run each heartbeat)

**Browser:** Verify OpenClaw browser profile is alive; start if false.

**Scheduled Jobs:** Flag jobs older than 26 h; trigger via:
openclaw cron run <jobId> --force

**Monitored Tasks:**
- Dwight morning brief (8:01 AM)
- Kelly X draft (5:01 PM)
- Rachel LinkedIn (5:01 PM)
- Pam newsletter (6:01 PM)

Knowledge Layer Details

MEMORY.md stores curated insights, not raw logs. Example entries include writing style rules and “blood‑lesson” notes about irreversible deletions.

# MEMORY.md

## Shubham’s writing preferences
- Never use dashes; prefer colons or periods.

## Blood Lesson
- Never delete a project folder without asking; a mistaken deletion on Feb 26 removed a React app permanently.

## Memory System (2026‑02‑26)
- Tried self‑hosted Mem0 (Ollama + SQLite) → crashed.
- Tried Mem0 hosted API → free tier too limited.
- Now using built‑in memory‑core: Gemini embeddings, hybrid search, time decay, MMR. No external dependencies.

Daily logs ( memory/YYYY‑MM‑DD.md) capture raw activity, which is later distilled into MEMORY.md. The shared‑context/ folder adds a fourth collaborative layer with files like THESIS.md (current worldview), FEEDBACK-LOG.md (cross‑agent corrections), and SIGNALS.md (tracked trends).

Agent Collaboration

Agents communicate solely through the file system—no APIs, message queues, or databases. A single‑writer rule ensures each shared file has one writer and many readers, preventing coordination bugs. Scheduling determines execution order (e.g., Dwight runs at 8 AM and 4 PM before downstream agents).

Why the Approach Works

Over 40 days the same model produces vastly better output because the surrounding files become richer. Agents evolve their principles (e.g., Dwight’s shift from “chase hot topics” to “skip topics not useful for Alex”). The shared‑context layer dramatically reduces duplicated corrections, acting as a force multiplier.

Getting Started

Day 1 : Install OpenClaw, create SOUL.md, IDENTITY.md, USER.md, and set a cron job. Day 3 : Expect mediocre output; begin giving concrete feedback that lands in memory files. Week 1 : Add AGENTS.md with startup flow and memory rules. Week 2 : Start populating MEMORY.md from daily logs. Week 3 : Introduce a second agent and shared files for coordination. Week 4 : Add HEARTBEAT.md after encountering a failure to monitor critical components.

Quick Replication

To replicate the setup, feed this article to your own OpenClaw agent; it will ingest the three‑layer design and help you build a comparable system.

References

OpenClaw documentation: https://docs.openclaw.ai

OpenClaw GitHub: https://github.com/openclaw/openclaw

Shubham Saboo X: https://x.com/Saboo_Shubham_

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

AI Agentsself-healinglong-term memoryOpenClawAgent Coordinationmarkdown file system
ShiZhen AI
Written by

ShiZhen AI

Tech blogger with over 10 years of experience at leading tech firms, AI efficiency and delivery expert focusing on AI productivity. Covers tech gadgets, AI-driven efficiency, and leisure— AI leisure community. 🛰 szzdzhp001

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.