Skip to content

Add persistent memory tool for agent - #679

Merged
edenreich merged 7 commits into
mainfrom
feat/memory-tool
Jun 28, 2026
Merged

edenreich merged 7 commits into
mainfrom
feat/memory-tool

Conversation

@edenreich

@edenreich edenreich commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Adds a persistent, cross-session Memory tool for the agent, modeled on the Claude Code memory system.

How it works

  • Store: a global directory at ~/.infer/memory/ holding a tool-maintained index MEMORY.md (one line per fact) plus individual <slug>.md fact-files, each with YAML frontmatter (name, description, metadata.type ∈ user | feedback | project | reference).
  • Operations: read (no name → the index; with a name → one fact in full), write (upsert a fact and its index entry), delete (remove a fact and its index entry). The tool keeps MEMORY.md in sync automatically and writes atomically.
  • Context: the MEMORY.md index is injected into the agent's context at the start of each session; the agent loads individual facts on demand.

Configuration

  • Settings live in their own memory.yaml (not config.yaml), alongside the other split-out config files: enabled (default false), dir (override; defaults to ~/.infer/memory), max_chars (cap on the injected index). Env overrides: INFER_MEMORY_ENABLED / INFER_MEMORY_DIR / INFER_MEMORY_MAX_CHARS.
  • Because memory is global, infer init seeds memory.yaml in the home directory (~/.infer/memory.yaml), create-if-absent so re-running init never clobbers an enabled config or blocks init across projects.

Reminders

  • Reminders are now enabled by default; a memory-consult reminder nudges the agent to consult and record durable facts, and is automatically pruned at load time when memory is disabled.

Notes

  • The tool writes through its own atomic writer (temp + rename) rather than the sandboxed file writer, whose .infer/ protected-path guard would otherwise reject writes under ~/.infer/.
  • The memory store is created lazily on first write; nothing is written into a project's .infer/.

@edenreich
edenreich requested a review from a team as a code owner June 28, 2026 13:29
Comment thread config/config.go Resolved
Comment thread config/config.go Resolved
Comment thread internal/agent/tools/memory.go Resolved
Comment thread internal/agent/tools/memory.go Resolved
Comment thread internal/agent/tools/memory.go Resolved
Comment thread internal/agent/tools/memory.go Resolved
Comment thread internal/agent/tools/memory_test.go Resolved
Comment thread internal/agent/agent_utils.go Resolved
Co-authored-by: Eden Reich <[email protected]>
…ted config

Rework the persistent memory tool into the Claude Code memory model:

- Store durable facts as individual <slug>.md files (frontmatter
  name/description/metadata.type) under a global ~/.infer/memory dir,
  catalogued by a tool-maintained MEMORY.md index that is injected into
  context each session, replacing the single project-level memory.md.
- Operations are read/write/delete; the tool keeps the index in sync and
  writes atomically, fixing writes the .infer/ protected-path guard would
  otherwise reject.
- Move settings out of config.yaml into a dedicated memory.yaml, seeded in
  the home directory (create-if-absent) since memory is global.
- Enable reminders by default and prune memory-consult when memory is off.
@edenreich

Copy link
Copy Markdown
Contributor Author

@infer /model ollama_cloud/glm-5.2 is it ready for merge?

@edenreich

Copy link
Copy Markdown
Contributor Author

@claude Is it ready for merge?

@inference-gateway-maintainer

inference-gateway-maintainer Bot commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @edenreich's task in 3m 25s —— View job


Merge readiness review - PR #679

  • Gather context (read changed files + diff)
  • Check CI status
  • Review memory tool implementation
  • Review config wiring & init seeding
  • Review prompts/reminders changes
  • Assess open review comments from author
  • Provide merge-readiness verdict

Verdict: functionally ready ✅ - two threads to resolve first

The implementation is solid, CI is fully green, and the test coverage is comprehensive. There's nothing blocking on the code itself. Before clicking merge, I'd just resolve the stale review threads and decide on one bundled default change (details below).

CI

Both workflow runs are green - build, lint, vet, test, and CodeQL all pass.

What I verified

  • Path-traversal safety: sanitizeSlug collapses any input to a flat [a-z0-9-] stem (no separators/dots), and there's an explicit ../evil test asserting nothing escapes the memory dir. 👍
  • Atomic writes: temp-file + rename, with a test (TestMemoryTool_NoTempLeftovers) confirming no .tmp-memory* residue.
  • Index integrity: upsert-in-place (no dupes), idempotent delete, and MEMORY.md regenerated wholesale on every change - all tested.
  • Sandbox carve-out (isWithinMemoryDir) is correctly gated on Memory.Enabled and falls back to ~/.infer/memory when Dir is empty.
  • No stale symbols: confirmed ResolveMemoryPath, Memory.Path, OperationAppend/Replace, MemoryFileName, etc. are all gone from the tree.

1. Your earlier review comments are stale (please resolve)

The 8 review comments from 13:31-13:33 all target a previous implementation - their diff_hunk context shows the single-file append/replace/remove design using filewriter, Memory.Path/UserPath, ResolveMemoryPath, and user.md. That whole approach was replaced by the current directory-of-facts model (read/write/delete, ResolveMemoryDir, dedicated atomic writer) in commit b157ccc. Those threads no longer point at existing code and can be resolved/dismissed.

2. One genuine nit still open: test import alias

internal/agent/tools/memory_test.go:10 is still unaliased:

"github.com/inference-gateway/cli/config"

Your suggestion was to alias it for consistency with memory.go (which uses config "github.com/inference-gateway/cli/config"). Purely cosmetic - lint passes either way - but it's the one suggestion that wasn't carried into the rewrite. Fix this →

Worth a conscious decision (non-blocking)

  • Reminders now default to enabled: true. This PR flips the global default (was false, issue [TASK] Refactor the prompt for remote control via channel manager #525) and ships the todo-hygiene reminder on by default for all users, not just memory users. It's documented in the PR body and the memory-consult reminder is correctly pruned when memory is off (pruneMemoryReminderIfDisabled) - just make sure flipping that global default is intended to ride along with this feature.
  • Memory is auto-approved for all operations (IsApprovalRequired returns false), including delete. Reasonable since it's confined to the memory dir, but note deletes are silent + non-recoverable by design.
  • Docs gap: the Memory tool and memory.yaml aren't mentioned in docs/tools-reference.md, docs/configuration-reference.md, or docs/directory-structure.md. Fine as a follow-up, but worth tracking.

Recommendation

Code and tests are merge-ready. I'd (1) resolve the 8 outdated review threads, (2) optionally apply the import-alias nit, and (3) confirm the reminders-on-by-default change is intended. After that, ship it. 🚀
· feat/memory-tool

@edenreich

Copy link
Copy Markdown
Contributor Author

@infer /model ollama_cloud/glm-5.2 Can you address the nit-picking from Claude?

@inference-gateway-maintainer

inference-gateway-maintainer Bot commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

View Job

I'm cooking...will get back to you soon...

Pull Request

#679

✅ Infer Result: Success

The nit from Claude's review has been addressed and pushed. No further work is needed.

Model: ollama_cloud/glm-5.2 · Exit Code: 0 · Duration: 2m 5s

Tokens: 159,763 in · 1,295 out · 161,058 total (13 requests)

Tool calls: 13 total · 100% success rate

Triggered by edenreich · Infer Action

Comment thread config/config.go Resolved
Comment thread config/config.go Resolved
Comment thread config/config.go Resolved
Comment thread internal/agent/tools/memory_test.go Resolved
Comment thread internal/agent/tools/memory_test.go Resolved
Comment thread internal/agent/tools/memory_test.go Resolved
Comment thread internal/agent/tools/memory_test.go Resolved
Comment thread internal/agent/tools/memory_test.go Resolved
Comment thread internal/agent/tools/memory_test.go Resolved
Comment thread internal/agent/tools/memory_test.go Resolved
Co-authored-by: Eden Reich <[email protected]>
@edenreich
edenreich merged commit a487b13 into main Jun 28, 2026
1 check passed
@edenreich
edenreich deleted the feat/memory-tool branch June 28, 2026 23:18
inference-gateway-releaser Bot added a commit that referenced this pull request Jun 30, 2026
## [0.126.0](v0.125.0...v0.126.0) (2026-06-30)

### 🚀 Features

* add persistent memory tool for agent ([#679](#679)) ([a487b13](a487b13))
* **agent:** interactive subagent management and unified background-work tracking ([#684](#684)) ([343e083](343e083))

### 🐛 Bug Fixes

* **chat:** bind opt+backspace and ctrl+backspace to delete-word-backward ([#697](#697)) ([173fe83](173fe83)), closes [#689](#689) [#576](#576)
* **a2a:** retain completed background tasks in /tasks ([#691](#691)) ([#701](#701)) ([43b8e13](43b8e13))
* **autocomplete:** surface arguments for one-of/all-optional tool schemas ([#698](#698)) ([655b2e4](655b2e4))

### ♻️ Code Refactoring

* add .gitignore by default to the projects dir ([4717deb](4717deb))
* enable memory by default ([86c2158](86c2158))
* make infer config userspace-first ([#682](#682)) ([1e77e42](1e77e42)), closes [#680](#680)
* **tui:** single event-loop ingress - one notifier, no self-rescheduling pollers ([#700](#700)) ([2ab8854](2ab8854))
* standardize comment punctuation by replacing em dashes with hyphens ([78f53a8](78f53a8))

### 📚 Documentation

* fix docs/ drift found by the README-to-codebase audit ([#687](#687)) ([413047a](413047a)), closes [#572](#572) [#686](#686)
* sync README and reference docs with the codebase ([#685](#685)) ([c328423](c328423)), closes [#572](#572) [#684](#684) [#684](#684)

### 👷 CI/CD

* **deps:** update CLAUDE workflow to version 0.14.5 ([eaba2b3](eaba2b3))

### 🧹 Maintenance

* add .infer to .gitignore ([08ef319](08ef319))
* **deps:** bump infer CLI v0.124.0 -> v0.125.0, infer-action v0.19.0 -> v0.19.1 ([#681](#681)) ([e9e7e21](e9e7e21))
* remove agent definitions ([4f7fd7d](4f7fd7d))
* remove unused configuration and shortcut files ([4c611db](4c611db))
* update claude-code to 2.1.191 ([729e81c](729e81c))
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.126.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant