{"record":{"id":"0bd2abb0011e7729","repo":"TencentCloud/TencentDB-Agent-Memory","slug":"teamid-is-required-for-an-agent-prompt-setting","errorCode":null,"errorMessage":"teamId is required for an agent prompt setting","messagePattern":"teamId is required for an agent prompt setting","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"MemoryCore/src/core/memory-prompt/types.ts","lineNumber":128,"sourceCode":"  clearMemoryPromptSettings?(\n    ids: string[],\n    logs: MemoryPromptSettingLogRecord[],\n  ): Promise<void> | void;\n  queryMemoryPromptSettingLogs?(\n    filter: MemoryPromptSettingLogFilter,\n  ): Promise<MemoryPromptSettingLogRecord[]> | MemoryPromptSettingLogRecord[];\n}\n\nfunction targetHash(value: string): string {\n  return createHash(\"sha256\").update(value).digest(\"hex\").slice(0, 32);\n}\n\nexport function buildMemoryPromptSettingId(\n  target: { teamId?: string; agentId?: string },\n  layer: MemoryPromptLayer,\n): string {\n  if (target.agentId) {\n    if (!target.teamId) throw new Error(\"teamId is required for an agent prompt setting\");\n    return `mps:a:${targetHash(`${target.teamId}\\0${target.agentId}`)}:${layer}`;\n  }\n  if (target.teamId) return `mps:t:${targetHash(target.teamId)}:${layer}`;\n  return `mps:i:${layer}`;\n}\n\nexport function getMemoryPromptTargetType(target: {\n  teamId?: string;\n  agentId?: string;\n}): MemoryPromptTargetType {\n  if (target.agentId) return \"agent\";\n  if (target.teamId) return \"team\";\n  return \"instance\";\n}\n","sourceCodeStart":110,"sourceCodeEnd":143,"githubUrl":"https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/3efcd317b84146d6a08518ac0f7ee7c8a8d200ec/MemoryCore/src/core/memory-prompt/types.ts#L110-L143","documentation":"buildMemoryPromptSettingId composes a prompt setting id from a target and layer. An agent-scoped target (mps:a:...) requires both teamId and agentId because the id hashes `teamId\\0agentId`. When target.agentId is set without target.teamId, the function cannot compute a stable agent-scoped id and throws.","triggerScenarios":"Calling buildMemoryPromptSettingId with { agentId: \"...\" } and no teamId (undefined or empty) for any layer; same requirement propagates to its callers settingIds, setting, candidates, ids.","commonSituations":"Building an agent prompt setting from a context that only carries agentId (e.g. resolving agent-scope config outside a team, or a migration that moved agent settings under teams); teamId omitted in the lookup object while the caller assumed instance-level (mps:i:) fallback.","solutions":["Include teamId in the target object whenever agentId is provided","If the setting is not team/agent-scoped, remove agentId so it falls through to the team (mps:t:) or instance (mps:i:) branch","At call sites, verify the teamId was not lost when constructing the target from partial context"],"exampleFix":"// before\nconst id = buildMemoryPromptSettingId({ agentId: \"agt_1\" }, \"l2\");\n// after\nconst id = buildMemoryPromptSettingId({ teamId: \"team_9\", agentId: \"agt_1\" }, \"l2\");","handlingStrategy":"validation","validationCode":"function canBuildAgentSettingId(target) {\n  return !(target.agentId && !target.teamId);\n}","typeGuard":"function isAgentTarget(t) {\n  return typeof t.agentId === \"string\" && t.agentId.length > 0 && typeof t.teamId === \"string\" && t.teamId.length > 0;\n}","tryCatchPattern":"try {\n  const id = buildMemoryPromptSettingId(target, layer);\n} catch (e) {\n  if (e.message.includes(\"teamId is required\")) {\n    logger.error(\"agent-scoped prompt setting requires teamId+agentId\");\n  }\n  throw e;\n}","preventionTips":["Carry teamId alongside agentId in any context object used for prompt setting lookups","If no team exists, drop agentId to use the team- or instance-scoped branch instead","Type agent targets as { teamId: string; agentId: string } so the compiler enforces both fields"],"tags":["validation","configuration","prompt","scoping"],"backgroundTag":"missing-required-argument","analyzedSha":"3efcd317b84146d6a08518ac0f7ee7c8a8d200ec","analyzedAt":"2026-09-01T05:44:22.276Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}