{"record":{"id":"fdac40163e4553d3","repo":"mem0ai/mem0","slug":"one-of-the-filters-userid-agentid-or-runid-is-re","errorCode":null,"errorMessage":"One of the filters: userId, agentId or runId is required!","messagePattern":"One of the filters: userId, agentId or runId is required!","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/memory/index.ts","lineNumber":793,"sourceCode":"    const userId = validateAndTrimEntityId(config.userId, \"userId\");\n    const agentId = validateAndTrimEntityId(config.agentId, \"agentId\");\n    const runId = validateAndTrimEntityId(config.runId, \"runId\");\n\n    // Convert camelCase entity params to snake_case for storage (matches API and search/getAll filters)\n    if (userId) filters.user_id = metadata.user_id = userId;\n    if (agentId) filters.agent_id = metadata.agent_id = agentId;\n    if (runId) filters.run_id = metadata.run_id = runId;\n    if (filters.user_id) metadata.user_id = filters.user_id;\n    if (filters.agent_id) metadata.agent_id = filters.agent_id;\n    if (filters.run_id) metadata.run_id = filters.run_id;\n\n    // Normalize expiration date into the stored metadata (round-trips via get()).\n    if (config.expirationDate != null) {\n      metadata.expiration_date = normalizeExpirationDate(config.expirationDate);\n    }\n\n    if (!filters.user_id && !filters.agent_id && !filters.run_id) {\n      throw new Error(\n        \"One of the filters: userId, agentId or runId is required!\",\n      );\n    }\n\n    const parsedMessages = Array.isArray(messages)\n      ? (messages as Message[])\n      : [{ role: \"user\", content: messages }];\n\n    const final_parsedMessages = await parse_vision_messages(parsedMessages);\n\n    // Add to vector store\n    const vectorStoreResult = await this.addToVectorStore(\n      final_parsedMessages,\n      metadata,\n      filters,\n      infer,\n    );\n","sourceCodeStart":775,"sourceCodeEnd":811,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/memory/index.ts#L775-L811","documentation":"Thrown by Memory.add() when none of the config fields userId, agentId, or runId is set. Mem0 scopes every memory to at least one entity (user, agent, or run) so it can filter later; an unscoped write would be unreachable by search/getAll, which both require the same filters. The check runs after camelCase params are converted to snake_case filters.","triggerScenarios":"Calling memory.add('text', {}) or memory.add('text', { userId: '', agentId: undefined }) so that filters.user_id, filters.agent_id, and filters.run_id are all falsy after assignment.","commonSituations":"Forgetting the second argument entirely; passing an options object with the wrong key names (e.g. user_id instead of userId in config, which is only accepted inside filters); entity IDs read from an unset env var or empty session.","solutions":["Pass at least one identifier: memory.add(text, { userId: 'u1' })","If keys come from config, verify they are camelCase (userId, agentId, runId) — snake_case belongs in filters, not the top-level options","Default the scope in one place, e.g. const scope = { userId: session.userId ?? 'anonymous' }"],"exampleFix":"// before\nawait memory.add('User lives in Berlin');\n\n// after\nawait memory.add('User lives in Berlin', { userId: 'alice' });","handlingStrategy":"validation","validationCode":"const scope = { userId, agentId, runId };\nif (!scope.userId && !scope.agentId && !scope.runId) {\n  throw new Error('memory scope (userId/agentId/runId) is required');\n}","typeGuard":"const hasScope = (c: { userId?: string; agentId?: string; runId?: string }) =>\n  Boolean(c.userId || c.agentId || c.runId);","tryCatchPattern":null,"preventionTips":["Derive the scope options from one session object so an add() without scope is impossible","Remember top-level config uses camelCase; snake_case keys belong inside filters"],"tags":["validation","oss","memory-add","filters"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}