> ## Documentation Index
> Fetch the complete documentation index at: https://docs.loom.teamecho.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenClaw Integration

> Use Loom as a Context Engine in OpenClaw.

Loom includes a first-party **OpenClaw plugin** (`loom-openclaw-plugin/`) that integrates Loom as a Context Engine, providing structured long-term memory for OpenClaw.

## Quick Start

### 1. Install & configure Loom

```bash theme={null}
cd Loom
pip install -e .
loom init          # generates configs/loom.yaml and template files
```

Open `configs/loom.yaml` and fill in the `llm` section (or copy `.env.example` to `.env` and edit):

```yaml theme={null}
# configs/loom.yaml
llm:
  api_key: "your-api-key"
  model: "google/gemini-2.5-flash"            # any OpenAI-compatible model
  base_url: "https://openrouter.ai/api/v1"    # OpenRouter / OpenAI / local endpoint
```

### 2. Start the Loom backend

```bash theme={null}
loom serve                   # foreground (Ctrl+C to stop)
# or
loom serve start             # background daemon (recommended)
```

The server runs at `http://localhost:8666` by default. Use `loom serve status` to verify.

### 3. Install the plugin

```bash theme={null}
clawhub login
openclaw plugins install loom-claw
```

For local development from this repository, use:

```bash theme={null}
openclaw plugins install --link /path/to/Loom/loom-openclaw-plugin
```

<Note>
  If you don't have OpenClaw yet, see the [OpenClaw Install Guide](https://docs.openclaw.ai/install) first.
</Note>

### 4. Start (or restart) the Gateway

If the Gateway is **not running**, start it:

```bash theme={null}
openclaw gateway
```

If the Gateway is **already running**, restart it to load the new plugin:

```bash theme={null}
openclaw gateway restart
```

### 5. Verify

```bash theme={null}
openclaw plugins list --enabled     # plugin should appear
openclaw plugins inspect loom-claw  # detailed plugin info
openclaw gateway status             # Gateway health check
```

Then open a chat and send `/loom status` to confirm end-to-end connectivity. The plugin will automatically extract and recall structured memories each turn.

## Features

* **Auto-extract** and **auto-recall** — extracts information into structured schemas and injects it into the system prompt each turn
* **Schema-based memory** — organizes knowledge into typed domains and fields
* **Multi-schema management** — create, switch, backup, and restore independent schema files
* **Template system** — bootstrap schemas from built-in, shared, or custom templates; full template CRUD via slash commands
* **Agent tools** — 5 registered tools for LLM-driven memory management
* **Slash commands** — full `/loom` command suite for manual memory management

## Configuration

Configure in `openclaw.json` under `plugins.entries.loom-claw.config`:

| Option             | Default                 | Description                                               |
| ------------------ | ----------------------- | --------------------------------------------------------- |
| `loomBaseUrl`      | `http://localhost:8666` | Loom backend URL                                          |
| `sessionId`        | `default`               | Loom session ID                                           |
| `schemaId`         | `default`               | Shared schema file ID                                     |
| `schemaTemplate`   | —                       | Initial template                                          |
| `buildEveryNTurns` | `1`                     | Extraction frequency (same as Loom `build_every_n_turns`) |

Example `openclaw.json`:

```json theme={null}
{
  "plugins": {
    "entries": {
      "loom-claw": {
        "enabled": true,
        "config": {
          "loomBaseUrl": "http://localhost:8666",
          "sessionId": "default",
          "schemaId": "default",
          "schemaTemplate": "general",
          "buildEveryNTurns": 1
        }
      }
    }
  }
}
```

## Slash Commands

**View & Recall**

| Command                   | Description                                |
| ------------------------- | ------------------------------------------ |
| `/loom` or `/loom status` | Show connection status and schema overview |
| `/loom inspect`           | View schema structure with field values    |
| `/loom recall`            | Recall all stored memory data              |

**Memory Management**

| Command                 | Description                           |
| ----------------------- | ------------------------------------- |
| `/loom forget <domain>` | Delete a specific schema domain       |
| `/loom forget --all`    | Clear all memory                      |
| `/loom reset`           | Backup current schema and start fresh |

**Schema Files**

| Command                     | Description                                |
| --------------------------- | ------------------------------------------ |
| `/loom schemas`             | List all schema files and backups          |
| `/loom new [name]`          | Create a new blank schema and switch to it |
| `/loom switch <schema_id>`  | Switch to an existing schema               |
| `/loom restore <backup_id>` | Restore a schema from backup               |

**Template Management**

| Command                               | Description                                         |
| ------------------------------------- | --------------------------------------------------- |
| `/loom templates`                     | List all available templates (grouped by source)    |
| `/loom templates show <name>`         | Preview template domains and fields                 |
| `/loom templates use <name>`          | Create a schema from template and switch to it      |
| `/loom templates create`              | Show format help for creating custom templates      |
| `/loom templates create <definition>` | Create a custom template (compact text or `--json`) |
| `/loom templates delete <name>`       | Delete a custom template                            |
| `/loom templates help`                | Show template command help                          |

**Configuration**

| Command                             | Description                        |
| ----------------------------------- | ---------------------------------- |
| `/loom config`                      | View current runtime configuration |
| `/loom config buildEveryNTurns <N>` | Update extraction frequency        |
| `/loom help`                        | Show help                          |

### Creating Custom Templates via Slash Command

Create templates directly from the chat using the compact text format:

```
/loom templates create game_character
  character: name, class, level, skills
  story: main_quest, side_quests
  social: friends, guild, reputation
```

Format:

* First line: `template_name description` (name allows letters, numbers, `_`, `-`)
* Following lines: `domain_name: field1 | description, field2 | description`

Or use JSON format: `/loom templates create --json {"_meta":{"name":"..."},...}`

## Agent Tools

Five tools are registered for the OpenClaw agent:

| Tool           | Description                               |
| -------------- | ----------------------------------------- |
| `loom_inspect` | Inspect schema structure and field values |
| `loom_recall`  | Recall all schema memory data             |
| `loom_build`   | Manually trigger information extraction   |
| `loom_forget`  | Delete a domain or clear all memory       |
| `loom_update`  | Trigger schema update from chat history   |

## Context Engine Lifecycle

| OpenClaw Hook | Plugin Behavior                               | Loom API                                            |
| ------------- | --------------------------------------------- | --------------------------------------------------- |
| `bootstrap`   | Verify backend, create session, load template | `POST /api/sessions`, `GET /api/schemas/recall-all` |
| `assemble`    | Fetch schema data, inject into system prompt  | `GET /api/schemas/recall-all`                       |
| `afterTurn`   | Format messages, extract info                 | `POST /api/build`                                   |
| `compact`     | Delegate to runtime                           | —                                                   |

## Data Flow

```
User message → OpenClaw agent
                 ↓
           [assemble] → GET /api/schemas/recall-all
                 ↓        → schema data injected into system prompt
           Model generates response
                 ↓
           [afterTurn] → POST /api/build
                           → CM Agent extracts information
                           → Updates schema
                           → Available on next assemble
```

## Data Storage

Loom stores data under the OpenClaw Agent Workspace:

```
~/.openclaw/workspace/loom/
├── schemas/              # Schema files (shared across sessions)
│   ├── default.json
│   └── backups/
│       └── default_20260314_180736.json
└── sessions/
    └── default.json
```

Configure paths in `configs/loom.yaml`:

```yaml theme={null}
persistence:
  session_dir: "~/.openclaw/workspace/loom/sessions"
  schemas_dir: "~/.openclaw/workspace/loom/schemas"
```
