Skip to content

Repository Planning Graph (RPG)

The Repository Planning Graph (RPG) indexes the structural and semantic graph of a codebase: directories, files, modules, classes, functions, imports, and data flows. Agents can then ask questions, plan changes, and check for conflicts against a live, queryable model of the repository. Stored next to MemoryLayer’s memories, it gives agents a shared view of both what was decided (memory) and what the code is (graph).

RPG ships as memorylayer-server-rpg, an open-source (Apache-2.0) server plugin released alongside MemoryLayer since 0.2.0.

Install

Installing the plugin also installs the matching memorylayer-server version. No other configuration is needed: the server discovers the plugin through the memorylayer_server.plugin_packages entry point and registers its routes, task handlers, service, and ontology contribution automatically.

Terminal window
pip install memorylayer-server-rpg
memorylayer serve # /v1/rpg is now available

The official scitrera/memorylayer-server Docker image already includes the plugin.

Why RPG?

Agents that work on code without a planning graph keep rediscovering the same structural facts every time their context resets:

  • “Where is authenticateUser called from?”
  • “Which files would change if I rename this class?”
  • “Two agents are working in parallel. Do their tasks conflict?”
  • “What’s the actual data flow between auth/ and db/?”

RPG persists these answers as a graph in MemoryLayer. Nodes are memories and edges are associations, so the usual MemoryLayer tools (recall, graph traversal, graph analysis) work on the code graph side by side with conversation memory. RPG also works with every compatible storage backend, because it needs no database of its own.

RPG gives you:

  • A canonical graph of directories, files, modules, packages, classes, interfaces, functions, methods, and components
  • Overlay contexts (rpg-task-*, rpg-intent-*) so each in-flight task or intent has its own staging graph that can be merged with the canonical view
  • Conflict detection between concurrent tasks at the file and symbol level
  • LLM enrichment that adds feature groupings, one-line descriptions, and data-flow edges on top of the structural graph. Because data flow is traced across languages and service boundaries, this also works for microservice monorepos.
  • Maintenance operations (validate, cleanup, statistics, recompute counts) so the graph stays healthy as the repository evolves

Architecture at a Glance

┌─────────────────────────────────────────────────────────────┐
│ Indexer / IDE / Agent ─────► /v1/rpg/sync ──► RpgService │
│ (emits nodes + edges) │
│ MemoryLayer storage │
│ ┌──────────────────────────┐ │
│ │ Memory (rpg_* subtypes) │ │
│ │ Association (edges) │ │
│ └──────────────────────────┘ │
│ Agent ─────► /v1/rpg/{subgraph,search,merged-subgraph, │
│ conflicts,...} ──► reasons + plans │
└─────────────────────────────────────────────────────────────┘
  • Routes are registered under /v1/rpg.
  • RPG reuses the core storage backend.
  • It uses the same authentication and authorization as the rest of MemoryLayer: reads need memories:read and mutations need memories:write. Denials return 403.
  • With the Aether transport, on-behalf-of delegation makes every graph mutation attributable to a specific agent acting for a specific user.

What Gets Indexed

Your indexer emits nodes and edges. RPG does not parse source code itself.

Node typeRepresents
rpg_directoryA folder in the repo
rpg_fileA source file
rpg_module / rpg_packageLanguage-level module / package boundary
rpg_class / rpg_interfaceClass / interface declaration
rpg_function / rpg_methodTop-level function / class method
rpg_componentHigher-level feature component

Node IDs are the path for files and directories and path:QualifiedName for symbols. Each node carries path, name, an optional description, language, parent_id, and free-form metadata such as line numbers and signatures.

Edges use the code_structure relationship category that the plugin adds to the ontology: contains, inherits, invokes, imports, composes, and data_flow. Each has an inverse (contained_by, inherited_by, and so on). See the Relationship Types Reference.

API Surface (under /v1/rpg)

All routes are workspace-scoped through the authenticated principal.

Sync

POST /v1/rpg/sync

This call bulk-upserts a snapshot of nodes and edges. Other body fields:

FieldDefaultDescription
full_syncfalseTreat the snapshot as complete and delete nodes and edges that are missing from it
source_commit—Git commit the snapshot was generated from
context_idrpgPartition to write: rpg (canonical), rpg-task-<id>, or rpg-intent-<id>
task_id—Task ID for provenance

A full sync of the canonical rpg context automatically schedules LLM enrichment. The response reports nodes and edges created, updated, and deleted, plus sync_time_ms.

Query

EndpointPurpose
GET /v1/rpg/subgraphNeighbourhood rooted at a file path or node_id. Takes depth (default 3, max 10), node_types, relationship_types, context_id, and max_nodes (default 2000).
GET /v1/rpg/searchFree-text search across node names, descriptions, and paths (limit 20)
GET /v1/rpg/nodesEnumerate nodes, optionally filtered by node_type
GET /v1/rpg/statusNode and edge counts plus the last synced commit for a workspace
GET /v1/rpg/merged-subgraphBase context plus an overlay context, merged (for example, canonical plus a task’s intent)

Overlays

EndpointPurpose
GET /v1/rpg/overlaysList active rpg-task-* / rpg-intent-* contexts
DELETE /v1/rpg/overlays/{context_id}Drop an entire overlay
DELETE /v1/rpg/nodesBulk delete by node ID
DELETE /v1/rpg/edgesBulk delete by association ID

Conflict Detection

EndpointPurpose
GET /v1/rpg/conflicts?task_id=...File-level conflicts between this task’s intent and other active intents
GET /v1/rpg/conflicts/symbols?task_id_a=...&task_id_b=...Symbol-level conflicts between two task overlays. high means the same symbol; medium means the same file.

This is what makes RPG load-bearing for multi-agent workflows. Before letting two agents merge in parallel, an orchestrator can call /conflicts/symbols to check whether they touch the same code.

Enrichment and Maintenance

EndpointPurpose
POST /v1/rpg/enrichRun LLM enrichment phases (features, descriptions, data_flows; all by default) in a context_id, as a background task ("async": true, the default) or inline
POST /v1/rpg/maintenance/{op}validate, cleanup, statistics, cleanup_intents, or recompute_counts

SDKs

The Python and TypeScript SDKs expose the whole surface as client.rpg (sync_client.rpg for synchronous Python). The Go SDK exposes it as client.Rpg.

result = await client.rpg.sync(
nodes=[{"node_id": "src/auth/login.ts", "node_type": "rpg_file",
"path": "src/auth/login.ts", "name": "login.ts", "language": "typescript"}],
edges=[],
full_sync=False,
source_commit="3f2c1ab",
)
subgraph = await client.rpg.get_subgraph(path="src/auth/login.ts", depth=2)
conflicts = await client.rpg.get_symbol_conflicts("task-42", "task-43")

Example: Subgraph Around a File

Terminal window
curl "$MEMORYLAYER_URL/v1/rpg/subgraph?path=src/auth/login.ts&depth=2" \
-H "Authorization: Bearer $API_KEY"

This returns the node for src/auth/login.ts, the classes and functions it declares, what it imports, and one more hop: enough to brief an agent before it edits the file.

Example: Conflict Check Between Two Task Overlays

Terminal window
curl "$MEMORYLAYER_URL/v1/rpg/conflicts/symbols?task_id_a=task-42&task_id_b=task-43" \
-H "Authorization: Bearer $API_KEY"

This compares the rpg-task-task-42 and rpg-task-task-43 overlays and returns every symbol that both modify, each with a severity.

Example: Enrich the Canonical Graph

Terminal window
curl -X POST "$MEMORYLAYER_URL/v1/rpg/enrich" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"context_id": "rpg",
"phases": ["descriptions", "data_flows"],
"async": true
}'

This schedules a background task in which the configured LLM adds one-line descriptions and detected data-flow edges to the canonical graph. The response includes the task_id.

How It Fits With the Rest of MemoryLayer

  • RPG nodes are ordinary memories. They show up in /v1/memories/recall unless you filter them out, which is sometimes useful: an agent asking “where is auth handled?” gets back both code-graph nodes and earlier decision memories.
  • The include_rpg flag on /v1/graph analysis and /v1/knowledgebase/generate pulls RPG nodes into workspace-wide graph analysis and the knowledge base.
  • Overlays are normal context partitions, so the existing context-scoped queries work on them without special handling.
  • RPG’s memory subtypes (rpg_file, rpg_class, …) and code_structure relationships are contributed through the standard OntologyContributorPlugin extension point. They are not built into the core server.

Why It Belongs in the Same Server

Putting the code graph in the same store as conversation memory enables queries that neither can answer alone:

  • “Last time we touched this file, we hit a deadlock. Recall the fix.” This joins RPG file nodes with episodic problem and solution memories.
  • “Surface the architectural decisions that affect src/auth/.” This joins the RPG path neighbourhood with decision-subtype memories.
  • “Find every file touched by a task that contradicted the documented intent.” This joins RPG task overlays with contradicts associations from the conversation graph.

Where the Pieces Live

RPG is spread across the editions:

  • memorylayer-server-rpg plugin (Apache-2.0): the /v1/rpg routes, sync, search and traversal, overlays, conflict detection, enrichment and maintenance tasks, and the code_structure ontology. Installing memorylayer-server alone does not register them. Install the plugin, or use the official server image, which bundles it.
  • MemoryLayer core (Apache-2.0): the shared machinery RPG builds on: memory and association storage, metadata-filtered subtype queries, the ontology contributor extension point, and the include_rpg option on graph analysis and the knowledge base.
  • MemoryLayer Enterprise (AGPL-3.0): PostgreSQL indexes tuned for RPG workloads (partial indexes over active RPG memories and code-structure edges) and RPG-aware graph analysis on Apache AGE. Enterprise installs core and the plugin together.

Background

RPG was first built to support Scitrera Forge, an agent-orchestration initiative that has since been discontinued. RPG does not depend on Forge, and Forge is not required for any of the functionality on this page.