feat(memory): inject_memories MVP#3027
Closed
hamza-jeddad wants to merge 6 commits into
Closed
Conversation
- 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
9cab46f to
73bb56e
Compare
- 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
73bb56e to
d7e6892
Compare
|
❌ PR Review Failed — The review agent encountered an error and could not complete the review. View logs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
inject_memories,max_inject_memories,inject_memories_strategyonAgentConfig; schema + validationinject_memoriesturn_start builtin registered on the runtime's hooks registryWithInjectMemoriesopt, teamloader,applyInjectMemoriesDefault, populateAgentName/LastUserMessagein turn_start inputlookupMemoryDB,formatMemoriesXMLwith XML escapinginvalidatingDBwrapper bumps atomic generation counterdocs/configuration/agents/,docs/tools/memory/), andexamples/inject_memories.yamlOnly the
localstrategy is shipped. Anllmstrategy 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/cacheandpkg/rag/treesitterare unrelated to this change.