TencentCloud/TencentDB-Agent-Memory · error
clearMemoryContent requires non-empty teamId and agentId
Error message
clearMemoryContent requires non-empty teamId and agentId
What it means
clearMemoryContent deletes L0/L1 memory content scoped by teamId and agentId, so both are mandatory; missing either would produce an over-broad or meaningless delete. The method trims both values and throws when either is empty.
Source
Thrown at MemoryCore/src/core/store/sqlite.ts:2743
}
} catch (err) {
this.logger?.warn(`[sqlite] deleteL0BySession failed: ${err instanceof Error ? err.message : String(err)}`);
return 0;
}
}
/**
* 清空某个 (team, agent) 下的全部 L0 + L1 内容(含向量 / FTS 附属行)。
* 不动entity_* / meta_* 资产表 —— 资产 ID 与绑定关系完整保留。
*
* sqlite store 不落L2/L3 profile 行(profiles 表只存在于 TCVDB),
* 所以 profilesDeleted 恒为 0,L2/L3 文件由调用方走 StorageAdapter 清理。
*/
clearMemoryContent(filter: MemoryContentClearFilter): MemoryContentClearResult {
const teamId = (filter?.teamId ?? "").trim();
const agentId = (filter?.agentId ?? "").trim();
if (!teamId || !agentId) {
throw new Error("clearMemoryContent requires non-empty teamId and agentId");
}
const userId = filter.userId?.trim() || undefined;
const empty: MemoryContentClearResult = { l0Deleted: 0, l1Deleted: 0, profilesDeleted: 0 };
if (this.degraded) return empty;
// 参数绑定,禁止拼接。userId 可选 → 动态追加一段条件 + 一个参数。
const where = `team_id = ? AND agent_id = ?${userId ? " AND user_id = ?" : ""}`;
const params: string[] = userId ? [teamId, agentId, userId] : [teamId, agentId];
try {
const l0Ids = (this.db.prepare(
`SELECT record_id FROM l0_conversations WHERE ${where}`,
).all(...params) as Array<{ record_id: string }>).map((r) => r.record_id);
const l1Ids = (this.db.prepare(
`SELECT record_id FROM l1_records WHERE ${where}`,
).all(...params) as Array<{ record_id: string }>).map((r) => r.record_id);
if (l0Ids.length === 0 && l1Ids.length === 0) return empty;View on GitHub (pinned to 3efcd317b8)
Solutions
- Populate both filter.teamId and filter.agentId with non-empty trimmed strings before calling
- Optionally include filter.userId to narrow the clear scope
- Handle the degenerate degraded-store case (returns zeros) separately from this validation error
Example fix
// before
store.clearMemoryContent({ teamId: team?.id });
// after
if (!team?.id || !agent.id) throw new Error('teamId and agentId required');
store.clearMemoryContent({ teamId: team.id, agentId: agent.id }); Defensive patterns
Strategy: validation
Validate before calling
function assertClearFilter(f) {
const teamId = (f?.teamId ?? '').trim();
const agentId = (f?.agentId ?? '').trim();
if (!teamId || !agentId) throw new Error('teamId and agentId required');
return { teamId, agentId };
}
store.clearMemoryContent(assertClearFilter(filter)); Type guard
function isMemContentFilter(f): f is MemoryContentClearFilter & { teamId: string; agentId: string } {
return typeof f?.teamId === 'string' && f.teamId.trim() !== '' && typeof f?.agentId === 'string' && f.agentId.trim() !== '';
} Try / catch
try {
store.clearMemoryContent(filter);
} catch (e) {
if (String(e.message).includes('non-empty teamId and agentId')) {
throw new ConfigError('Memory clear aborted: teamId/agentId missing in filter');
}
throw e;
} Prevention
- Validate the filter object at the API boundary before it reaches the store
- Keep teamId/agentId on a typed context object so they cannot be undefined
- Never call destructive clears from paths where scope fields may be partial
When it happens
Trigger: Calling VectorStore.clearMemoryContent(filter) where filter.teamId or filter.agentId is undefined, null, empty, or whitespace-only.
Common situations: Building the filter object dynamically where agentId comes from an unset field, a user-scoped clear path that forgot teamId, or passing null instead of a populated filter.
Related errors
- [sqlite] deleteL0BySession requires a non-empty sessionId
- memory 系统用户 key 必须匹配 sk-mem-[A-Za-z0-9_-]{32}
- llm.provider=proxy 且 useMemorySystemUserKey=false 时必须显式 llm.
- Generation log object key exceeds COS limit
- Invalid generation log key
AI-assisted analysis of TencentCloud/TencentDB-Agent-Memory@3efcd317b8 (2026-09-01).
Data as JSON: /api/errors/d9a2e7363fb5d2f2.
Report an issue: GitHub.