feat: per-agent API key support for multi-user setups #14
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.
Summary
Adds support for per-agent SuperMemory API keys, enabling multi-user OpenClaw setups where each user gets isolated memory containers via scoped API keys.
When
perAgentKeys: trueis set in plugin config, the plugin reads per-agent API keys from OpenClaw's auth-profiles (~/.openclaw/agents/<agentId>/agent/auth-profiles.json). Each agent gets its ownSupermemoryClientinstance with its scoped key. Falls back to the global API key when no per-agent key is found.Fully backward compatible — default behavior is unchanged (
perAgentKeysdefaults tofalse).Use Case
In a multi-user OpenClaw deployment, each user is mapped to a separate OpenClaw agent. With SuperMemory scoped API keys, each user's memories are isolated in their own container. This PR enables the plugin to use different API keys per agent, so each user's memory operations go through their scoped key.
Changes
client-manager.ts(new)ClientManagerclass — lazy cache ofSupermemoryClientper agentId, reads auth-profiles to resolve per-agent keysconfig.tsperAgentKeys: booleanoption (default:false)index.tsClientManager; resolve correct client per hook invocation viactx.agentIdtools/search.tsgetClient()resolver instead of fixed clienttools/store.tstools/forget.tstools/profile.tsHow It Works
SupermemoryClient(existing behavior) + aClientManagerwrapperbefore_agent_start,agent_end), thectx.agentIdis used to resolve the right clientClientManager.getClient(agentId)checks~/.openclaw/agents/<agentId>/agent/auth-profiles.jsonfor asupermemoryprovider entrygetClient()closure that resolves to the current agent's clientConfiguration
{ "plugins": { "entries": { "openclaw-supermemory": { "enabled": true, "config": { "apiKey": "${SUPERMEMORY_OPENCLAW_API_KEY}", "perAgentKeys": true } } } } }Tests
tsc --noEmitpasses (zero type errors)biome ci .passes (zero lint/format errors)Sign-Off
Made with Cursor