Experimental goal: expose a forget tool that removes selected transcript spans
from the active LLM context window.
SDK constraints
Pi session files are append-only. Entries cannot be modified or physically
deleted through SessionManager.
Active context can still be changed safely by adding a compaction entry.
appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromHook)
makes buildSessionContext() emit the summary, then branch messages from
firstKeptEntryId onward.
Recent tail deletion is already covered by Pi tree navigation/forking. It is
out of scope for Forget.
Middle deletion is not supported without replaying or filtering the transcript.
Replay breaks IDs/tool-call adjacency; per-turn filtering is fragile and not a
persistent session edit.
Design
Tool: forget
mode="inspect": list active branch entries with id, role/type, rough token
estimate, and no content preview by default. Preview is opt-in only because
inspect output itself becomes newer context and can otherwise re-leak text
the next before compaction is meant to hide.
mode="before": append a compaction entry that replaces all active context
before entry_id with a short tombstone summary.
Per-prompt system reminder: short turn-local line tells the agent to consider
Forget when the user starts a new task/objective and skip same-task follow-ups.
Guardrails:
target must exist on active branch.
target must be the latest user message, marked current_user=yes by inspect.
target must not be a toolResult or stale earlier user message.
dry-run preview available with dry_run: true.
no physical deletion claim; JSONL keeps recoverable history.
not a secret-redaction guarantee; newer/current messages and model thinking
can still contain sensitive strings.
Harness: extension loads, tool registers, injects short per-prompt reminder,
inspect output works, before creates compaction with expected
firstKeptEntryId, context drops old text, range refuses.
Real MiniMax: optional FORGET_REAL=1; runs isolated SDK session with only
Forget loaded, calls real model, applies forget, verifies compaction is active.
Real task-switch probes: baseline prompt had 0 compactions; stronger
MUST + current_user=yes prompt caused MiniMax to forget at task switches
while still answering simple tasks.
Manual test
cd extensions/forget
bun test
FORGET_REAL=1 bun run test:real
pi -e ./index.ts --model minimax:MiniMax-M2.7-highspeed
# forget planExperimental goal: expose a `forget` tool that removes selected transcript spans
from the **active LLM context window**.
## SDK constraints- Pi session files are append-only. Entries cannot be modified or physically
deleted through `SessionManager`.
- Active context can still be changed safely by adding a compaction entry.
`appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromHook)`
makes `buildSessionContext()` emit the summary, then branch messages from
`firstKeptEntryId` onward.
- Recent tail deletion is already covered by Pi tree navigation/forking. It is
out of scope for Forget.
- Middle deletion is not supported without replaying or filtering the transcript.
Replay breaks IDs/tool-call adjacency; per-turn filtering is fragile and not a
persistent session edit.
## Design- Tool: `forget`
- `mode="inspect"`: list active branch entries with id, role/type, rough token
estimate, and no content preview by default. Preview is opt-in only because
inspect output itself becomes newer context and can otherwise re-leak text
the next `before` compaction is meant to hide.
- `mode="before"`: append a compaction entry that replaces all active context
before `entry_id` with a short tombstone summary.
- Per-prompt system reminder: short turn-local line tells the agent to consider
Forget when the user starts a new task/objective and skip same-task follow-ups.
- Guardrails:
- target must exist on active branch.
- target must be the latest user message, marked `current_user=yes` by inspect.
- target must not be a `toolResult` or stale earlier user message.
- dry-run preview available with `dry_run: true`.
- no physical deletion claim; JSONL keeps recoverable history.
- not a secret-redaction guarantee; newer/current messages and model thinking
can still contain sensitive strings.
## Tests- Unit: branch formatting, target validation, forget summary/details.
- Harness: extension loads, tool registers, injects short per-prompt reminder,
`inspect` output works, `before` creates compaction with expected
`firstKeptEntryId`, context drops old text, `range` refuses.
- Real MiniMax: optional `FORGET_REAL=1`; runs isolated SDK session with only
Forget loaded, calls real model, applies forget, verifies compaction is active.
- Real task-switch probes: baseline prompt had 0 compactions; stronger
`MUST` + `current_user=yes` prompt caused MiniMax to forget at task switches
while still answering simple tasks.
## Manual test```bashcd extensions/forget
bun test
FORGET_REAL=1 bun run test:real
pi -e ./index.ts --model minimax:MiniMax-M2.7-highspeed
```