Skip to content

feat: Add MemAgent automatic chat+embedding storage and demo script#5

Closed
billcache wants to merge 5 commits intomainfrom
feature/programming_mem
Closed

feat: Add MemAgent automatic chat+embedding storage and demo script#5
billcache wants to merge 5 commits intomainfrom
feature/programming_mem

Conversation

@billcache
Copy link
Copy Markdown
Contributor

Description

What problem does this solve?

  • Enables MemAgent to automatically persist every user input, agent response, and their vector embeddings after each interaction.
  • Provides a clear, testable workflow for semantic memory and future retrieval.
  • Adds a demo script and documentation so users can easily verify and understand the feature.

How did you solve it?

  • Integrated a fire-and-forget call in MemAgent.run to save user input, response, embeddings, timestamp, and session ID to a local vectordb (JSON file).
  • Extended the storage logic and types to support session metadata.
  • Added/updated tests to cover the new workflow, including ESM-compatible mocking.
  • Created demo-agent.ts to show end-to-end usage, and updated the README with clear instructions.

Any breaking changes?

  • No breaking changes. All new features are backward compatible and opt-in.

Testing performed

  • Added and ran unit/integration tests for the new storage logic and MemAgent integration.
  • Manually ran the demo script to verify that chat interactions and embeddings are correctly saved and retrievable.
  • All tests pass after fixing ESM mocking issues.

- Added a new CLI tool for simulating chat interactions with OpenAI and storing user queries and AI responses as vector embeddings.
- Introduced `LongTermProgrammingMemory` for managing programming memory entries and chat interactions.
- Enhanced `OpenAIService` with embedding generation capabilities.
- Updated `MemAgent` to automatically save chat interactions and embeddings.
- Added demo script for testing the chat simulation and memory storage.
- Updated README with usage instructions and configuration details.
- Updated `package.json` and `package-lock.json` for dependency management.
@ngduyanhece
Copy link
Copy Markdown
Contributor

@namanhoxcam here are some comment can you help to adjust

  1. i see the change in readme but please double check to include the readme with only your change that you need
  2. i see you update the type node version; please check if you really need it
  3. you would ne to implement memory as a seperated services; check out the current services under the brain folder to follow the pattern
  4. you should leverage the vectordb to save instaed of storing it into a file path

billcache added 3 commits July 1, 2025 22:33
…t interaction storage

- Replaced LongTermProgrammingMemory with MemoryService for managing chat interactions.
- Implemented QdrantClientService for vector storage of chat memory entries.
- Added isProgrammingRelatedLLM utility to check programming relevance of messages.
- Updated MemAgent to save chat interactions based on programming relevance.
- Removed deprecated long-term memory and demo agent files.
- Enhanced tests for MemAgent and MemoryService integration.
@ngduyanhece
Copy link
Copy Markdown
Contributor

Screenshot 2025-07-02 at 08 40 58 got the error when run the build; also can you change the brain/services to brain/memory the name services is not appropriate add the option so that we can run with qdrant cloud (with API) key

- Introduced MemoryService for handling chat interactions with support for both file and Qdrant backends.
- Implemented QdrantClientService for vector storage and retrieval of chat memory entries.
- Updated MemAgent to utilize MemoryService and QdrantClientService for improved chat interaction storage.
- Revised README to clarify Qdrant configuration and usage instructions.
- Added tests for MemoryService and QdrantClientService to ensure functionality and error handling.
@ngduyanhece ngduyanhece closed this Jul 6, 2025
@ngduyanhece ngduyanhece deleted the feature/programming_mem branch July 6, 2025 11:25
RyanNg1403 added a commit that referenced this pull request Apr 13, 2026
Fixes applied (6):
- #1: Path traversal guard — safePath() validates all file paths stay
  within contextTreeDir before write/delete
- #2: SYNTHESIZE/UPDATE throws instead of deleting pre-existing file
  (previousTexts not captured for synthesize operations)
- #3: Remove unnecessary `as number` cast — TypeScript narrows
  log.completedAt after status checks
- #5: Manifest rebuild errors now reported in result.errors instead
  of silently swallowed
- #6: unlinkSafe() only swallows ENOENT, rethrows permission errors
- #9: Added test for SYNTHESIZE/UPDATE error path

Skipped (4):
- #4: lastDreamLogId intentionally NOT cleared — keeping it allows
  "Dream already undone" error which is more informative than
  "No dream to undo" on double-undo
- #7: resolveProject() fallback to cwd follows existing codebase
  pattern (curate/view.ts uses the same approach)
- #8: No exhaustiveness check in switch — silent no-op is correct
  for undo of unknown future operation types (safer than crashing)
- #10: No lastDreamLogId assertion in test — follows from #4 skip
This was referenced Apr 13, 2026
cuongdo-byterover added a commit that referenced this pull request Apr 14, 2026
Blocking (5 fixes):
- #1: Bound resolveUniqueFilename loop to MAX_SUFFIX=10000 with
  timestamp fallback (local-markdown-adapter)
- #2: Make GBrain bin resolution lazy — execFileSync no longer runs
  in constructor, deferred to first executor use
- #3: Replace execFileSync with async execFileAsync in config-validator
  (validateGBrain is now async)
- #4: Add MAX_ARG_LENGTH guard (200KB) in execBrvCurate to prevent
  E2BIG on large content
- #5: Bound memory-wiki store() filename loop with same pattern

Medium (6 fixes):
- #6: Remove unreachable 'creative' from QueryType union and
  SELECTION_MATRIX
- #8: Replace this.index! non-null assertions with explicit null
  guards in obsidian and local-markdown adapters
- #9: Fix byterover writeSupported: true → false in
  createDefaultCapabilities (matches adapter)
- #10: Replace 'as' type assertion with instanceof narrowing in
  execBrvCurate error handler
- #11: Replace 'as Error' assertions with instanceof checks in
  swarm curate and query CLI commands
- Stale JSDoc: remove 'creative' from router comment

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
RyanNg1403 added a commit that referenced this pull request Apr 16, 2026
Addresses 10 review items from RyanNg1403 (Claude Code) and ChatGPT Codex
on PR #434. Two real bugs (1× P1, 1× P2) found by Codex; the rest are
documentation / test-assertion improvements from RyanNg.

P1 (Codex) — task-router pre-dispatch skip polluted AgentPool counter
preDispatchCheck's ineligible branch routed through handleTaskCompleted,
which unconditionally calls agentPool.notifyTaskCompleted(projectPath).
But the task was never submitted to the pool, so decrementing activeTasks
under-represents real load and can let drainQueue dispatch an extra
queued task beyond per-agent concurrency.

Fix: extracted handleTaskSkippedByPreCheck — emits task:completed to
client + project room and calls moveToCompleted, but skips
notifyTaskCompleted AND lifecycle hooks (also resolves RyanNg #5 which
flagged the lifecycle-hook side of the same call site). Three new
regression tests assert the pool counter and onTaskCompleted hooks are
not touched on skip, while the project broadcast still fires.

P2 (Codex) — duplicate review entries on late dream failures
dream-executor's success path runs createReviewEntries (step 6b), then
dreamStateService.update (step 7). If step 7 throws, control jumps to
catch which re-invokes createReviewEntries on the same allOperations,
producing duplicate pending review entries.

Fix: reviewEntriesWritten boolean set after the success-path call;
catch-path call gated on !reviewEntriesWritten in addition to the
existing allOperations.length > 0 invariant. One new regression test
forces step 7 to throw after step 6b succeeds and asserts
createReviewEntries is invoked exactly once.

Doc / test improvements
- dream-state-service.ts: comment on stateMutexes' monotonic growth
  bound (#1); JSDoc on write() cross-referencing update() to warn
  against bypassing the mutex (#2).
- consolidate.ts: JSDoc on loadAndClearPendingMerges explaining the
  intentional two-phase access pattern (unguarded read for hints +
  mutex-guarded update for clear) and the fail-open behavior when the
  initial read throws (#3, #4).
- consolidate.test.ts: assert update.calledOnce instead of
  write.calledOnce — surfaces intent (the contract) rather than the
  stub's implementation detail (#8).

Verification
- Lint: 0 errors (perfectionist/sort-classes flagged class-member order
  during audit; resolved by repositioning handleTaskSkippedByPreCheck
  alphabetically between handleTaskError and handleTaskStarted).
- Typecheck: clean.
- Unit tests: 6238 passing, 16 pre-existing pending, 0 failing.
- /brv-code-quality skill: passed all 6 audit gates.
Sign up for free to 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