Skip to content

feat(openclaw-memory-plugin): support per-agent memory isolation#597

Open
xudongcc wants to merge 2 commits intovolcengine:mainfrom
xudongcc:feat-openclaw-support-multiple-agents
Open

feat(openclaw-memory-plugin): support per-agent memory isolation#597
xudongcc wants to merge 2 commits intovolcengine:mainfrom
xudongcc:feat-openclaw-support-multiple-agents

Conversation

@xudongcc
Copy link

@xudongcc xudongcc commented Mar 14, 2026

Description

Use the host-provided agent ID to namespace memories so that
each agent on the same OpenClaw instance gets its own isolated
memory space. The default primary agent "main" maps to "default"
for backward compatibility with existing memories.

Related Issue

#471

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

  • Pass agentId from ctx to all OpenViking API requests
  • Update agentId config help text and placeholder
  • Add "Multi-Agent Memory Isolation" section to README
  • Fix the issue where memory_recall, memory_store, and memory_forget tools do not carry agentId
  • Fix the issue where the current implementation of modifying hooks does not consider multi-agent concurrency

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

Additional Notes

@xudongcc xudongcc force-pushed the feat-openclaw-support-multiple-agents branch from 2fb9f9d to 5d799a7 Compare March 16, 2026 13:05
@xudongcc xudongcc changed the title WIP: feat(openclaw-memory-plugin): support per-agent memory isolation feat(openclaw-memory-plugin): support per-agent memory isolation Mar 16, 2026
Copy link
Collaborator

@qin-ctx qin-ctx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good refactor — moving from the stateful setAgentId() pattern to per-request agentId parameters cleanly eliminates the async race condition in multi-agent scenarios and extends isolation to tools (not just hooks). The "main" → "default" backward-compat mapping and the composite cache key (${scope}:${agentId}) are well thought out.

Two non-blocking suggestions below. The merge conflict also needs resolution.

@xudongcc xudongcc force-pushed the feat-openclaw-support-multiple-agents branch from 5d799a7 to d743d4d Compare March 17, 2026 14:20
Use the host-provided agent ID to namespace memories so that
each agent on the same OpenClaw instance gets its own isolated
memory space. The default primary agent "main" maps to "default"
for backward compatibility with existing memories.
- Pass agentId from ctx to all OpenViking API requests
- Update agentId config help text and placeholder
- Add "Multi-Agent Memory Isolation" section to README
@xudongcc xudongcc force-pushed the feat-openclaw-support-multiple-agents branch from d743d4d to 4f41780 Compare March 17, 2026 14:22
@xudongcc
Copy link
Author

@qin-ctx

Thanks for the thorough review! Both suggestions have been addressed:

  • lastProcessedMsgCount per-agent isolation — Changed from a shared closure variable to new Map<string, number>() keyed by agentId. The agentId resolution is now moved before extractNewTurnTexts so the per-agent counter is used from the start.

  • README TOC — Added - Multi-Agent Memory Isolation to the Table of Contents.

Additionally, while resolving the merge conflict I noticed an existing TS error (Cannot invoke an object which is possibly 'null'.ts(2721)) on resolveLocalClient(client) introduced by #681's dual-context refactor. Added a non-null assertion since the call is guarded by the isSpawner check which guarantees the assignment. Fixed in a separate commit for clarity.

@Astro-Han
Copy link
Contributor

Confirmed from my side: #597 does address the multi-agent concurrency problem reported in #667.

The root cause is not just "singleton client", but shared mutable per-agent state on the client side, plus cross-agent shared counters like lastProcessedMsgCount. This PR fixes that in the right direction by passing agentId per request and isolating the message counter per agent.

It would make sense to link or close #667 after this lands.

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

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

3 participants