Skip to content

Commit 197db6b

Browse files
committed
feat: pi-agent-memory — persistent memory extension for pi-mono agents
Add pi-agent-memory, a native pi-mono extension that connects pi-agents to claude-mem's worker service for cross-session, cross-engine memory. - Extension registers session lifecycle hooks (init, context injection, observation capture, summarize, complete) - Registers memory_recall tool for explicit memory search - Registers /memory-status command for health checks - All HTTP calls use AbortController timeouts - Fire-and-forget for tool_result to avoid blocking the agent loop - Cross-engine: pi-agent observations share the same database with Claude Code, Cursor, Codex, and OpenClaw Also updates platform-source normalization to recognize pi-agent identifiers via exact Set matching.
1 parent cde4faa commit 197db6b

File tree

8 files changed

+653
-1
lines changed

8 files changed

+653
-1
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ curl -fsSL https://install.cmem.ai/openclaw.sh | bash
161161

162162
The installer handles dependencies, plugin setup, AI provider configuration, worker startup, and optional real-time observation feeds to Telegram, Discord, Slack, and more. See the [OpenClaw Integration Guide](https://docs.claude-mem.ai/openclaw-integration) for details.
163163

164+
### Pi-Agent (pi-mono)
165+
166+
Install claude-mem as a persistent memory extension for [pi-agents](https://github.com/badlogic/pi-mono):
167+
168+
```bash
169+
pi install npm:pi-agent-memory
170+
```
171+
172+
Gives any pi-mono-based agent (pi-coding-agent, OpenClaw, custom runtimes) cross-session memory. Observations are shared across all engines in the same database. See the [pi-agent README](pi-agent/README.md) for full details.
173+
164174
**Key Features:**
165175

166176
- 🧠 **Persistent Memory** - Context survives across sessions

pi-agent/LICENSE

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
This package is part of claude-mem (https://github.com/thedotmack/claude-mem)
2+
and is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0).
3+
4+
Copyright (C) 2025 Alex Newman (@thedotmack). All rights reserved.
5+
Pi-agent adapter contributed by ArtemisAI.
6+
7+
See the full license text at:
8+
https://github.com/thedotmack/claude-mem/blob/main/LICENSE
9+
10+
SPDX-License-Identifier: AGPL-3.0-or-later

pi-agent/README.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# pi-agent-memory
2+
3+
Persistent memory extension for [pi-agents](https://github.com/badlogic/pi-mono) powered by [claude-mem](https://github.com/thedotmack/claude-mem).
4+
5+
Gives pi-coding-agent and any pi-mono-based runtime cross-session, cross-engine memory by connecting to claude-mem's worker service.
6+
7+
## Installation
8+
9+
Requires the claude-mem worker running on `localhost:37777`. Install claude-mem first via `npx claude-mem install` or run the worker from source.
10+
11+
### From npm (recommended)
12+
13+
```bash
14+
pi install npm:pi-agent-memory
15+
```
16+
17+
### From git
18+
19+
```bash
20+
pi install git:github.com/thedotmack/claude-mem
21+
```
22+
23+
### Manual
24+
25+
```bash
26+
cp extensions/pi-mem.ts ~/.pi/agent/extensions/pi-mem.ts
27+
```
28+
29+
### Verify
30+
31+
```bash
32+
# Start pi — the extension auto-loads
33+
pi
34+
35+
# Check connectivity
36+
/memory-status
37+
```
38+
39+
## What It Does
40+
41+
- **Captures observations** — every tool call your pi-agent makes is recorded to claude-mem's database
42+
- **Injects context** — relevant past observations are automatically injected into the LLM context each turn
43+
- **Memory search** — a `memory_recall` tool is registered for the LLM to explicitly search past work
44+
- **Cross-engine sharing** — pi-agent observations live alongside Claude Code, Cursor, Codex, and OpenClaw memories in the same database
45+
46+
## Architecture
47+
48+
```text
49+
Pi-Agent (pi-coding-agent / OpenClaw / custom)
50+
51+
├── pi-mem extension (this package)
52+
│ ├── session_start ──→ (local state init only)
53+
│ ├── before_agent_start ──→ POST /api/sessions/init (with prompt)
54+
│ ├── context ──→ GET /api/context/inject
55+
│ ├── tool_result ──→ POST /api/sessions/observations
56+
│ ├── agent_end ──→ POST /api/sessions/summarize
57+
│ │ POST /api/sessions/complete
58+
│ ├── session_compact ──→ (preserve session state)
59+
│ └── session_shutdown ──→ (cleanup)
60+
61+
└── memory_recall tool ──→ GET /api/search
62+
63+
64+
claude-mem worker (port 37777)
65+
SQLite + FTS5 + Chroma
66+
Shared across all engines
67+
```
68+
69+
## Event Mapping
70+
71+
| Pi-Mono Event | Worker API | Purpose |
72+
|---|---|---|
73+
| `session_start` | — (local state only) | Derive project name, generate session ID |
74+
| `before_agent_start` | `POST /api/sessions/init` | Capture user prompt for privacy filtering |
75+
| `context` | `GET /api/context/inject` | Inject past observations into LLM context |
76+
| `tool_result` | `POST /api/sessions/observations` | Record what tools did (fire-and-forget) |
77+
| `agent_end` | `POST /api/sessions/summarize` + `complete` | AI-compress the session |
78+
| `session_compact` || Preserve session ID across context compaction |
79+
| `session_shutdown` || Clean up local state |
80+
81+
Derived from the OpenClaw plugin (`claude-mem/openclaw/src/index.ts`), which is a proven integration of claude-mem into a pi-mono-based runtime.
82+
83+
## Configuration
84+
85+
| Variable | Default | Description |
86+
|---|---|---|
87+
| `CLAUDE_MEM_PORT` | `37777` | Worker service port |
88+
| `CLAUDE_MEM_HOST` | `127.0.0.1` | Worker service host |
89+
| `PI_MEM_PROJECT` | (derived from cwd) | Project name for scoping observations |
90+
| `PI_MEM_DISABLED` || Set to `1` to disable the extension |
91+
92+
## Cross-Engine Memory
93+
94+
All engines write to the same `~/.claude-mem/claude-mem.db`, tagged by `platform_source`:
95+
96+
| Engine | Platform Source |
97+
|---|---|
98+
| Claude Code | `claude` |
99+
| OpenClaw | `openclaw` |
100+
| Pi-Agent | `pi-agent` |
101+
| Cursor | `cursor` |
102+
| Codex | `codex` |
103+
104+
Context injection returns observations from all engines for the same project by default. Pass `platformSource` to filter by engine.
105+
106+
## Related Packages
107+
108+
Other independent claude-mem adapters published to npm:
109+
110+
- [`@ephemushroom/opencode-claude-mem`](https://www.npmjs.com/package/@ephemushroom/opencode-claude-mem) — OpenCode adapter (MIT)
111+
- [`opencode-cmem`](https://www.npmjs.com/package/opencode-cmem) — OpenCode adapter (MIT)
112+
113+
Other pi memory extensions (standalone, not claude-mem based):
114+
115+
- [`@samfp/pi-memory`](https://www.npmjs.com/package/@samfp/pi-memory) — Learns corrections/preferences from sessions
116+
- [`@zhafron/pi-memory`](https://www.npmjs.com/package/@zhafron/pi-memory) — Memory management + identity
117+
- [`@db0-ai/pi`](https://www.npmjs.com/package/@db0-ai/pi) — Auto fact extraction, local SQLite
118+
119+
## Development
120+
121+
```bash
122+
# Edit the extension
123+
vim extensions/pi-mem.ts
124+
125+
# Test locally
126+
pi -e ./extensions/pi-mem.ts
127+
128+
# Or install from local path
129+
pi install ./pi-agent
130+
```
131+
132+
## License
133+
134+
AGPL-3.0 — same as [claude-mem](https://github.com/thedotmack/claude-mem/blob/main/LICENSE).

pi-agent/banner.png

4.23 MB
Loading

0 commit comments

Comments
 (0)