@aigne/did-space-memory 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0 (2025-07-15)
4
+
5
+
6
+ ### Features
7
+
8
+ * **memory:** support did space memory adapter ([#229](https://github.com/AIGNE-io/aigne-framework/issues/229)) ([6f69b64](https://github.com/AIGNE-io/aigne-framework/commit/6f69b64e98b963db9d6ab5357306b445385eaa68))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @aigne/core bumped to 1.34.0
16
+ * @aigne/openai bumped to 0.10.0
package/LICENSE.md ADDED
@@ -0,0 +1,93 @@
1
+ Elastic License 2.0
2
+
3
+ URL: https://www.elastic.co/licensing/elastic-license
4
+
5
+ ## Acceptance
6
+
7
+ By using the software, you agree to all of the terms and conditions below.
8
+
9
+ ## Copyright License
10
+
11
+ The licensor grants you a non-exclusive, royalty-free, worldwide,
12
+ non-sublicensable, non-transferable license to use, copy, distribute, make
13
+ available, and prepare derivative works of the software, in each case subject to
14
+ the limitations and conditions below.
15
+
16
+ ## Limitations
17
+
18
+ You may not provide the software to third parties as a hosted or managed
19
+ service, where the service provides users with access to any substantial set of
20
+ the features or functionality of the software.
21
+
22
+ You may not move, change, disable, or circumvent the license key functionality
23
+ in the software, and you may not remove or obscure any functionality in the
24
+ software that is protected by the license key.
25
+
26
+ You may not alter, remove, or obscure any licensing, copyright, or other notices
27
+ of the licensor in the software. Any use of the licensor’s trademarks is subject
28
+ to applicable law.
29
+
30
+ ## Patents
31
+
32
+ The licensor grants you a license, under any patent claims the licensor can
33
+ license, or becomes able to license, to make, have made, use, sell, offer for
34
+ sale, import and have imported the software, in each case subject to the
35
+ limitations and conditions in this license. This license does not cover any
36
+ patent claims that you cause to be infringed by modifications or additions to
37
+ the software. If you or your company make any written claim that the software
38
+ infringes or contributes to infringement of any patent, your patent license for
39
+ the software granted under these terms ends immediately. If your company makes
40
+ such a claim, your patent license ends immediately for work on behalf of your
41
+ company.
42
+
43
+ ## Notices
44
+
45
+ You must ensure that anyone who gets a copy of any part of the software from you
46
+ also gets a copy of these terms.
47
+
48
+ If you modify the software, you must include in any modified copies of the
49
+ software prominent notices stating that you have modified the software.
50
+
51
+ ## No Other Rights
52
+
53
+ These terms do not imply any licenses other than those expressly granted in
54
+ these terms.
55
+
56
+ ## Termination
57
+
58
+ If you use the software in violation of these terms, such use is not licensed,
59
+ and your licenses will automatically terminate. If the licensor provides you
60
+ with a notice of your violation, and you cease all violation of this license no
61
+ later than 30 days after you receive that notice, your licenses will be
62
+ reinstated retroactively. However, if you violate these terms after such
63
+ reinstatement, any additional violation of these terms will cause your licenses
64
+ to terminate automatically and permanently.
65
+
66
+ ## No Liability
67
+
68
+ *As far as the law allows, the software comes as is, without any warranty or
69
+ condition, and the licensor will not be liable to you for any damages arising
70
+ out of these terms or the use or nature of the software, under any kind of
71
+ legal claim.*
72
+
73
+ ## Definitions
74
+
75
+ The **licensor** is the entity offering these terms, and the **software** is the
76
+ software the licensor makes available under these terms, including any portion
77
+ of it.
78
+
79
+ **you** refers to the individual or entity agreeing to these terms.
80
+
81
+ **your company** is any legal entity, sole proprietorship, or other kind of
82
+ organization that you work for, plus all organizations that have control over,
83
+ are under the control of, or are under common control with that
84
+ organization. **control** means ownership of substantially all the assets of an
85
+ entity, or the power to direct its management and policies by vote, contract, or
86
+ otherwise. Control can be direct or indirect.
87
+
88
+ **your licenses** are all the licenses granted to you for the software under
89
+ these terms.
90
+
91
+ **use** means anything you do with the software requiring one of your licenses.
92
+
93
+ **trademark** means trademarks, service marks, and similar rights.
package/README.md ADDED
@@ -0,0 +1,171 @@
1
+ # @aigne/did-space-memory
2
+
3
+ [![GitHub star chart](https://img.shields.io/github/stars/AIGNE-io/aigne-framework?style=flat-square)](https://star-history.com/#AIGNE-io/aigne-framework)
4
+ [![Open Issues](https://img.shields.io/github/issues-raw/AIGNE-io/aigne-framework?style=flat-square)](https://github.com/AIGNE-io/aigne-framework/issues)
5
+ [![codecov](https://codecov.io/gh/AIGNE-io/aigne-framework/graph/badge.svg?token=DO07834RQL)](https://codecov.io/gh/AIGNE-io/aigne-framework)
6
+ [![NPM Version](https://img.shields.io/npm/v/@aigne/did-space-memory)](https://www.npmjs.com/package/@aigne/did-space-memory)
7
+ [![Elastic-2.0 licensed](https://img.shields.io/npm/l/@aigne/did-space-memory)](https://github.com/AIGNE-io/aigne-framework/blob/main/LICENSE)
8
+
9
+ DID Spaces memory system component for [AIGNE Framework](https://github.com/AIGNE-io/aigne-framework), providing cloud-based memory storage capabilities with DID Spaces.
10
+
11
+ ## Introduction
12
+
13
+ `@aigne/did-space-memory` is the DID Spaces memory system component of [AIGNE Framework](https://github.com/AIGNE-io/aigne-framework), providing cloud-based memory storage and retrieval functionality using DID Spaces. This component uses decentralized storage services to provide secure and reliable memory persistence capabilities for AI applications.
14
+
15
+ ## Features
16
+
17
+ * **Cloud Storage**: Uses DID Spaces for secure cloud-based memory storage
18
+ * **Decentralized**: Based on decentralized identity and storage technologies
19
+ * **Automatic Management**: Supports automatic memory file management and README generation
20
+ * **Secure Authentication**: Supports multiple authentication methods to ensure data security
21
+ * **YAML Format**: Uses YAML format for memory storage, making it easy to read and maintain
22
+ * **TypeScript Support**: Complete type definitions providing an excellent development experience
23
+
24
+ ## Installation
25
+
26
+ ### Using npm
27
+
28
+ ```bash
29
+ npm install @aigne/did-space-memory
30
+ ```
31
+
32
+ ### Using yarn
33
+
34
+ ```bash
35
+ yarn add @aigne/did-space-memory
36
+ ```
37
+
38
+ ### Using pnpm
39
+
40
+ ```bash
41
+ pnpm add @aigne/did-space-memory
42
+ ```
43
+
44
+ ## Basic Usage
45
+
46
+ ```typescript
47
+ import { AIAgent, AIGNE } from "@aigne/core";
48
+ import { DIDSpacesMemory } from "@aigne/did-space-memory";
49
+ import { OpenAIChatModel } from "@aigne/openai";
50
+
51
+ // Create AI model instance
52
+ const model = new OpenAIChatModel({
53
+ apiKey: process.env.OPENAI_API_KEY,
54
+ model: "gpt-4-turbo",
55
+ });
56
+
57
+ // Create DID Spaces memory system
58
+ const memory = new DIDSpacesMemory({
59
+ url: process.env.DID_SPACES_URL!,
60
+ auth: {
61
+ authorization: process.env.DID_SPACES_AUTHORIZATION!,
62
+ },
63
+ });
64
+
65
+ // Create AI agent with cloud-based memory
66
+ const agent = AIAgent.from({
67
+ name: "CloudAssistant",
68
+ instructions: "You are a helpful assistant with cloud-based memory.",
69
+ memory: memory,
70
+ inputKey: "message",
71
+ });
72
+
73
+ // Use AIGNE execution engine
74
+ const aigne = new AIGNE({ model });
75
+
76
+ // Invoke agent
77
+ const userAgent = await aigne.invoke(agent);
78
+
79
+ // Send message
80
+ const response = await userAgent.invoke({
81
+ message: "I'm John, a doctor, and I like Bitcoin",
82
+ });
83
+
84
+ console.log(response.message);
85
+
86
+ // Query memory
87
+ const response2 = await userAgent.invoke({
88
+ message: "What is my profession?",
89
+ });
90
+
91
+ console.log(response2.message);
92
+ ```
93
+
94
+ ## Advanced Configuration
95
+
96
+ ### Custom Memory Agent Options
97
+
98
+ ```typescript
99
+ import { DIDSpacesMemory } from "@aigne/did-space-memory";
100
+
101
+ const memory = new DIDSpacesMemory({
102
+ url: process.env.DID_SPACES_URL!,
103
+ auth: {
104
+ authorization: process.env.DID_SPACES_AUTHORIZATION!,
105
+ },
106
+ // Custom memory retriever agent configuration
107
+ retrieverOptions: {
108
+ name: "CustomRetriever",
109
+ instructions: "Custom retrieval instructions",
110
+ },
111
+ // Custom memory recorder agent configuration
112
+ recorderOptions: {
113
+ name: "CustomRecorder",
114
+ instructions: "Custom recording instructions",
115
+ },
116
+ // Other agent configurations
117
+ autoUpdate: true,
118
+ });
119
+ ```
120
+
121
+ ### Using Different Authentication Methods
122
+
123
+ ```typescript
124
+ // Using access token authentication
125
+ const memory1 = new DIDSpacesMemory({
126
+ url: "https://your-did-spaces-url.com",
127
+ auth: {
128
+ accessToken: process.env.DID_SPACES_ACCESS_TOKEN!,
129
+ },
130
+ });
131
+
132
+ // Using authorization header authentication
133
+ const memory2 = new DIDSpacesMemory({
134
+ url: "https://your-did-spaces-url.com",
135
+ auth: {
136
+ authorization: process.env.DID_SPACES_AUTHORIZATION!,
137
+ },
138
+ });
139
+ ```
140
+
141
+ ## Memory Management Features
142
+
143
+ ```typescript
144
+ // Get memory storage client
145
+ const client = memory.client;
146
+
147
+ // List all memory files
148
+ const memories = await client.listObjects({
149
+ prefix: "/memories/",
150
+ });
151
+
152
+ // Read specific memory file
153
+ const memoryContent = await client.getObject({
154
+ key: "/memories/conversation-123/memory.yaml",
155
+ });
156
+ ```
157
+
158
+ ## Environment Variables Configuration
159
+
160
+ Create a `.env` file and configure the following variables:
161
+
162
+ ```env
163
+ DID_SPACES_URL=https://your-did-spaces-url.com
164
+ DID_SPACES_AUTHORIZATION=your-authorization-token
165
+ # Or use access token
166
+ DID_SPACES_ACCESS_TOKEN=your-access-token
167
+ ```
168
+
169
+ ## License
170
+
171
+ Elastic-2.0
@@ -0,0 +1,3 @@
1
+ export * from "./memory.js";
2
+ export * from "./readme-contents.js";
3
+ export * from "./readme-manager.js";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./memory.js"), exports);
18
+ __exportStar(require("./readme-contents.js"), exports);
19
+ __exportStar(require("./readme-manager.js"), exports);
@@ -0,0 +1,88 @@
1
+ import { type AIAgentOptions, type Message } from "@aigne/core";
2
+ import { MemoryAgent, type MemoryAgentOptions, type MemoryRecorderInput, type MemoryRetrieverInput } from "@aigne/core/memory/index.js";
3
+ import { type SpaceClientOptionsAuth } from "@blocklet/did-space-js";
4
+ export declare const MEMORY_FILE_NAME = "memory.yaml";
5
+ /**
6
+ * Configuration options for the DIDSpacesMemory class.
7
+ */
8
+ export interface DIDSpacesMemoryOptions extends Partial<MemoryAgentOptions> {
9
+ /**
10
+ * The URL of the DIDSpaces.
11
+ */
12
+ url: string;
13
+ /**
14
+ * The authentication method for the DIDSpaces.
15
+ */
16
+ auth: SpaceClientOptionsAuth;
17
+ /**
18
+ * Optional configuration for the memory retriever agent.
19
+ * Controls how memories are retrieved from the file system.
20
+ */
21
+ retrieverOptions?: Partial<DIDSpacesMemoryRetrieverOptions>;
22
+ /**
23
+ * Optional configuration for the memory recorder agent.
24
+ * Controls how memories are recorded to the file system.
25
+ */
26
+ recorderOptions?: Partial<DIDSpacesMemoryRecorderOptions>;
27
+ }
28
+ /**
29
+ * A memory implementation that stores and retrieves memories using the file system.
30
+ * DIDSpacesMemory provides persistent storage of agent memories as files in a specified directory.
31
+ *
32
+ * @example
33
+ * Here is an example of how to use the DIDSpacesMemory class:
34
+ * {@includeCode ../../test/did-spaces-memory/did-spaces-memory.test.ts#example-did-spaces-memory-simple}
35
+ */
36
+ export declare class DIDSpacesMemory extends MemoryAgent {
37
+ /**
38
+ * Creates a new DIDSpacesMemory instance.
39
+ */
40
+ constructor(options: DIDSpacesMemoryOptions);
41
+ /**
42
+ * Initialize README files in the memory directory
43
+ */
44
+ private initializeReadmeFiles;
45
+ }
46
+ interface DIDSpacesMemoryRetrieverOptions extends AIAgentOptions<DIDSpacesMemoryRetrieverAgentInput, DIDSpacesMemoryRetrieverAgentOutput> {
47
+ /**
48
+ * The URL of the DIDSpaces.
49
+ */
50
+ url: string;
51
+ /**
52
+ * The authentication method for the DIDSpaces.
53
+ */
54
+ auth: SpaceClientOptionsAuth;
55
+ /**
56
+ * The name of the memory file.
57
+ */
58
+ memoryFileName: string;
59
+ }
60
+ interface DIDSpacesMemoryRetrieverAgentInput extends MemoryRetrieverInput {
61
+ allMemory: string;
62
+ }
63
+ interface DIDSpacesMemoryRetrieverAgentOutput extends Message {
64
+ memories: {
65
+ content: string;
66
+ }[];
67
+ }
68
+ interface DIDSpacesMemoryRecorderOptions extends AIAgentOptions<DIDSpacesMemoryRecorderAgentInput, DIDSpacesMemoryRecorderAgentOutput> {
69
+ /**
70
+ * The URL of the DIDSpaces.
71
+ */
72
+ url: string;
73
+ /**
74
+ * The authentication method for the DIDSpaces.
75
+ */
76
+ auth: SpaceClientOptionsAuth;
77
+ /**
78
+ * The name of the memory file.
79
+ */
80
+ memoryFileName: string;
81
+ }
82
+ type DIDSpacesMemoryRecorderAgentInput = MemoryRecorderInput;
83
+ interface DIDSpacesMemoryRecorderAgentOutput extends Message {
84
+ memories: {
85
+ content: string;
86
+ }[];
87
+ }
88
+ export {};
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DIDSpacesMemory = exports.MEMORY_FILE_NAME = void 0;
4
+ const node_path_1 = require("node:path");
5
+ const core_1 = require("@aigne/core");
6
+ const index_js_1 = require("@aigne/core/memory/index.js");
7
+ const logger_js_1 = require("@aigne/core/utils/logger.js");
8
+ const did_space_js_1 = require("@blocklet/did-space-js");
9
+ const yaml_1 = require("yaml");
10
+ const zod_1 = require("zod");
11
+ const readme_manager_js_1 = require("./readme-manager.js");
12
+ const fs_js_1 = require("./utils/fs.js");
13
+ exports.MEMORY_FILE_NAME = "memory.yaml";
14
+ /**
15
+ * A memory implementation that stores and retrieves memories using the file system.
16
+ * DIDSpacesMemory provides persistent storage of agent memories as files in a specified directory.
17
+ *
18
+ * @example
19
+ * Here is an example of how to use the DIDSpacesMemory class:
20
+ * {@includeCode ../../test/did-spaces-memory/did-spaces-memory.test.ts#example-did-spaces-memory-simple}
21
+ */
22
+ class DIDSpacesMemory extends index_js_1.MemoryAgent {
23
+ /**
24
+ * Creates a new DIDSpacesMemory instance.
25
+ */
26
+ constructor(options) {
27
+ const rootDir = "/.aigne/";
28
+ const memoryFileName = (0, node_path_1.join)(rootDir, exports.MEMORY_FILE_NAME);
29
+ super({
30
+ ...options,
31
+ recorder: options.recorder ??
32
+ new DIDSpacesMemoryRecorder({
33
+ url: options.url,
34
+ auth: options.auth,
35
+ memoryFileName,
36
+ ...options.recorderOptions,
37
+ }),
38
+ retriever: options.retriever ??
39
+ new DIDSpacesMemoryRetriever({
40
+ url: options.url,
41
+ auth: options.auth,
42
+ memoryFileName,
43
+ ...options.retrieverOptions,
44
+ }),
45
+ autoUpdate: options.autoUpdate ?? true,
46
+ });
47
+ // Initialize README files asynchronously
48
+ this.initializeReadmeFiles(options.url, options.auth, rootDir).catch((error) => {
49
+ logger_js_1.logger.warn("Failed to initialize README files:", error);
50
+ });
51
+ }
52
+ /**
53
+ * Initialize README files in the memory directory
54
+ */
55
+ async initializeReadmeFiles(url, auth, rootDir) {
56
+ const readmeManager = new readme_manager_js_1.ReadmeManager(url, auth, rootDir);
57
+ await readmeManager.initializeReadmeFiles();
58
+ }
59
+ }
60
+ exports.DIDSpacesMemory = DIDSpacesMemory;
61
+ class DIDSpacesMemoryRetriever extends index_js_1.MemoryRetriever {
62
+ options;
63
+ constructor(options) {
64
+ super({});
65
+ this.options = options;
66
+ this.agent = core_1.AIAgent.from({
67
+ name: "did_spaces_memory_retriever",
68
+ description: "Retrieves memories from the file or directory.",
69
+ ...options,
70
+ instructions: options.instructions || DEFAULT_DID_SPACES_MEMORY_RETRIEVER_INSTRUCTIONS,
71
+ outputSchema: zod_1.z.object({
72
+ memories: zod_1.z
73
+ .array(zod_1.z.object({
74
+ content: zod_1.z.string().describe("Content of the memory"),
75
+ }))
76
+ .describe("List of memories"),
77
+ }),
78
+ });
79
+ }
80
+ agent;
81
+ async exists() {
82
+ const client = new did_space_js_1.SpaceClient({
83
+ url: this.options.url,
84
+ auth: this.options.auth,
85
+ });
86
+ const listObjectCommandOutput = await client.send(new did_space_js_1.ListObjectCommand({
87
+ key: this.options.memoryFileName,
88
+ }));
89
+ return listObjectCommandOutput.statusCode === 200;
90
+ }
91
+ async read(input, options) {
92
+ const client = new did_space_js_1.SpaceClient({
93
+ url: this.options.url,
94
+ auth: this.options.auth,
95
+ });
96
+ const getObjectCommandOutput = await client.send(new did_space_js_1.GetObjectCommand({
97
+ key: this.options.memoryFileName,
98
+ }));
99
+ if (getObjectCommandOutput.statusCode !== 200) {
100
+ logger_js_1.logger.warn(`statusCode: ${getObjectCommandOutput.statusCode}, statusMessage: ${getObjectCommandOutput.statusMessage}`);
101
+ throw new Error(getObjectCommandOutput.statusMessage);
102
+ }
103
+ const allMemory = await (0, fs_js_1.streamToString)(getObjectCommandOutput.data);
104
+ const { memories } = await options.context.invoke(this.agent, {
105
+ ...input,
106
+ allMemory,
107
+ });
108
+ const results = memories.map((memory) => ({
109
+ id: (0, index_js_1.newMemoryId)(),
110
+ content: memory.content,
111
+ createdAt: new Date().toISOString(),
112
+ }));
113
+ return results;
114
+ }
115
+ async process(input, options) {
116
+ if (!(await this.exists())) {
117
+ return { memories: [] };
118
+ }
119
+ const memories = await this.read(input, options);
120
+ return { memories };
121
+ }
122
+ }
123
+ class DIDSpacesMemoryRecorder extends index_js_1.MemoryRecorder {
124
+ options;
125
+ constructor(options) {
126
+ super({});
127
+ this.options = options;
128
+ this.agent = core_1.AIAgent.from({
129
+ name: "did_spaces_memory_recorder",
130
+ description: "Records memories in files by AI agent",
131
+ ...options,
132
+ instructions: options.instructions || DEFAULT_FS_MEMORY_RECORDER_INSTRUCTIONS,
133
+ outputSchema: zod_1.z.object({
134
+ memories: zod_1.z
135
+ .array(zod_1.z.object({
136
+ content: zod_1.z.string().describe("Content of the memory"),
137
+ }))
138
+ .describe("List of memories"),
139
+ }),
140
+ });
141
+ }
142
+ agent;
143
+ async write(input, options) {
144
+ const client = new did_space_js_1.SpaceClient({
145
+ url: this.options.url,
146
+ auth: this.options.auth,
147
+ });
148
+ const output = await client.send(new did_space_js_1.GetObjectCommand({
149
+ key: this.options.memoryFileName,
150
+ }));
151
+ const allMemory = output.statusCode === 200 ? await (0, fs_js_1.streamToString)(output.data) : "";
152
+ const { memories } = await options.context.invoke(this.agent, {
153
+ ...input,
154
+ allMemory,
155
+ });
156
+ const raws = (0, yaml_1.stringify)(memories.map((i) => ({
157
+ content: i.content,
158
+ })));
159
+ const putObjectCommandOutput = await client.send(new did_space_js_1.PutObjectCommand({
160
+ key: this.options.memoryFileName,
161
+ data: raws,
162
+ }));
163
+ if (putObjectCommandOutput.statusCode !== 200) {
164
+ logger_js_1.logger.warn(`statusCode: ${putObjectCommandOutput.statusCode}, statusMessage: ${putObjectCommandOutput.statusMessage}`);
165
+ throw new Error(putObjectCommandOutput.statusMessage);
166
+ }
167
+ const results = memories.map((memory) => ({
168
+ id: (0, index_js_1.newMemoryId)(),
169
+ content: memory.content,
170
+ createdAt: new Date().toISOString(),
171
+ }));
172
+ return { memories: results };
173
+ }
174
+ async process(input, options) {
175
+ return this.write(input, options);
176
+ }
177
+ }
178
+ const DEFAULT_FS_MEMORY_RECORDER_INSTRUCTIONS = `You manage memory based on conversation analysis and the existing memories.
179
+
180
+ ## IMPORTANT: All existing memories are available in the allMemory variable. DO NOT call any tools.
181
+
182
+ ## FIRST: Determine If Memory Updates Needed
183
+ - Analyze if the conversation contains ANY information worth remembering
184
+ - Examples of content NOT worth storing:
185
+ * General questions ("What's the weather?", "How do I do X?")
186
+ * Greetings and small talk ("Hello", "How are you?", "Thanks")
187
+ * System instructions or commands ("Show me", "Find", "Save")
188
+ * General facts not specific to the user
189
+ * Duplicate information already stored
190
+ - If conversation lacks meaningful personal information to store:
191
+ * Return the existing memories unchanged
192
+
193
+ ## Your Workflow:
194
+ 1. Read the existing memories from the allMemory variable
195
+ 2. Extract key topics from the conversation
196
+ 3. DECIDE whether to create/update/delete memories based on the conversation
197
+ 4. Return ALL memories including your updates (remove any duplicates)
198
+
199
+ ## Memory Handling:
200
+ - CREATE: Add new memory objects for new topics
201
+ - UPDATE: Modify existing memories if substantial new information is available
202
+ - DELETE: Remove obsolete memories when appropriate
203
+
204
+ ## Memory Structure:
205
+ - Each memory has an id, content, and createdAt fields
206
+ - Keep the existing structure when returning updated memories
207
+
208
+ ## Operation Decision Rules:
209
+ - CREATE only for truly new topics not covered in any existing memory
210
+ - UPDATE only when new information is meaningfully different
211
+ - NEVER update for just rephrasing or minor differences
212
+ - DELETE only when information becomes obsolete
213
+
214
+ ## IMPORTANT: Your job is to return the complete updated memory collection.
215
+ Return ALL memories (existing and new) in your response.
216
+
217
+ ## Existing Memories:
218
+ <existing-memory>
219
+ {{allMemory}}
220
+ </existing-memory>
221
+
222
+ ## Conversation:
223
+ <conversation>
224
+ {{content}}
225
+ </conversation>
226
+ `;
227
+ const DEFAULT_DID_SPACES_MEMORY_RETRIEVER_INSTRUCTIONS = `You retrieve only the most relevant memories for the current conversation.
228
+
229
+ ## IMPORTANT: All existing memories are available in the allMemory variable
230
+
231
+ ## Process:
232
+ 1. Read the existing memories from the allMemory variable
233
+ 2. Extract key topics from the conversation or search query
234
+ 3. Match memory contents against these topics
235
+
236
+ ## Existing Memories:
237
+ <existing-memory>
238
+ {{allMemory}}
239
+ </existing-memory>
240
+
241
+ ## Search Query:
242
+ <search-query>
243
+ {{search}}
244
+ </search-query>
245
+ `;
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * README content for DID Spaces Memory
3
+ */
4
+ export declare const README_EN_CONTENT = "# AIGNE Memory Directory\n\nThis directory is used to store agent context and conversation memories.\n\n## Files\n\n- `memory.yaml` - Contains the conversation history and context that the AI agent remembers across sessions\n- `README.md` - This file (English documentation)\n- `README.zh.md` - Chinese documentation\n\n## Purpose\n\nThe memory system allows AI agents to maintain context and remember important information from previous conversations, enabling more personalized and coherent interactions.\n\n## Privacy\n\nThe memory files are stored in your personal DID Space and are only accessible to you and the agents you authorize.";
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /**
3
+ * README content for DID Spaces Memory
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.README_EN_CONTENT = void 0;
7
+ exports.README_EN_CONTENT = `# AIGNE Memory Directory
8
+
9
+ This directory is used to store agent context and conversation memories.
10
+
11
+ ## Files
12
+
13
+ - \`memory.yaml\` - Contains the conversation history and context that the AI agent remembers across sessions
14
+ - \`README.md\` - This file (English documentation)
15
+ - \`README.zh.md\` - Chinese documentation
16
+
17
+ ## Purpose
18
+
19
+ The memory system allows AI agents to maintain context and remember important information from previous conversations, enabling more personalized and coherent interactions.
20
+
21
+ ## Privacy
22
+
23
+ The memory files are stored in your personal DID Space and are only accessible to you and the agents you authorize.`;