How suraj-ranganath/scopememory works
1. What this repository is
- ScopeMemory is an authorization control plane for long-horizon agents: it predicts likely tool use, scopes permissions narrowly, and records the decision trail.
- The repo is split between a small dependency-free demo and a more complete platform prototype.
2. Two main execution paths
- demo/ is the simplest end-to-end proof: a SQLite-backed terminal demo that shows the ReBAC/authorization concept without infrastructure.
- platform/ is the real architecture prototype: FastAPI/Uvicorn services, graph backends, policy evaluation, credential brokering, MCP integration, and review UIs.
3. Canonical state and audit
- Dolt is the authoritative store for governed memory: workflow recipes, grants, policy state, graph edges, and audit/proof records.
- The architectural intent is that authorization changes are versioned and reviewable like code, which is why the repo emphasizes branch/diff/replay semantics.
4. Context graph and derived retrieval
- The platform builds a shared context graph from sessions, tools, scopes, resources, teams, approvals, and recipes.
- memgraph_sync.py, graph_backend.py, and graph_fallback.py indicate a derived graph layer for traversal and a local fallback when the graph service is unavailable.
- person_b/ adds recipe indexing and learning-oriented fixtures, suggesting a memory-retrieval subsystem that turns prior workflows into candidate authorization facts.
5. Policy decision boundary
- Policy is not embedded in the agent; it is evaluated centrally through Datalog-style logic (cozo_policy.py, policy_contracts.py, authorization_checks.py).
- The decision model is explicit: allow, ephemeral auto-approve, escalate to human, deny, or repair malformed requests.
- The important architecture boundary is that candidate context can be proposed by retrieval/LLM systems, but the final decision is policy-driven and reproducible.
6. Identity and delegation
- platform/agentic_identity/ handles signed delegation JWTs and the IAM adapter that binds user/team/agent identity into the authorization chain.
- This is the trust anchor that lets the gateway reason about “who delegated to which agent for which workflow,” rather than relying on broad standing credentials.
7. Credential brokering and secret containment
- credential_broker.py, credential_runtime.py, onepassword_provider.py, and onepassword_readiness.py show a brokered secret path.
- The intended pattern is opaque credential leases: the agent never sees decrypted secrets; they are injected only inside the execution boundary.
- hook_adapter.py and codex_hook.py indicate pre-tool-call interception for Claude/Codex-style runtimes, so secret-bearing actions can be normalized and gated before execution.
8. MCP is the external tool boundary
- platform/mcp/ is a standalone JSON-RPC/MCP server layer with routing, handlers, registry, visibility, and safe views.
- This is the main enforcement surface for tools: the gateway can inspect a tool request, preflight it, authorize it, and then allow the MCP call to proceed with scoped permissions.
9. Gateway-centric control flow
- gateway_service.py, platform/app.py, and related modules implement the runtime that sits between agents and tools.
- The flow is: agent host sends an MCP/tool request → gateway resolves identity and context graph → policy evaluates against governed state → gateway either blocks, escalates, repairs, or issues a narrow grant/lease → execution occurs → audit is written back to canonical storage.
10. UI and operator surfaces
- platform/web/ is a React/Vite frontend for reviewing requests, proofs, and workflow state.
- platform/streamlit_app.py and platform/ui/ provide a lighter policy console / demo UI path.
- These are read-mostly operational surfaces over the same governed state, not separate sources of truth.
11. Learning and demo-specific memory
- platform/person_b/ contains a focused “learning worker,” contract fixtures, and recipe fixtures for demonstrating how past access requests become future authorization memory.
- This subsystem looks like the experimentation zone for recipe proposal, indexing, and session-driven memory shaping.
12. Infrastructure and repo organization
- The platform is packaged for local orchestration with docker-compose.yml, a Dockerfile, and run_stack.sh.
- The docs in docs/engineering-plan/ are a first-class architectural artifact: they define the RFCs, research, decisions, and roadmap that govern the code.
- For an architecture diagram, the key boxes are: agent host, identity, gateway, context graph, policy engine, Dolt, graph store/fallback, credential broker, MCP server, and review UI, with audit flowing back into Dolt.
Main entry points: gateway_service.py Gateway · graph_backend.py Context graph · cozo_policy.py Policy engine · dolt_store.py Dolt store
Components 22
Demo path
Dependency-free end-to-end authorization proof
- Demo demo · Minimal SQLite-backed ReBAC proof-of-concept
demo/run_demo.py - ReBAC logic · Tiny demo authorization model and checks
demo/rebac.py
Control plane
Gateway, identity, policy, and execution runtime
- App entry · Main platform service entrypoint
platform/app.py - Gateway · Sits between agent hosts and tools
platform/gateway_service.py - Identity · Signed delegation and IAM binding for user/team/agent identity
platform/agentic_identity - Policy engine · Central allow/deny/escalate/repair evaluation
platform/cozo_policy.py - Auth checks · Authorization request validation and policy gating helpers
platform/authorization_checks.py - Grant lifecycle · Narrow grant and lease issuance across request flow
platform/grant_lifecycle.py - Runtime exec · Executes approved actions inside constrained runtime
platform/runtime_execution.py
Governed state
Canonical storage and derived graph layer
- Dolt store · Canonical governed memory, policy state, grants, and audit trail
platform/dolt_store.py - Dolt schema · Authoritative tables and initialization for governed state
platform/dolt/schema.sql - Context graph · Shared graph of sessions, tools, scopes, resources, teams, and approvals
platform/graph_backend.py - Graph sync · Syncs governed state into Memgraph-style derived views
platform/memgraph_sync.py - Graph fallback · Local traversal fallback when graph service is unavailable
platform/graph_fallback.py
Tool boundary
MCP and credential containment
- MCP server · JSON-RPC/MCP surface for external tools
platform/mcp/server.py - Credential broker · Opaque secret injection and lease handling
platform/credential_broker.py - Hook adapter · Pre-tool-call interception and normalization for agent runtimes
platform/hook_adapter.py
Operator surfaces
Human review and console UIs
- Web UI · Browser interface for requests, proofs, and workflow state
platform/web/src/App.tsx - Policy console · Lightweight operator console for policy and demo flows
platform/streamlit_app.py
Learning
Recipe indexing and memory shaping
- Learning worker · Transforms past access into candidate authorization memory
platform/person_b/learning_worker.py - Recipe index · Indexes recipe and recipe-hit fixtures for future decisions
platform/person_b/memgraph_recipe_index.py
Architecture docs
RFCs and engineering plan
- RFCs · First-class engineering plan, decisions, and roadmap
docs/engineering-plan/README.md
Connections 24
- Demo demo → ReBAC logic: uses · The terminal demo exercises the demo authorization model
- App entry → Gateway: hosts · The platform entrypoint runs the gateway-centric runtime
- Gateway → Identity: resolves · Gateway binds user/team/agent identity before decisions
- Gateway → Context graph: loads context · Gateway consults the shared context graph for requests
- Gateway → Policy engine: evaluates · Central policy decides allow, escalate, deny, or repair
- Gateway → Auth checks: validates · Request shaping and authorization checks happen before grant
- Gateway → Grant lifecycle: issues grant · Gateway can create narrow grants or leases
- Grant lifecycle → Runtime exec: permits · Approved grants constrain execution
- Runtime exec → Credential broker: leases secrets · Secrets are injected inside the execution boundary
- Credential broker → Hook adapter: attaches to · Hooks intercept secret-bearing tool calls before execution
- Hook adapter → MCP server: gates calls · Normalized tool requests are forwarded to MCP
- Gateway → MCP server: fronts · Gateway is the enforcement surface before MCP tool access
- Dolt store → Dolt schema: defines · Schema establishes the canonical governed store
- Policy engine → Dolt store: reads state · Policy evaluation uses versioned governed memory
- Context graph → Graph sync: built by · Derived graph is kept in sync from governed state
- Context graph → Graph fallback: falls back to · Local graph traversal is used when the main service is unavailable
- Graph sync → Dolt store: syncs from · Graph ingestion derives from canonical storage
- Learning worker → Recipe index: builds · Learning worker indexes access and recipe fixtures
- Learning worker → Context graph: proposes facts · Learning feeds candidate memory into the shared graph
- Web UI → Dolt store: reviews · Review UI reads governed state and audit trails
- Policy console → Policy engine: operates · Console surfaces policy decisions and demo flows
- RFCs → Gateway: specifies · RFCs define the gateway-centric architecture
- RFCs → Policy engine: specifies · Docs define the policy and proof model
- RFCs → Credential broker: specifies · Docs define credential containment and hook behavior