#9415: Artifact-first memory: externalize tool outputs + deterministic recall
docs
app: web-ui
gateway
agents
stale
Cluster:
Context Management Enhancements
## Summary
Externalizes large tool outputs into session-scoped artifact files with deterministic hash-based references. This keeps transcripts lean while preserving exact recall for large outputs.
## Motivation
Large tool outputs inflate transcripts and prompt size. This change keeps transcripts slim while preserving exact recall via artifact references.
## How It Works
1. Tool result is written to an artifact file
2. A registry entry (hash + metadata) is appended
3. Transcript stores only `artifactRef` (no payload)
4. Read path optionally rehydrates payload on demand
5. Recall path injects top-K artifact summaries within a fixed budget
## Architecture
```mermaid
graph LR;
A[Tool Result] --> B[Artifact Externalizer];
B --> C[Artifact Store];
B --> D[Registry JSONL];
B --> E[Transcript Writer];
E --> F[Session Transcript w/ artifactRef];
F --> G[Session Reader];
G -->|rehydrate| H[Tool Payload];
F --> I[Recall Engine];
I --> J[Bounded Prompt Injection];
```
## Key Code Changes
1. **New Artifact System Files:**
- `src/agents/tool-result-externalizer.ts` - Wraps tool results into artifact files before session persistence
- `src/agents/artifact-store.ts` - Reads/writes tool-result artifacts with metadata (id, size, summary)
- `src/agents/artifact-registry.ts` - Manages session-scoped registry entries (hash lookup)
- `src/agents/session-artifacts.ts` - TypeScript types for `ArtifactRef` and `ToolResultArtifactDetails`
- `src/agents/artifact-recall.ts` - Builds bounded recall sections for system prompts (top-K summaries)
2. **Context Pruning Integration:**
- `src/agents/pi-extensions/context-pruning/artifacts.ts` - Tool result serialization and placeholder generation
- `src/agents/pi-extensions/context-pruning/pruner.ts` - Filters artifacts during context pruning
- `src/agents/pi-extensions/compaction-safeguard.ts` - Protects artifacts from compaction
3. **Session Migration Path:**
- `src/agents/session-artifact-migration.ts` - Migrates legacy inline payloads to artifact refs
- `src/gateway/session-utils.fs.ts` - Updated to handle artifact rehydration
4. **Config Types:**
- `src/config/types.memory.ts` - New `memory.artifacts` config (`enabled`, `maxItems`, `maxChars`, `narrativeMaxChars`)
## Breaking Change (2026-02-05)
Session transcripts no longer embed tool payloads. Tool results are now stored as files at `~/.openclaw/agents/<agentId>/sessions/artifacts/` and referenced by `details.artifactRef`. Custom readers must follow artifact references or run migration.
## Testing
- Full unit test coverage for artifact store, registry, recall, and migration
- `pnpm build && pnpm check && pnpm test`
Most Similar PRs
#17345: feat: Memory kernel rebuild with token budgeting, summary sidecar, ...
by markmusson · 2026-02-15
75.5%
#16261: feat(agents): add two-tier tool output truncation and excludeFromCo...
by ProgramCaiCai · 2026-02-14
68.3%
#12296: security: persistence-only secret redaction for session transcripts
by akoscz · 2026-02-09
67.2%
#10915: fix: prevent session bloat from oversized tool results and improve ...
by DukeDeSouth · 2026-02-07
66.5%
#11825: fix: keep tool_use/tool_result pairs together during session compac...
by C31gordon · 2026-02-08
66.3%
#14024: feat(agents): add structured tool reflection for error recovery
by career091101 · 2026-02-11
66.2%
#15050: fix: transcript corruption resilience — strip aborted tool_use bloc...
by yashchitneni · 2026-02-12
66.1%
#7525: Agents: skip errored tool calls during pairing
by justinhuangcode · 2026-02-02
65.7%
#16856: feat(agents): add tool execution duration tracking with configurabl...
by EunHyeokJung · 2026-02-15
65.4%
#20183: fix(memory): index reset/deleted session transcripts
by VACInc · 2026-02-18
65.4%