Skip to content

feat(memory): implement persistent project memory and background extraction - #43870

Open
DhanushPillay wants to merge 8 commits into
anomalyco:devfrom
DhanushPillay:feat/persistent-memory
Open

feat(memory): implement persistent project memory and background extraction#43870
DhanushPillay wants to merge 8 commits into
anomalyco:devfrom
DhanushPillay:feat/persistent-memory

Conversation

@DhanushPillay

@DhanushPillayDhanushPillay commented Aug 21, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Introduces a persistent memory system so the agent remembers project-specific context (architectural decisions, quirks, API patterns) across sessions without forgetting.

  • Added a memory SQLite table to store project-scoped memory strings.
  • Created the core/memory service for DB CRUD operations.
  • Built a background extraction job hooked into SessionStatusEvent.Status. When a session goes idle after meaningful tool use, it asynchronously prompts the LLM to extract non-obvious learnings and saves them.
  • Registered a MemoryContext node to inject these stored memories into the agent's system prompt (<project-memory>) on boot.
  • Added memory_list, memory_delete, and memory_add LLM tools so the agent can self-manage its memories directly.

It uses a background job to prevent blocking the UI/event loop when a session ends, and injects context directly into the system registry so the agent always has immediate access to past learnings.

How did you verify your code works?

Compiled the core package against the TypeScript compiler to verify strong types and schema alignment. Validated the Effect service registration and verified that the background job hooks correctly into the event stream without blocking.

Screenshots / recordings

N/A - Background systems and LLM tooling.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actionsgithub-actionsBot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Aug 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@Enough1122

Copy link
Copy Markdown

AI code review — automated review for reference; please use your judgment.

  • packages/core/src/memory/tools.ts:~88 (@ts-expect-error Brand cast) — bypassing brand validation on input.id; use MemorySchema.ID.make(input.id) or validate the ID format instead of suppressing the type error.
  • packages/core/src/memory/extract.ts:~140-150 — unbounded memory growth: every non-trivial session appends new "auto" memories with no cap or dedup, so long-lived projects accumulate near-duplicate entries injected into every future session's context. Consider a per-project cap or similarity check.
  • packages/core/src/memory/extract.ts:~95 — SessionRunnerModel.resolve(...) may fail (no model/provider configured); the whole extraction silently logs and drops. Fine, but consider skipping extraction earlier when the session had no model usage rather than resolving mid-job.
  • packages/core/src/memory/extract.ts:~130 — try/catch around JSON.parse conflicts with repo style (prefer Effect schema helpers like Schema.decodeUnknownOption over manual parse); also the markdown fence cleanup regex won't handle ```json\n...```\n trailing newline variants reliably.
  • No tests added for the new Memory service/tools/extraction pipeline — this is significant new behavior (DB migration included); recommend unit tests for store/list/delete and the extraction parser.

- Add pruneAuto to cap auto-extracted memories at 200
- Fix JSON parsing in extraction with Schema.decodeUnknownOption
- Move SessionRunnerModel.resolve outside of background job
- Fix ID branding bypass in tools.ts
- Add unit tests for memory core service
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@DhanushPillay@Enough1122