Skip to content

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

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

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.
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.

1 participant