Skip to content

Commit cd134bb

Browse files
committed
Add lazy memory health recommendations
1 parent 90ed143 commit cd134bb

9 files changed

Lines changed: 651 additions & 97 deletions

File tree

docs/architecture/api-studio.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ The API is organized by domain:
5656
| **Settings** | `GET /settings`, `PUT /settings` | `settings_handlers.go` |
5757
| **Tools** | `GET /tools`, `GET /tools/cache` | `tools_handlers.go` |
5858
| **AI Chat** | `POST /ai-chat`, `GET /ai-chat/stream` | `ai_chat_handlers.go` |
59-
| **Memory diagnostics** | `GET /memories/map`, `POST /memories/consolidate/preview`, `POST /memories/consolidate/apply` | `memory_map.go`, `memory_consolidation.go` |
59+
| **Memory health** | `GET /memories/health`, `GET /memories/map`, `POST /memories/consolidate/preview`, `POST /memories/consolidate/apply` | `memory_health.go`, `memory_map.go`, `memory_consolidation.go` |
6060

61-
The memory consolidation endpoints are platform-only and tenant-scoped. They draft and upsert structured scenario cards through the existing memory stores; they do not connect directly to tenant databases and they do not delete source memories.
61+
The memory health and consolidation endpoints are platform-only and tenant-scoped. `GET /memories/health` evaluates recommendations lazily when the UI is opened and reuses fresh results for five days; it does not run on a scheduler. Consolidation drafts and upserts structured scenario cards through the existing memory stores; it does not connect directly to tenant databases and it does not delete source memories.
6262

6363
### SSE Chat Streaming
6464

@@ -124,7 +124,8 @@ MCP tools are cached with background refresh to avoid slow MCP server queries on
124124
| `pkg/api/mcp_handlers.go` | MCP server management and inspector |
125125
| `pkg/api/sandbox_handlers.go` | Sandbox initialization, templates, proxy |
126126
| `pkg/api/ai_chat_handlers.go` | Dedicated AI assistant for Studio UI |
127-
| `pkg/api/memory_map.go` | Memory Map diagnostics for duplicate/scattered/risky memories |
127+
| `pkg/api/memory_health.go` | Lazy Memory Health recommendations with a five-day freshness window |
128+
| `pkg/api/memory_map.go` | Advanced Memory Map diagnostics for duplicate/scattered/risky memories |
128129
| `pkg/api/memory_consolidation.go` | Scenario-card preview/apply endpoints for controlled consolidation |
129130
| `web/src/components/` | React components (37+ files) |
130131
| `web/src/api/` | API client functions for the frontend |

docs/architecture/memory.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,24 +197,32 @@ Implementation details:
197197

198198
The key invariant is that Astonish should save **how to do the thing efficiently**, not a transcript of exploratory dead ends. Temporary outages, timeouts, rate limits, and “X did not work” observations may appear only as conditional cautions that require re-verification before they change behavior.
199199

200-
### Memory Map Diagnostics and Consolidation
200+
### Memory Health Recommendations and Advanced Map
201201

202-
Platform mode exposes `GET /api/memories/map` as a diagnostic report over the current user's visible personal, team, and org memories. The Studio Knowledge Browser surfaces this as the **Memory Map** tab.
202+
Platform mode exposes `GET /api/memories/health` as the product-facing memory organization surface. It evaluates the current user's visible personal, team, and org memories lazily when the Knowledge Browser's **Memory Health** tab is opened. There is no background schedule: a cached evaluation is reused for five days when the memory snapshot has not changed, and the next UI visit after the TTL triggers a fresh evaluation. Users can also force a refresh with **Reanalyze**.
203203

204-
The report groups likely related memory chunks by a canonical topic key and flags conditions that make memory feel scattered or unsafe:
204+
Memory Health returns reviewable recommendations, not automatic writes:
205+
206+
- create a scenario card from related raw memories
207+
- update an existing scenario card with new raw source memories
208+
- review a card that still carries temporary-failure or trial/error wording
209+
210+
Each recommendation contains the proposed card, target scope, source memory IDs, and the diagnostic flags that explain why it was suggested. Applying a recommendation uses the same scenario-card upsert endpoint as manual consolidation; source memories are retained as provenance.
211+
212+
`GET /api/memories/map` remains available as the advanced diagnostic report behind the Memory Health UI. It groups likely related memory chunks by a canonical topic key and flags conditions that make memory feel scattered or unsafe:
205213

206214
- duplicate risk: multiple memories appear to cover the same topic
207215
- scattered topic: related memories are spread across scopes or categories
208216
- transient failure risk: a memory uses outage/timeout/flaky language that should not become a permanent avoidance rule
209217
- trial/error risk: a memory appears to preserve exploratory failed attempts instead of the shortest successful path
210218
- scenario card: the group already contains a structured card, so raw rows should be treated as provenance or incremental evidence
211219

212-
The Memory Map also provides controlled consolidation endpoints:
220+
The consolidation endpoints remain the write boundary:
213221

214222
- `POST /api/memories/consolidate/preview` drafts a scenario card from a selected group without saving.
215223
- `POST /api/memories/consolidate/apply` saves or merges the edited card into the selected personal, team, or org scope.
216224

217-
Both endpoints resolve stores through the tenant router and current authenticated context. They do not connect directly to tenant databases and they do not delete raw memories.
225+
Both endpoints resolve stores through the tenant router and current authenticated context. They do not connect directly to tenant databases and they do not delete raw memories. Memory Health recommendations are operational metadata, not agent knowledge, and are not stored as retrievable memories.
218226

219227
### BM25 Implementation
220228

docs/website/docs/agent/memory.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,14 @@ This helps the agent reuse the efficient path it learned instead of replaying tr
7575

7676
## Managing Memory in Studio
7777

78-
Studio provides a visual interface for memory management:
78+
Studio provides a visual interface for memory management. The main organization surface is **Memory Health**: when opened, Astonish checks whether the visible memories need consolidation, deduplication, or review. The check is lazy and on demand — there is no scheduled background job. If a recent evaluation is still fresh, Studio reuses it; after five days, the next visit runs a new evaluation.
7979

8080
- Browse all memory entries with search and filtering
8181
- View memory content, tags, and metadata
82-
- Use **Memory Map** to identify duplicate, scattered, or risky memories
83-
- Draft and save scenario cards from Memory Map groups
82+
- Use **Memory Health** to review suggested organization improvements
83+
- Reanalyze memory on demand; otherwise fresh evaluations are reused for five days
84+
- Draft and save scenario cards from recommendations
85+
- Open the advanced **Memory Map** only when you need low-level diagnostics
8486
- Publish personal memories to your team by merging them into scenario cards when possible
8587
- Promote team memories to org level (admin) by merging them into org scenario cards when possible
8688
- Delete or edit memory entries

pkg/api/handlers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,7 @@ func RegisterRoutes(router *mux.Router, svc *store.Services, backend store.Platf
13251325

13261326
// Memory sharing endpoints (platform mode)
13271327
router.HandleFunc("/api/memories/map", MemoryMapHandler).Methods("GET")
1328+
router.HandleFunc("/api/memories/health", MemoryHealthHandler).Methods("GET")
13281329
router.HandleFunc("/api/memories/consolidate/preview", MemoryConsolidationPreviewHandler).Methods("POST")
13291330
router.HandleFunc("/api/memories/consolidate/apply", MemoryConsolidationApplyHandler).Methods("POST")
13301331
router.HandleFunc("/api/memories/search", MemorySearchCrossTierHandler).Methods("POST")

0 commit comments

Comments
 (0)