Skip to content

feat(memory): inject_memories MVP#3027

Closed
hamza-jeddad wants to merge 6 commits into
mainfrom
feat/inject-memories
Closed

feat(memory): inject_memories MVP#3027
hamza-jeddad wants to merge 6 commits into
mainfrom
feat/inject-memories

Conversation

@hamza-jeddad

Copy link
Copy Markdown
Contributor

Implements the inject_memories feature (epic #3011).

The runtime now automatically retrieves relevant memories at the start of every turn and injects them as a transient system message — no model call required.

Commits:

Only the local strategy is shipped. An llm strategy is planned for a future release (noted in schema description).

Testing: All new code tested with table-driven unit tests. Pre-existing failures in pkg/cache and pkg/rag/treesitter are unrelated to this change.

@hamza-jeddad hamza-jeddad requested a review from a team as a code owner June 8, 2026 20:52
@aheritier aheritier added area/agent For work that has to do with the general agent loop/agentic features of the app area/config For configuration parsing, YAML, environment variables kind/feat PR adds a new feature (maps to feat: commit prefix) labels Jun 8, 2026
- Add InjectMemories, MaxInjectMemories, InjectMemoriesStrategy fields to AgentConfig
- Add InjectMemoriesStrategyLocal constant and DefaultMaxInjectMemories = 10
- Add validateInjectMemories() method called from Config.Validate()
- Add inject_memories, max_inject_memories, inject_memories_strategy to agent-schema.json
  (only 'local' strategy shipped; 'llm' planned for a future release)
- Add table-driven tests covering valid and invalid configurations
- Add BuiltinInjectMemories constant and injectMemoriesBuiltin method on LocalRuntime
- Register builtin in NewLocalRuntime alongside cache_response
- No-op implementation; retrieval logic lands in #3013
- Add unit test for no-op return contract
- Add injectMemories/maxInjectMemories fields and accessors to Agent
- Add WithInjectMemories opt to pkg/agent/opts.go
- Wire WithInjectMemories in teamloader alongside other agent flags
- Add applyInjectMemoriesDefault() mirroring applyCacheDefault pattern
- Add effectiveMaxInjectMemories() fallback helper
- Wire applyInjectMemoriesDefault into buildHooksExecutors
- Populate AgentName and LastUserMessage in executeTurnStartHooks input
- Expand tests: applyInjectMemoriesDefault and effectiveMaxInjectMemories
@hamza-jeddad hamza-jeddad force-pushed the feat/inject-memories branch from 9cab46f to 73bb56e Compare June 8, 2026 21:04
- Add InjectMemoriesStrategy field/accessor to Agent; update WithInjectMemories
- Add DB() and SetDB() accessors to memory.ToolSet
- Add inject_memories_bm25.go: self-contained BM25 ranker (k1=1.5, b=0.75)
  matching pkg/rag/strategy/bm25.go tokenisation for consistency
- Implement injectMemoriesBuiltin with 'local' strategy:
  GetMemories → BM25 rank → XML inject as AdditionalContext
- lookupMemoryDB resolves first memory toolset from agent.ToolSets()
- formatMemoriesXML wraps hits in <memories>...</memories> with XML escaping
- Degrade gracefully: no toolset, empty DB, zero hits all return nil
- Add BM25 unit tests and full pipeline integration tests with fake DB
- Add memorySnapshotCache (RWMutex + double-check) to avoid SQLite hit per turn
- Add invalidatingDB wrapper that bumps atomic generation counter on writes
- Wire memSnapshots and memDBs/memDBsMu onto LocalRuntime struct
- Initialise memSnapshots in NewLocalRuntime
- Update lookupMemoryDB to memoize invalidatingDB wrapper; call mt.SetDB so
  writes through agent memory tools (add_memory etc.) also bump the counter
- injectMemoriesBuiltin uses snapshot cache for local strategy
- Tests: cache hit, invalidation on add/update/delete, concurrent reads,
  failed-write does not advance generation, atomic gen counter
- Add examples/inject_memories.yaml (validated by TestJsonSchemaWorksForExamples)
- Add Inject Memories section to docs/configuration/agents/index.md:
  config table, strategies, FAQ (transient injection, snapshot invalidation)
- Add three new fields to agent schema table in agents/index.md
- Append 'See also' link from docs/tools/memory/index.md
- Update AGENTS.md: note inject_memories as runtime-private auto-injected hook
@hamza-jeddad hamza-jeddad force-pushed the feat/inject-memories branch from 73bb56e to d7e6892 Compare June 8, 2026 21:09
@docker-agent

Copy link
Copy Markdown

PR Review Failed — The review agent encountered an error and could not complete the review. View logs.

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

Labels

area/agent For work that has to do with the general agent loop/agentic features of the app area/config For configuration parsing, YAML, environment variables kind/feat PR adds a new feature (maps to feat: commit prefix)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants