What Are Agent Adapters in MemoryProxy and Where Are They Located?
TLDR: Agent Adapters in MemoryProxy are TypeScript modules located in MemoryProxy/src/agent-adapters/ that normalize per-client request payloads from IDE tools like Claude Code, CodeBuddy, and Codex into a uniform format, implementing client identification, request classification, and user-text extraction via the AgentAdapter interface defined in MemoryProxy/src/agent-adapters/types.ts.
In the TencentCloud/TencentDB-Agent-Memory repository, the MemoryProxy acts as a unified gateway that forwards requests from IDE clients to underlying LLM services such as OpenAI and Anthropic. Because each client injects request payloads in a different format, the proxy relies on Agent Adapters to translate those variations into a consistent internal representation. This design keeps the core proxy logic clean and makes supporting a new IDE as simple as registering a new adapter file.
What Does an Agent Adapter Do?
As implemented in the AgentAdapter interface (declared in MemoryProxy/src/agent-adapters/types.ts at lines 23–56), each adapter is responsible for three critical operations:
- Identify the client type — returns an
agentKindstring (e.g.,claude-code,codebuddy,codex) so downstream stages know which protocol conventions to apply. - Classify the request — determines whether an incoming request is a main conversation turn, a fork (like a suggestion or child thread), a side-query, or an auxiliary request. This classification drives later pipeline behavior, including injection, L0 memory handling, and skill-buffer processing.
- Extract the true user-typed text — isolates the actual text the user typed from the client's
contentpayload, filtering out embedded system prompts, tool results, and image blocks that various clients inject.
The interface itself is minimal and deliberate:
// MemoryProxy/src/agent-adapters/types.ts
export interface AgentAdapter {
agentKind: string;
classifyRequest(body: unknown, path?: string, headers?: Record<string, string>): RequestKind;
extractUserText(content: unknown): string;
}
Where Are the Agent Adapters Located?
All agent adapters live inside MemoryProxy/src/agent-adapters/ in the repository. The table below maps each supported client to its adapter file and highlights its distinguishing behavior:
| Client (agentKind) | File | Highlights |
|---|---|---|
| Claude Code (Anthropic protocol) | MemoryProxy/src/agent-adapters/claude-code.ts |
Uses classifyCcRequest and extracts the last text block from the Anthropic payload (lines 13–24) |
| CodeBuddy (OpenAI protocol) | MemoryProxy/src/agent-adapters/codebuddy.ts |
Currently delegates to the default adapter for conservative behavior (lines 32–38) |
| Codex | MemoryProxy/src/agent-adapters/codex.ts |
Provides its own classification and extraction logic, closely mirroring the default adapter (lines 13–24) |
| WorkBuddy | MemoryProxy/src/agent-adapters/workbuddy.ts |
Implements extractUserText for its specific payload format (lines 57–66) |
| DSH | MemoryProxy/src/agent-adapters/dsh.ts |
Custom handling for DSH-specific request structures (lines 44–56) |
| Unknown / fallback | MemoryProxy/src/agent-adapters/default.ts |
Conservatively treats every request as main and concatenates all text blocks (lines 4–10) |
The Adapter Factory: index.ts
The factory that maps a URL prefix (e.g., claude-code, codebuddy) to the correct adapter lives in MemoryProxy/src/agent-adapters/index.ts at lines 24–38. Any part of the proxy that needs an adapter calls resolveAgentAdapter(agentSource). The main request handler does this, as shown in MemoryProxy/src/handler.ts at lines 698–699:
const { resolveAgentAdapter } = await import("./agent-adapters/index.js");
const adapter = resolveAgentAdapter(agentSource);
How to Use an Agent Adapter in Practice
To integrate an adapter into request processing, you resolve it first, then use its two core methods.
Extracting user text in a request handler:
import { resolveAgentAdapter } from "./agent-adapters/index.js";
export async function handleRequest(body: any, agentSource: string) {
const adapter = resolveAgentAdapter(agentSource);
const userText = adapter.extractUserText(body.input);
// `userText` now contains only what the user actually typed,
// regardless of the client's internal framing.
// …continue processing (mem command parsing, skill buffer, etc.)
}
Classifying a request before injection:
import { resolveAgentAdapter } from "./agent-adapters/index.js";
export function routeRequest(body: any, path?: string, headers?: Record<string, string>) {
const adapter = resolveAgentAdapter(body.agentSource);
const kind = adapter.classifyRequest(body, path, headers);
// `kind` will be "main", "fork", "sidequery", or "auxiliary",
// which determines how the subsequent pipeline stages behave.
return kind;
}
Key Files at a Glance
| File | Purpose |
|---|---|
MemoryProxy/src/agent-adapters/types.ts |
Defines AgentAdapter, AgentKind, and RequestKind interfaces (lines 23–56) |
MemoryProxy/src/agent-adapters/index.ts |
Factory that resolves a client prefix to its adapter (lines 24–38) |
MemoryProxy/src/agent-adapters/claude-code.ts |
Adapter for Claude Code (Anthropic) clients (lines 13–24) |
MemoryProxy/src/agent-adapters/default.ts |
Fallback adapter for unknown clients (lines 4–10) |
MemoryProxy/src/handler.ts (excerpt) |
Shows how the adapter is resolved and used in request handling (lines 698–699) |
Summary
- Agent Adapters are the memory proxy's abstraction for normalizing heterogeneous IDE client payloads.
- They live in the
MemoryProxy/src/agent-adapters/directory, with one TypeScript file per client plus adefault.tsfallback. - Each adapter implements three responsibilities: identify the client, classify the request (
main,fork,sidequery,auxiliary), and extract user-typed text. - The
resolveAgentAdapter()factory function inindex.tsis the single entry point for obtaining the correct adapter. - Adding a new IDE client requires only a new adapter file plus registration in
index.ts— no changes to the core proxy logic.
Frequently Asked Questions
How do I register a new client with MemoryProxy?
Create a new TypeScript file in MemoryProxy/src/agent-adapters/ that implements the AgentAdapter interface from types.ts, then register its agentKind string in the resolver map inside MemoryProxy/src/agent-adapters/index.ts. The proxy will then route requests from that client to your adapter automatically.
What request kinds does classifyRequest return?
According to the RequestKind type in MemoryProxy/src/agent-adapters/types.ts, the classifier returns one of four values: main for regular conversation turns, fork for child or suggestion threads, sidequery for supporting queries, and auxiliary for background or meta requests. These values directly influence the injection, memory, and skill-buffer stages of the pipeline.
Why does the CodeBuddy adapter delegate to the default adapter?
The codebuddy.ts adapter currently uses resolveDefaultAdapter() and assumes the conservative main classification for every request (lines 32–38). This is a safe default while work-in-progress adapters are refined; the file is structured so a custom implementation can be dropped in without changing the factory.
Where is the adapter factory called from?
The main request handler in MemoryProxy/src/handler.ts (lines 698–699) dynamically imports resolveAgentAdapter and resolves the adapter using agentSource, which is typically derived from the URL path prefix (e.g., /v1/claude-code maps to the Claude Code adapter).
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →