# What Is Code-Graph and How Does It Help With Code Modifications?

> Discover Code Graph, a searchable index of code symbols and relationships. Learn how it empowers AI agents to understand impact, trace dependencies, and perform safer code modifications.

- Repository: [Tencent Cloud/TencentDB-Agent-Memory](https://github.com/TencentCloud/TencentDB-Agent-Memory)
- Tags: deep-dive
- Published: 2026-08-21

---

**Code-Graph is a structured, searchable index of codebase symbols and relationships that enables AI agents to understand impact, trace dependencies, and execute safer modifications.**

Code-Graph serves as the knowledge backbone of the **TencentDB Agent Memory** system, transforming raw Git repositories into queryable graph assets. By indexing symbols, call hierarchies, and file relationships, it provides AI agents with semantic context that goes far beyond simple text search. This component allows development teams to perform impact analysis and targeted refactoring with precision.

## Architecture of the Code-Graph System

### Indexer and Asset Storage

The **Indexer** runs as part of the Knowledge Service and processes Git-cloned repositories into graph structures containing symbols, callers, callees, and file-tree relationships. According to the ID schema definition in [`MemoryKnowledge/src/store/ids.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryKnowledge/src/store/ids.ts), these assets receive globally unique identifiers prefixed with `cg-`, distinguishing them from Skills, Wikis, and other knowledge types.

### Unified Asset Model

Code-Graph assets share the generic asset model used by Skills and Wikis throughout the system. The gateway schema in [`MemoryCore/src/gateway/generated/types.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryCore/src/gateway/generated/types.ts) defines the `code_graph_id` field as a globally unique identifier, ensuring consistent asset management across the platform.

### REST API and Client SDKs

The service exposes **13 stateless REST endpoints** under `/api/v1/knowledge/code-graph/*`, implemented in [`MemoryKnowledge/src/routes/code-graph.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryKnowledge/src/routes/code-graph.ts). These support create, list, get, sync, delete, and search operations. Client SDKs for Node.js and Python wrap these HTTP calls; the Python implementation in [`sdk/memory-core/python/tencentdb_agent_memory/v3/client.py`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/sdk/memory-core/python/tencentdb_agent_memory/v3/client.py) provides methods like `list_code_graphs()` and `search_code()`.

### Panel UI Integration

The web interface displays Code-Graph assets and enables visual exploration of call graphs. The [`CodeSourcesPanel.tsx`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/CodeSourcesPanel.tsx) component located at [`MemoryPanel/web/src/pages/code/CodePage/components/CodeSourcesPanel.tsx`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryPanel/web/src/pages/code/CodePage/components/CodeSourcesPanel.tsx) includes functionality to allocate specific graphs to agents, binding the knowledge asset to particular modification tasks.

## How Code-Graph Assists Code Modifications

### Impact Awareness and Ripple Effect Analysis

Before editing a function, agents query the graph to retrieve **callers and callees**, revealing the full scope of potential changes. This prevents accidental breakage of downstream dependencies by showing exactly which other functions rely on the target symbol.

### Semantic Search Capabilities

Instead of relying on grep or raw text matching, agents issue semantic queries such as "find all usages of `UserService.create`" and receive structured results containing precise file paths and line numbers. This targeted search eliminates false positives and speeds up refactoring workflows.

### Versioned and Shared Knowledge

As a **first-class asset**, a Code-Graph can be versioned, reviewed, and shared across multiple agents. This ensures every team member operates from the same understanding of the codebase structure, maintaining consistency during collaborative modification tasks.

### Automated Synchronization

The Knowledge Service maintains fresh indices through automated syncing. As configured in `MemoryKnowledge/.env.example`, optional sync daemons can schedule regular updates, guaranteeing that impact analysis always reflects the current repository state.

## Working with Code-Graph Assets

### Listing Assets with the Python SDK

```python
from tencentdb_agent_memory.v3 import client

# Initialise the client (endpoint and credentials are read from .env)

mem_client = client.MemoryClient()

# Retrieve a list of Code‑Graph assets

code_graphs = mem_client.list_code_graphs()
for cg in code_graphs:
    print(f"ID: {cg['code_graph_id']}, Repo: {cg['repo_url']}")

```

### Searching for Symbol Callers via cURL

```bash
curl -X POST "http://localhost:8421/api/v1/knowledge/code-graph/search" \
     -H "Content-Type: application/json" \
     -d '{"query":"callers","symbol":"UserService.create"}'

```

### Syncing Graphs with the Node.js SDK

```javascript
const { MemoryClient } = require('@tencentdb-agent-memory/memory-core');

(async () => {
  const client = new MemoryClient({ baseURL: 'http://localhost:8421' });
  const cgId = 'cg-7e3d10ab'; // obtained from list_code_graphs()
  await client.syncCodeGraph({ codeGraphId: cgId });
  console.log('Code‑Graph synced');
})();

```

## Summary

- Code-Graph indexes repositories into searchable graph assets with `cg-` prefixed IDs defined in [`MemoryKnowledge/src/store/ids.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryKnowledge/src/store/ids.ts)
- Provides 13 REST endpoints under `/api/v1/knowledge/code-graph/*` for graph management and symbol search
- Enables impact analysis by mapping caller/callee relationships before modifications
- Supports semantic queries through Python, Node.js, and raw HTTP interfaces
- Maintains currency through automated sync capabilities configured in `MemoryKnowledge/.env.example`

## Frequently Asked Questions

### What identifier prefix denotes a Code-Graph asset?

Code-Graph assets use identifiers prefixed with `cg-`, as defined in [`MemoryKnowledge/src/store/ids.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryKnowledge/src/store/ids.ts). This distinguishes them from Skills, Wikis, and other knowledge assets in the system.

### How many REST endpoints does the Code-Graph API expose?

The API publishes 13 stateless REST endpoints under the `/api/v1/knowledge/code-graph/*` route, handling operations including create, list, get, sync, delete, and search.

### Can Code-Graph assets be shared between different agents?

Yes. Code-Graph assets are first-class knowledge objects that can be allocated to specific agents through the Panel UI or shared programmatically, ensuring consistent codebase understanding across multiple AI agents.

### How does the system keep Code-Graph indices up to date?

The Knowledge Service supports scheduled synchronization through configurable sync daemons, as specified in `MemoryKnowledge/.env.example`, allowing automated refreshing of graph data to match the latest repository state.