Agent RBAC
Stable in docs/STATUS.md. Mnemosyne is alpha, on the 3.6.x line, and the
API can still change within 3.x.
Three layers
- Workspace isolation. Postgres row-level security keeps workspaces apart.
- Key scopes and sensitivity ceiling. An API key carries scopes and a ceiling. A read above the ceiling answers 404.
- Agent policy. Inside one workspace, a policy can narrow what a given agent may do. This page is about the third layer.
Scopes
There are 15 memory scopes (SPEC_SCOPES in packages/types/src/security.ts):
memory:read memory:write memory:delete memory:hard_delete
memory:session memory:task memory:event memory:self_edit
memory:procedural memory:reasoning memory:export memory:admin
memory:federation memory:governance memory:subscribeThe server maps each request to one scope from its method and path. For
example, POST /recall needs memory:read, any DELETE needs
memory:delete, and a path ending in /hard needs memory:hard_delete.
The agent policy
interface AgentMemoryAccess {
agentId: string;
workspaceId: string;
readScopes: SpecScope[];
writeScopes: SpecScope[];
selfEdit: { enabled: boolean; maxWorthDelta?: number };
taskScopes: {
canCreate: boolean;
canDelegate: boolean;
canDelegateTo: string[];
};
limits: {
maxRecallsPerMinute: number;
maxWritesPerMinute: number;
maxSessionsConcurrent: number;
maxSelfEditsPerSession: number;
};
requireApprovalFor: ApprovalTrigger[];
federationAccess: "none" | "read" | "read_write";
}A stored policy can also carry namespaces, an allow-list. An entry ending in
* matches by prefix.
How a request is checked
packages/server/src/middleware/rbac-policy.ts loads the policy for the calling
agent, caches it in the server process for 60 seconds, and calls
evaluateAccess (packages/core/src/cognitive/rbac-engine.ts):
- Scope. If the request’s scope is not in
readScopes(for a read) orwriteScopes(for a write), the request is denied with 403. - Namespace. If the policy has
namespacesand the request declares one, with thex-mnemo-namespaceheader or?namespace=, it must match. - Federation. A request to a federation path needs
federationAccessofread, orread_writefor a write. - Approval. If the action is in
requireApprovalFor, it is not executed until someone approves it.
No policy means no restriction: an agent without a policy passes through.
Set MNEMO_RBAC_DEFAULT_DENY=true to deny such agents.
Rate limits
maxRecallsPerMinute and maxWritesPerMinute are counted per agent in fixed
60-second windows. The response carries X-RateLimit-Limit,
X-RateLimit-Remaining and X-RateLimit-Reset, and a request over the limit
is refused with Retry-After. The counters need Redis. If the counter store is
missing or fails, the limit is not enforced.
Approvals
| Trigger | Fires on |
|---|---|
delete_fact | DELETE on a facts path |
overwrite_decision | PUT on a decisions path |
write_entity | POST or PATCH on an entities path |
bulk_export | An export path |
federation_share | A federation path |
procedural_evolution | A procedural path |
task_delegation | A delegate path |
cross_agent_read | A read with x-mnemo-target-agent naming another agent |
An approval request is tied to a user, so the calling key must be bound to one. A different user resolves it:
GET /approvals/:id
POST /approvals/:id/resolve { "status": "approved" | "denied" }The original request is then sent again with the x-mnemo-approval-id header.
Managing policies
Policies are stored in Postgres (DrizzleAccessPolicyStore in
packages/adapter-postgres). An agent is identified by the id of its API key.
Four routes manage them with a memory:admin key: list every policy in the
workspace, read one, create or replace one (agentId in the body) and delete
one.
GET /admin/agent-policies
GET /admin/agent-policy?agentId=...
PUT /admin/agent-policy
DELETE /admin/agent-policy?agentId=...The CLI wraps them:
mnemo policy list
mnemo policy get 6f1c2d3e-0000-4000-8000-000000000001
mnemo policy set 6f1c2d3e-0000-4000-8000-000000000001 --file acme-agent-policy.json
mnemo policy delete 6f1c2d3e-0000-4000-8000-000000000001set sends the whole policy from a JSON file. namespaces is optional, and a
limit of 0 means unlimited:
{
"readScopes": ["memory:read"],
"writeScopes": ["memory:write"],
"selfEdit": { "enabled": false },
"taskScopes": { "canCreate": true, "canDelegate": false, "canDelegateTo": [] },
"limits": {
"maxRecallsPerMinute": 600,
"maxWritesPerMinute": 120,
"maxSessionsConcurrent": 10,
"maxSelfEditsPerSession": 3
},
"requireApprovalFor": ["delete_fact", "bulk_export"],
"federationAccess": "none",
"namespaces": ["acme-*"]
}- The agent id goes in the query string or the body, never in the path.
- The body is strict: an unknown field or scope answers 400. It cannot name a workspace, which always comes from the key.
- A key cannot change its own policy (403), so a restricted agent that holds
memory:admincannot lift its own limits. - Each write is audited as
admin_accessonagent_policy. - Without a policy store the routes answer 503.
- A change applies at once on every replica when
MNEMO_REDIS_URLis set: the write is announced over Redis pub/sub (mnemo:rbac:policy-invalidate) and each replica drops its cached copy. Without Redis it applies at once on the server that took it, and within about a second on the others: a trigger records every policy write in the same transaction (migration 0067), and each replica reads that record every second, also through pgBouncer in transaction mode. The poll runs with Redis too, so a replica that missed an announcement catches up. If the poll fails, the log says so once and the 60-second cache is the bound. An hourly job,mnemo.policy.change.purge, trims the record. - The TypeScript client has
listAgentPolicies,getAgentPolicy,putAgentPolicyanddeleteAgentPolicy.