diff --git a/mem0-ts/src/oss/src/memory/index.ts b/mem0-ts/src/oss/src/memory/index.ts index f41d161ac..ee653da46 100644 --- a/mem0-ts/src/oss/src/memory/index.ts +++ b/mem0-ts/src/oss/src/memory/index.ts @@ -1189,7 +1189,13 @@ export class Memory { } } - const result = { ...memoryItem, ...filters }; + const result = { + ...memoryItem, + ...filters, + ...(memory.payload.attributedTo && { + attributedTo: memory.payload.attributedTo, + }), + }; await this._displayFirstRunNotice("get"); return result; } @@ -1453,6 +1459,7 @@ export class Memory { ...(payload.user_id && { user_id: payload.user_id }), ...(payload.agent_id && { agent_id: payload.agent_id }), ...(payload.run_id && { run_id: payload.run_id }), + ...(payload.attributedTo && { attributedTo: payload.attributedTo }), ...(scored.scoreDetails && { score_details: scored.scoreDetails }), }; }); @@ -1687,6 +1694,9 @@ export class Memory { ...(mem.payload.user_id && { user_id: mem.payload.user_id }), ...(mem.payload.agent_id && { agent_id: mem.payload.agent_id }), ...(mem.payload.run_id && { run_id: mem.payload.run_id }), + ...(mem.payload.attributedTo && { + attributedTo: mem.payload.attributedTo, + }), })); const result = { results }; diff --git a/mem0-ts/src/oss/src/types/index.ts b/mem0-ts/src/oss/src/types/index.ts index f52bbdb97..422f208e1 100644 --- a/mem0-ts/src/oss/src/types/index.ts +++ b/mem0-ts/src/oss/src/types/index.ts @@ -82,6 +82,7 @@ export interface MemoryItem { updatedAt?: string; score?: number; metadata?: Record; + attributedTo?: string; } export interface SearchFilters { diff --git a/mem0-ts/src/oss/tests/memory.crud.test.ts b/mem0-ts/src/oss/tests/memory.crud.test.ts index 7fb8d01d4..55db5d5f4 100644 --- a/mem0-ts/src/oss/tests/memory.crud.test.ts +++ b/mem0-ts/src/oss/tests/memory.crud.test.ts @@ -361,6 +361,45 @@ describe("Memory - search()", () => { }); }); +// ─── attributedTo (#5666) ──────────────────────────────── + +describe("Memory - attributedTo round-trip (#5666)", () => { + let memory: Memory; + const userId = `attributed_test_${Date.now()}`; + let id: string; + + beforeAll(async () => { + memory = createMemory(); + // The mocked LLM tags every extracted fact with attributed_to: "user". + const addResult: SearchResult = await memory.add("I love AI", { userId }); + id = addResult.results[0].id; + }); + + afterAll(async () => { + await memory.reset(); + }); + + test("get() surfaces attributedTo", async () => { + const item: MemoryItem | null = await memory.get(id); + expect(item!.attributedTo).toBe("user"); + }); + + test("getAll() surfaces attributedTo", async () => { + const result: SearchResult = await memory.getAll({ + filters: { user_id: userId }, + }); + expect(result.results[0].attributedTo).toBe("user"); + }); + + test("search() surfaces attributedTo", async () => { + const result: SearchResult = await memory.search("AI", { + filters: { user_id: userId }, + }); + expect(result.results.length).toBeGreaterThan(0); + expect(result.results[0].attributedTo).toBe("user"); + }); +}); + // ─── history() ─────────────────────────────────────────── describe("Memory - history()", () => {