Skip to content

Conversation

@jmoraispk
Copy link

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: true is 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 own SupermemoryClient instance 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 (perAgentKeys defaults to false).

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

File Change
client-manager.ts (new) ClientManager class — lazy cache of SupermemoryClient per agentId, reads auth-profiles to resolve per-agent keys
config.ts Add perAgentKeys: boolean option (default: false)
index.ts Use ClientManager; resolve correct client per hook invocation via ctx.agentId
tools/search.ts Accept getClient() resolver instead of fixed client
tools/store.ts Same
tools/forget.ts Same
tools/profile.ts Same

How It Works

  1. Plugin starts: creates a global SupermemoryClient (existing behavior) + a ClientManager wrapper
  2. On each hook invocation (before_agent_start, agent_end), the ctx.agentId is used to resolve the right client
  3. ClientManager.getClient(agentId) checks ~/.openclaw/agents/<agentId>/agent/auth-profiles.json for a supermemory provider entry
  4. If found: creates and caches a per-agent client with that key
  5. If not found: returns the global client
  6. Tools use a getClient() closure that resolves to the current agent's client

Configuration

{
  "plugins": {
    "entries": {
      "openclaw-supermemory": {
        "enabled": true,
        "config": {
          "apiKey": "${SUPERMEMORY_OPENCLAW_API_KEY}",
          "perAgentKeys": true
        }
      }
    }
  }
}

Tests

  • tsc --noEmit passes (zero type errors)
  • biome ci . passes (zero lint/format errors)
  • No existing tests in the repo to verify against

Sign-Off

  • Models used: Claude claude-4.6-opus
  • Submitter effort: Medium — new ClientManager + wiring changes across 7 files

Made with Cursor

When `perAgentKeys: true` is set in plugin config, the plugin
resolves per-agent SuperMemory API keys from OpenClaw auth-profiles
(~/.openclaw/agents/<agentId>/agent/auth-profiles.json).

Each agent gets its own SupermemoryClient with a scoped API key,
enabling isolated memory containers per user. Falls back to the
global API key when no per-agent key is found.

Changes:
- New ClientManager class (client-manager.ts) with lazy per-agent cache
- config.ts: add perAgentKeys option (default: false, backward compatible)
- index.ts: use ClientManager; resolve client per hook invocation via ctx.agentId
- tools/*.ts: accept getClient() resolver instead of fixed client instance

Co-authored-by: Cursor <cursoragent@cursor.com>
@jmoraispk
Copy link
Author

Hey @Dhravya
Can you take a quick look?

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