使用命名空间从单个 OpenClaw 代理管理多个项目
I’m happy to translate the article for you, but I need the actual text you’d like translated. Could you please paste the content (or the portion you want translated) here? I’ll keep the source link, formatting, markdown, and code blocks exactly as you specify.
📦 MemoClaw 命名空间 – 保持记忆隔离
如果你的 OpenClaw 代理在多个项目上工作,项目 A 的记忆可能会泄漏到 项目 B 的召回中。你可能会询问前端部署情况,却得到完全来自另一个仓库的 CI 流水线的细节。
MemoClaw 命名空间 解决了这个问题。命名空间只是一个标签,用来隔离一组记忆。存储在 project-a 命名空间中的记忆在从 project-b 召回时不会出现。概念很简单,但你采用的策略很重要。
命名空间的工作原理
每个 MemoClaw 操作都接受 --namespace 标志。如果不指定,记忆会进入 default(默认)命名空间(空字符串)。
# 存储到特定命名空间
memoclaw store "Frontend uses Next.js 14 with app router" \
--namespace website-redesign --tags "stack"
# 只从该命名空间召回
memoclaw recall "what framework are we using" --namespace website-redesign
# 列出命名空间中的记忆
memoclaw list --namespace website-redesign
# 查看所有命名空间
memoclaw namespace list
# 查看每个命名空间的记忆计数
memoclaw namespace stats
website-redesign 中的记忆对未指定该命名空间的召回是不可见的。
策略 1 – 每个项目一个命名空间
最简单的方法:为每个项目(或仓库)分配一个独立的命名空间。
# Working on the API
memoclaw store "Rate limiting set to 100 req/min per user" \
--namespace memoclaw-api --tags "config"
# Working on the docs site
memoclaw store "Docs use Mintlify, deploy via GitHub integration" \
--namespace memoclaw-docs --tags "infra"
# Working on a client project
memoclaw store "Client wants Material UI, no Tailwind" \
--namespace client-acme --tags "preference"
切换上下文时,切换命名空间。你的代理的记忆仍然保持相关。
命名约定 – 使用仓库名称或项目 slug,全部小写并使用连字符,例如:
memoclaw-api
website-v2
client-acme
Strategy 2 – Shared + project namespaces
一些知识适用于所有场景(编码偏好、沟通风格、基础设施细节)。将其存放在 default 命名空间中,将项目特定的事实保存在具名命名空间里。
Shared knowledge (default namespace)
memoclaw store "Always use pnpm. Never npm or yarn." \
--importance 0.8 --tags "preference"
memoclaw store "Preferred commit format: conventional commits" \
--tags "preference"
memoclaw store "Use TypeScript for all new code" \
--tags "preference"
Project‑specific knowledge
memoclaw store "This project uses Drizzle ORM, not Prisma" \
--namespace client-acme --tags "stack"
Important: MemoClaw 并不会在一次调用中自动同时搜索默认命名空间和具名命名空间。你需要进行两次召回:
# 项目特定召回
memoclaw recall "what ORM to use" --namespace client-acme
# 回退到共享知识
memoclaw recall "what ORM to use"
Making the agent check both automatically
使用 OpenClaw 技能时,指示你的代理依次运行这两个召回(或合并结果),这样它就会始终同时考虑共享记忆和项目特定记忆。
TL;DR
- Namespaces isolate memories – 在每个命令上使用
--namespace。 - One‑namespace‑per‑project 方式简洁且易于推理。
- Shared + project namespaces 让你可以在默认命名空间中保存通用偏好,同时在具名命名空间中隔离项目特定事实。
- 需要合并知识时,记得同时查询两个命名空间(或让代理自动完成)。
内存召回模式
当为任务回忆上下文时:
- 首先 从当前项目命名空间中召回。
- 然后 从默认命名空间中召回通用偏好。
- 合并 结果——项目特定信息优先。
两次召回总计 $0.01。为干净的上下文值得。
Strategy 3 – 客户隔离
如果您处理多个客户,命名空间就成为隐私边界。
memoclaw store "Client A uses AWS, us-east-1" \
--namespace client-a --tags "infra"
memoclaw store "Client B is on GCP, europe-west1" \
--namespace client-b --tags "infra"
在 client-a 中的检索永远不会返回客户端 B 的详细信息。
提示: 对于自由职业者和机构,请从第一天起采用此模式。比起以后解开混合的记忆池,从一开始就正确使用命名空间要容易得多。
Strategy 4 – 环境命名空间
按环境分隔知识:
memoclaw store "Prod database: neon-prod-xyz.neon.tech, 64 connections max" \
--namespace prod --tags "database"
memoclaw store "Staging resets every Sunday night via cron" \
--namespace staging --tags "ops"
在排查问题时回忆 --namespace prod,可确保获取 生产特定 的细节,而不是暂存环境的配置。
将现有记忆迁移到命名空间
使用 migrate 命令并指定目标命名空间:
memoclaw migrate ~/projects/acme/docs/ --namespace client-acme
memoclaw migrate ~/notes/general/
对于已经存储的记忆,导出、编辑命名空间字段,然后重新导入:
memoclaw export -O all-memories.json
# 编辑文件 — 添加命名空间字段
memoclaw import namespaced-memories.json
何时 不 使用命名空间
如果满足以下情况,可跳过命名空间:
- 您只在 一个项目 上工作。
- 您的代理一次只处理 一个上下文。
- 您总共拥有 少于 100 条记忆。
在以下情况下使用命名空间:
- 您从第一天起就有 多个项目。
- 您进行 客户工作,需要隔离。
- 您的记忆池将 快速增长。
命名空间命名约定
| 模式 | 示例 | 使用时机 |
|---|---|---|
| 仓库名 | memoclaw-api | 开源或内部项目 |
| 客户标识 | client-acme | 客户工作 |
| 环境 | prod, staging | 运维和基础设施上下文 |
| 域 | frontend, backend | 大型 monorepo 团队 |
- 避免 空格、大写字母和特殊字符。
- 仅使用 连字符。
- 将命名空间名称视为 分支名称。
综合示例
一个用于管理三个项目的 OpenClaw 代理的实用设置:
memoclaw init
# Shared preferences (default namespace)
memoclaw store "Use TypeScript, pnpm, conventional commits" \
--importance 0.8 --tags "preference"
memoclaw store "Keep PRs under 400 lines. Split if larger." \
--importance 0.7 --tags "preference"
# Project namespaces
memoclaw migrate ~/projects/api/docs/ --namespace api-service
memoclaw migrate ~/projects/web/docs/ --namespace web-app
memoclaw migrate ~/projects/mobile/docs/ --namespace mobile-app
clawhub install anajuliabit/memoclaw
在 AGENTS.md 中
# Agents
OpenClaw 代理
- Namespaces:
default,api-service,web-app,mobile-app - Preferences: TypeScript, pnpm, conventional commits
- Usage:
- 使用
memoclaw recall --namespace检索项目特定的上下文。 - 在需要时回退到默认偏好设置。
- 使用
With this structure, you get clean, isolated recall while keeping shared preferences readily available.
MemoClaw 名称空间
活动项目及其名称空间
- api‑service – 后端 API(Node.js、Hono、Drizzle)
- web‑app – 营销站点(Next.js、Tailwind)
- mobile‑app – iOS 应用(Swift、SwiftUI)
使用方法:
在处理项目时,使用对应的名称空间调用memoclaw_recall。
对于通用偏好,使用 default 名称空间。
全屏模式(示例 UI)
Enter fullscreen mode
Exit fullscreen mode
MemoClaw – 为 AI 代理提供的记忆即服务。
100 次免费 API 调用,无需注册。
https://memoclaw.com/
