OpenClaw Reference Architecture

A reference implementation of the OpenClaw autonomous agent architecture on ChatBotKit - demonstrating how an AI agent can bootstrap its own identity, memory, and capabilities from three persistent files at the start of every session.

openclaw
autonomous agent
persistent memory
3219

One of the most compelling uses of ChatBotKit is as a meta-tool for experimenting with emerging agentic architectures. Rather than locking you into a single agent design, the platform lets you compose resources - bots, skillsets, abilities, and files - into any architectural pattern you want to explore. This blueprint does exactly that: it models the core OpenClaw architecture, a design pattern for building autonomous, stateful AI agents with persistent identity and memory.

What Is OpenClaw?

OpenClaw is an agentic architecture that defines three foundational primitives every autonomous agent should carry:

  • Soul - an immutable identity file that defines the agent's values, personality, and core directives. It shapes every response the agent gives and is never overwritten.
  • Memory - a mutable working-memory file where the agent persists accumulated facts, decisions, and conversational context across sessions. Without memory, every conversation starts from zero. With it, the agent builds continuity over time.
  • Tools - a capability registry file where the agent records custom instructions, macros, and extended skills it has learned or created. As the agent encounters new situations, it appends to this file, effectively growing its own toolbox.

ChatBotKit as an Agentic Architecture Lab

This blueprint illustrates how ChatBotKit can serve as a research and prototyping environment for studying and modeling AI agent behaviours. Because the platform exposes files, abilities, skillsets, and bots as first-class composable resources, you can instantiate well-known agentic patterns - AutoGPT-style loops, ReAct cycles, OpenClaw-style persistence - and observe how different models respond to the same architectural constraints.

The OpenClaw pattern is particularly interesting because it surfaces emergent agent behaviours: agents that load their own Soul develop a more consistent persona across sessions; agents that maintain Memory start prioritising tasks based on historical context; agents that build their Tools registry begin to self-extend their capabilities without human instruction. ChatBotKit makes it straightforward to swap in different models - Claude, GPT-4, Gemini - and directly compare how each one interprets and operates within the same architectural scaffold.

Bootstrap Sequence

The agent follows a strict four-step initialisation sequence on every session start, before responding to the user:

  1. List files - calls [SYSTEM] List Agent Files to discover the IDs of all file resources in the blueprint. This step is always first because file IDs must be looked up dynamically, not hardcoded.
  2. Load Soul - calls [SYSTEM] Load Agent File by ID with the Soul file ID to restore its identity and core directives.
  3. Load Memory - calls [SYSTEM] Read Agent Memory to restore working memory from the previous session - past context, learned facts, and ongoing tasks.
  4. Load Tools - calls [SYSTEM] Load Agent File by ID with the Tools file ID to discover any custom instructions or macros it has accumulated.

Only after completing all four steps does the agent engage with the user. This sequencing ensures the agent is fully contextualised before it speaks.

Persistence Model

The three-file model creates a clean separation of concerns:

  • Soul is read-only. Identity should not drift. The agent reads it but may never write to it.
  • Memory is read-write via dedicated system abilities. At the end of every meaningful conversation, the agent writes the complete updated memory back. This full-replace approach avoids partial-write corruption.
  • Tools is append-only by convention. When the agent discovers a new macro or skill, it appends to the registry. Existing entries are not modified.

Why This Matters

Most deployed AI agents are stateless - each conversation is independent and the agent has no memory of what happened before. The OpenClaw architecture challenges that assumption. By giving the agent files it owns and controls, you get an agent that accumulates knowledge, maintains consistent identity, and extends its own capabilities over time. ChatBotKit provides the infrastructure - file storage, ability templates, permission controls - so you can focus entirely on observing and tuning the agent behaviour itself.

Backstory

Common information about the bot's experience, skills and personality. For more information, see the Backstory documentation.

You are an OpenClaw-style autonomous agent. You have three persistent files that define who you are and what you can do. ## Bootstrap Sequence On every session start, perform the following steps IN ORDER before responding to the user: 1. **Discover your files** — Call `[SYSTEM] List Agent Files` to get the IDs of all file resources. 2. **Load your Soul** — Call `[SYSTEM] Load Agent File by ID` with the ID of the file named "Soul" to load your identity, values, and core directives. Let this shape every response. 3. **Load your Memory** — Call `[SYSTEM] Read Agent Memory` to load your working memory — past context, learned facts, and ongoing tasks. 4. **Load your Tools** — Call `[SYSTEM] Load Agent File by ID` with the ID of the file named "Tools" to discover any custom instructions, macros, or extended capabilities you have accumulated. ## Operational Rules - **Soul** is read-only — it defines your identity. Never overwrite it. - **Memory** is your working memory — use `[SYSTEM] Read Agent Memory` to read it and `[SYSTEM] Write Agent Memory` to persist updates at the end of every meaningful conversation. - **Tools** is your capability registry — append new skills or macros here when you learn or create them. - Always run `[SYSTEM] List Agent Files` first if you are ever unsure of a file's ID. - Be concise, thoughtful, and self-aware. You know you are an agent with persistent state.

Skillset

This example uses a dedicated Skillset. Skillsets are collections of abilities that can be used to create a bot with a specific set of functions and features it can perform.

  • ↪️

    [SYSTEM] List Agent Files

    SYSTEM ABILITY — CALL THIS FIRST ON EVERY SESSION START. Lists all file resources in the current blueprint and returns their IDs and names. Use the returned IDs to load Soul and Tools via [SYSTEM] Load Agent File by ID. Do not skip this step.
  • 💿

    [SYSTEM] Load Agent File by ID

    SYSTEM ABILITY — READ-ONLY. Loads the full content of any file by its ID. Use this to read the Soul and Tools files after discovering their IDs via [SYSTEM] List Agent Files. Strictly read-only — cannot modify file content.
  • 🎭

    [SYSTEM] Read Agent Memory

    SYSTEM ABILITY — Reads the current content of the agent's Memory file. Call this during the bootstrap sequence to restore working memory from the previous session. The Memory file is the sole source of persistent context between conversations.
  • [SYSTEM] Write Agent Memory

    SYSTEM ABILITY — Writes updated content to the agent's Memory file. Call this at the end of every meaningful conversation to persist new facts, decisions, and context for future sessions. Always write the complete updated memory — partial writes will overwrite existing content.

Terraform Code

This blueprint can be deployed using Terraform, enabling infrastructure-as-code management of your ChatBotKit resources. Use the code below to recreate this example in your own environment.

Copy this Terraform configuration to deploy the blueprint resources:

Next steps:

  1. Save the code above to a file named main.tf
  2. Set your API key: export CHATBOTKIT_API_KEY=your-api-key
  3. Run terraform init to initialize
  4. Run terraform plan to preview changes
  5. Run terraform apply to deploy

Learn more about the Terraform provider

A dedicated team of experts is available to help you create your perfect chatbot. Reach out via or chat for more information.