Skip to content

feat: Single-DB Multi-Agent Isolation with Shared Memory Support#96

Closed
witplay wants to merge 2 commits into
Tencent:mainfrom
witplay:feat/multi-agent-isolation
Closed

feat: Single-DB Multi-Agent Isolation with Shared Memory Support#96
witplay wants to merge 2 commits into
Tencent:mainfrom
witplay:feat/multi-agent-isolation

Conversation

@witplay
Copy link
Copy Markdown

@witplay witplay commented May 26, 2026

  • Add 'agent_id' column to SQLite store for logical isolation.
  • Logic: instruction/persona types -> 'shared' (global), episodic -> '{profile}' (private).
  • Update Hermes Plugin to prefix session keys with 'agent:{profile}:'.
  • Update Gateway Recall to include 'prependContext' (L1 memories) in response.
  • Implement agent identity filtering in FTS and Vector search.
  • Includes automatic migration logic for legacy data.

Description | 描述

This PR implements Single-DB Multi-Agent Isolation with a Shared Memory area, solving the data mixing issue in multi-profile setups (Issue #31347).

💡 Core Design

Instead of using multiple databases (heavy), we use a single SQLite database with an agent_id column:

  1. Shared Memory: instruction and persona types are marked as shared. All profiles (default, xiaoxiao, zhi, etc.) share user profile and global rules.
  2. Private Memory: episodic types are strictly isolated by agent:{profile}.
  3. Migration: Includes logic to migrate legacy data (defaulting to default profile).

📂 Modified Files

  • hermes-plugin/...: Prefix session keys with agent:{profile}:.
  • src/core/store/sqlite.ts: Add agent_id column, implement shared/private logic, filter FTS/Vector search.
  • src/core/hooks/auto-recall.ts: Parse sessionKey to pass agentId.
  • src/gateway/server.ts: Include prependContext (L1 memories) in recall response.

🛡️ Benefits

  • Zero Overhead: Single file management, easy backup/migration.
  • Clean Logic: Solves the "share persona vs isolate context" dilemma cleanly.

Related Issue | 关联 Issue

Related to #31347

Change Type | 修改类型

  • Bug fix | Bug 修复A
  • New feature | 新功能
  • Documentation update | 文档更新
  • Code optimization | 代码优化

Self-test Checklist | 自测清单

  • Verified locally | 本地验证通过
  • No existing features affected | 无影响现有功能

Additional Notes | 其他说明

This approach is lightweight compared to the proposed multi-DB solution and works perfectly with SQLite's local architecture.

HasHome added 2 commits May 27, 2026 03:20
- Add 'agent_id' column to SQLite store for logical isolation.
- Logic: instruction/persona types -> 'shared' (global), episodic -> '{profile}' (private).
- Update Hermes Plugin to prefix session keys with 'agent:{profile}:'.
- Update Gateway Recall to include 'prependContext' (L1 memories) in response.
- Implement agent identity filtering in FTS and Vector search.
- Includes automatic migration logic for legacy data.
@Maxwell-Code07
Copy link
Copy Markdown
Collaborator

Thank you very much for your contribution!
We discussed internally that we will support Agent-level data isolation in subsequent versions, but the relevant core storage layer and other business code have undergone significant architectural refactoring. Due to the large scope of refactoring, external PRs based on the current architecture are likely to conflict after the later version is implemented, making it difficult to integrate directly.
Your efforts will not be in vain. In our internal design plan, we will absorb the ideas in this PR as a reference. After the new architecture is ready in the future, you are also very welcome to continue to participate in the co-construction based on the new architecture and contribute ideas and code again~
This PR will be closed first.

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