# How TencentDB Agent Memory Improves WideSearch and SWE-bench Performance

> TencentDB Agent Memory enhances WideSearch and SWE-bench performance by up to 59%. Discover how layered memory assets and atomic proxy storage optimize token generation and eliminate race conditions.

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

---

**TencentDB Agent Memory boosts WideSearch and SWE-bench performance by up to 59% through layered memory assets, atomic proxy storage, and pre-indexed CodeGraph retrieval that eliminates redundant token generation and race conditions.**

TencentDB Agent Memory (TDAM) is an open-source memory system designed to accelerate large-scale LLM benchmarks. By reorganizing how agents store and retrieve context across Chat Memory, Skills, Wiki, and CodeGraph layers, the system specifically targets the latency and accuracy bottlenecks present in retrieval-heavy workloads like WideSearch and SWE-bench.

## Layered Memory Architecture Eliminates Token Bloat

The foundation of TDAM's performance gains lies in its **Layered Memory Assets** implementation. Rather than injecting entire codebases into the context window, the system organizes knowledge into four distinct layers (L0-L3) and fetches only the relevant stratum on demand【/cache/repos/github.com/TencentCloud/TencentDB-Agent-Memory/feat/server_team/README.md#L44-L55】.

### L0-L3 Memory Hierarchy

- **L3 (CodeGraph)**: Pre-indexed symbol relationships and call graphs
- **L2 (Wiki)**: Structured documentation and architectural decisions  
- **L1 (Skills)**: Reusable workflow templates and tool definitions
- **L0 (Chat Memory)**: Session-specific conversation history

This hierarchy allows WideSearch queries to initiate from the concise L3/L2 context, falling back to fine-grained L1/L0 layers only when specific facts are required.

### Selective Retrieval for WideSearch Queries

When processing WideSearch benchmarks that span thousands of code symbols, agents utilizing TDAM reduce prompt sizes dramatically by retrieving only the relevant **CodeGraph** subset rather than scanning entire repositories. The proxy storage layer guarantees atomic access to these assets through **per-key mutex** locks, preventing the race conditions common in high-throughput benchmark loops【/cache/repos/github.com/TencentCloud/TencentDB-Agent-Memory/feat/server_team/MemoryProxy/src/storage/per-key-mutex.ts】.

## Atomic Storage Prevents Race Conditions in SWE-bench

SWE-bench tasks involve iterative code edits where each step must observe the latest state changes. TDAM's **Per-Key Mutex & Proxy Storage** architecture ensures that newly generated skills or modified code symbols are immediately visible to subsequent requests without requiring full re-indexing of the repository.

The [`per-key-mutex.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/per-key-mutex.ts) implementation provides lightweight concurrency control that serializes updates to individual memory keys while allowing parallel reads across different assets. This mechanism proves critical during SWE-bench execution, where multiple tool calls may attempt to update the same skill or wiki entry simultaneously.

## CodeGraph Indexing Accelerates Symbol Resolution

**CodeGraph Indexing** transforms raw source files into a searchable graph of symbols, callers, and callees【/cache/repos/github.com/TencentCloud/TencentDB-Agent-Memory/feat/server_team/README.md#L22-L27】. Agents can resolve queries such as "who calls `foo`?" or "what files import `Bar`?" through O(1) lookups rather than linear scans.

For WideSearch benchmarks that require cross-referencing symbols across massive codebases, this graph structure eliminates the O(n) traversal penalty. The retrieval latency becomes constant regardless of repository size, directly improving benchmark completion times.

## Reusable Skills Cut Redundant Computation

The **Skill Library with Versioning** captures distilled workflows—such as "run unit tests" or "apply refactoring"—as reusable assets【/cache/repos/github.com/TencentCloud/TencentDB-Agent-Memory/feat/server_team/README.md#L6-L11】. Instead of recomputing multi-step reasoning on every benchmark iteration, agents invoke stored skills through single API calls.

In SWE-bench scenarios where verification steps repeat across multiple test cases, skill reuse shaves seconds off each iteration by bypassing redundant LLM generation for identical procedural logic.

## Measurable Performance Gains

The PersonaMem benchmark serves as a proxy for real-world LLM workloads, demonstrating TDAM's concrete improvements. Accuracy increased from **48%** to **76%**, representing a **+59%** relative improvement【/cache/repos/github.com/TencentCloud/TencentDB-Agent-Memory/feat/server_team/README.md#L71-L75】.

These architectural optimizations translate directly to WideSearch and SWE-bench performance:

- **WideSearch**: CodeGraph indexing reduces retrieval latency by limiting context to relevant symbol neighborhoods
- **SWE-bench**: Atomic storage and skill versioning prevent redundant work and ensure consistent state across iterative edits

## Implementation Examples

The following TypeScript snippets demonstrate how benchmark scripts interface with TDAM's memory-enhanced APIs.

### Listing Available Memory Tools

```typescript
import { createClient } from '@tencentdb-agent-memory/memory-core';

// Initialize the proxy client pointing to the running MemoryProxy service
const client = createClient({ baseURL: 'http://localhost:8123/v3' });

async function listTools() {
  const resp = await client.post('/tools/list', {});
  console.log('Available tools:', resp.data);
}

listTools();

```

*Source:* [`MemoryProxy/src/tdai/client.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryProxy/src/tdai/client.ts) provides the HTTP wrapper for unified `/v3/tools/*` endpoints【/cache/repos/github.com/TencentCloud/TencentDB-Agent-Memory/feat/server_team/MemoryProxy/src/tdai/client.ts】.

### Querying CodeGraph for Symbol Callers

```typescript
async function findCallers(symbol: string) {
  const resp = await client.post('/tools/call', {
    tool: 'codegraph',
    method: 'searchCallers',
    params: { symbol },
  });
  return resp.data; // Returns array of file-symbol pairs
}

```

*Source:* Implementation located in [`sdk/memory-core/typescript/src/v3/memory-prompt-client.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/sdk/memory-core/typescript/src/v3/memory-prompt-client.ts)【/cache/repos/github.com/TencentCloud/TencentDB-Agent-Memory/feat/server_team/sdk/memory-core/typescript/src/v3/memory-prompt-client.ts】.

### Executing Versioned Skills

```typescript
async function runTests(skillId: string) {
  const resp = await client.post('/tools/call', {
    tool: 'skill',
    method: 'execute',
    params: { skillId },
  });
  console.log('Test results:', resp.data);
}

```

*Source:* Skill client implementation in [`sdk/memory-core/typescript/src/v3/skill-client.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/sdk/memory-core/typescript/src/v3/skill-client.ts)【/cache/repos/github.com/TencentCloud/TencentDB-Agent-Memory/feat/server_team/sdk/memory-core/typescript/src/v3/skill-client.ts】.

## Summary

- **Layered Memory Assets** reduce token consumption by fetching only L2/L3 context for initial queries, deferring L0/L1 retrieval until necessary
- **Per-Key Mutex** synchronization in [`MemoryProxy/src/storage/per-key-mutex.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryProxy/src/storage/per-key-mutex.ts) prevents race conditions during concurrent SWE-bench iterations
- **CodeGraph Indexing** enables O(1) symbol resolution for WideSearch queries across large repositories
- **Versioned Skill Library** eliminates redundant computation by caching reusable workflows
- **PersonaMem benchmarks** validate a 59% accuracy improvement, indicating proportional gains in WideSearch and SWE-bench scenarios

## Frequently Asked Questions

### How does TencentDB Agent Memory differ from standard RAG for SWE-bench?

Standard retrieval-augmented generation treats the codebase as a flat document corpus. TDAM introduces **structured CodeGraph layers** and **atomic write consistency**, ensuring that iterative SWE-bench edits propagate immediately across all subsequent tool calls without requiring full context reconstruction.

### What specific component handles concurrent updates during benchmark runs?

The [`per-key-mutex.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/per-key-mutex.ts) module in `MemoryProxy/src/storage/` provides granular locking mechanisms that serialize updates to individual memory keys while preserving parallel read access. This prevents state corruption when multiple SWE-bench threads attempt to modify shared skills or wiki entries simultaneously.

### Can the Skill Library be versioned independently of the agent code?

Yes. The Skill Library implements explicit versioning within the L1 memory layer, allowing benchmark workflows to pin specific skill versions or roll back to previous iterations without redeploying the agent executable. This versioning is managed through the `/v3/tools/call` endpoint with the `skill` tool parameter.

### How does layered memory reduce token costs compared to full context windows?

By organizing knowledge into L0-L3 tiers, TDAM leverages **selective retrieval** from [`memory-prompt-client.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/memory-prompt-client.ts) to inject only the relevant CodeGraph subgraph or Wiki summary into the prompt. This approach caps token usage at the relevant neighborhood size rather than the full repository size, directly reducing per-query latency and API costs in WideSearch benchmarks.