Tools
Short Term Memory
Short-Term Memory Plugin for OpenClaw — automatic conversation context injection
Configuration Example
{
"ts": "2026-03-17T04:40:19.020Z",
"turn": 354,
"task": "qual a capital do Brasil?",
"input": "qual a capital do Brasil?",
"output": "A capital do Brasil é Brasília!",
"tags": ["memory"]
}
README
# Short-Term Memory Plugin for OpenClaw
Automatic per-turn memory injection and recording — no LLM calls for writing.
## How It Works
1. **`before_prompt_build`** — reads the last 20 entries from `~/.openclaw/memory/short-term.jsonl` and injects them as `prependContext` so the agent sees recent conversation history.
2. **`agent_end`** — after each successful turn, extracts the last user message and assistant reply, builds a compact record, and appends it to the JSONL file. Fully synchronous (critical: `agent_end` is fire-and-forget).
No LLM tokens are spent on memory writing. Tags are extracted via keyword heuristics.
## Storage Format
Each line in `short-term.jsonl` is a JSON object:
```json
{
"ts": "2026-03-17T04:40:19.020Z",
"turn": 354,
"task": "qual a capital do Brasil?",
"input": "qual a capital do Brasil?",
"output": "A capital do Brasil é Brasília!",
"tags": ["memory"]
}
```
### Field Limits
| Field | Max Length |
|----------|-----------|
| `task` | 100 chars |
| `input` | 200 chars |
| `output` | 300 chars |
| `tags` | 5 items |
### File Rotation
When the file reaches 10,000 entries, it is renamed to `short-term-YYYY-MM-DD.jsonl` and a fresh file starts.
## Installation
Copy this directory to `~/.openclaw/extensions/short-term-memory/`.
Add to `~/.openclaw/openclaw.json`:
```json
{
"plugins": {
"allow": ["short-term-memory"],
"entries": {
"short-term-memory": {
"enabled": true
}
}
}
}
```
Restart the gateway:
```bash
openclaw gateway restart
```
> **Important:** After editing `index.js`, always restart the gateway — the daemon caches loaded modules.
## Configuration
All settings are optional (defaults shown):
```json
{
"plugins": {
"entries": {
"short-term-memory": {
"enabled": true,
"config": {
"maxEntries": 10000,
"maxInjectEntries": 20,
"maxInputChars": 200,
"maxOutputChars": 300,
"maxTaskChars": 100,
"maxTags": 5
}
}
}
}
}
```
## Key Implementation Details
- **Synchronous `agent_end` handler:** The `agent_end` hook is dispatched as fire-and-forget (not awaited). Async handlers may not complete before the CLI process exits. The handler uses only synchronous I/O (`appendFileSync`, `mkdirSync`).
- **Content block support:** Handles both string and array content formats (`[{ type: "text", text: "..." }]`).
- **Memory prefix stripping:** Strips the injected `## Recent Memory` block from user input before recording to avoid self-referential entries.
- **Plugin contract:** Follows `OpenClawPluginDefinition` — `module.exports = { id, register(api) { api.on(...) } }`. Same pattern as `extensions/diffs` and `extensions/memory-lancedb`.
## Compatibility
- OpenClaw 2026.3.14+
- Node 22+
- Hooks: `before_prompt_build`, `agent_end`
## License
MIT
tools
Comments
Sign in to leave a comment