@ai.ntellect/core 0.3.0 → 0.3.1

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/agent/index.ts CHANGED
@@ -20,6 +20,7 @@ export class Agent {
20
20
  private readonly maxEvaluatorIteration: number;
21
21
  private evaluatorIteration = 0;
22
22
  private accumulatedResults: string = "";
23
+ private currentInterpreter: Interpreter | undefined;
23
24
 
24
25
  constructor({
25
26
  orchestrator,
@@ -57,10 +58,20 @@ export class Agent {
57
58
  scope: MemoryScope.GLOBAL,
58
59
  });
59
60
  console.log("✅ RECENT_ACTIONS: ", cacheMemories);
61
+
62
+ const persistentMemory = await this.memory.persistent.findRelevantDocuments(
63
+ prompt,
64
+ {
65
+ similarityThreshold: 80,
66
+ }
67
+ );
68
+ console.log("✅ PERSISTENT_MEMORY: ", persistentMemory);
60
69
  const request = await this.orchestrator.process(
61
70
  prompt,
62
71
  `## RECENT_ACTIONS: ${JSON.stringify(
63
72
  cacheMemories
73
+ )} ## PERSISTENT_MEMORY: ${JSON.stringify(
74
+ persistentMemory
64
75
  )} ## CURRENT_RESULTS: ${this.accumulatedResults}`
65
76
  );
66
77
  events.onMessage?.(request);
@@ -124,7 +135,7 @@ export class Agent {
124
135
  return this.interpreterResult({
125
136
  data: this.accumulatedResults,
126
137
  initialPrompt,
127
- interpreter: this.interpreters[0],
138
+ interpreter: this.currentInterpreter,
128
139
  });
129
140
  }
130
141
 
@@ -134,12 +145,16 @@ export class Agent {
134
145
  this.interpreters
135
146
  );
136
147
 
137
- // const sanitizedResults = ResultSanitizer.sanitize(this.accumulatedResults);
138
148
  const evaluation = await evaluator.process(
139
149
  initialPrompt,
140
150
  this.accumulatedResults
141
151
  );
142
152
 
153
+ this.currentInterpreter = this.getInterpreter(
154
+ this.interpreters,
155
+ evaluation.interpreter
156
+ );
157
+
143
158
  events.onMessage?.(evaluation);
144
159
 
145
160
  if (evaluation.isNextActionNeeded) {
@@ -152,31 +167,29 @@ export class Agent {
152
167
  events
153
168
  );
154
169
  }
155
- const interpreter = this.getInterpreter(
156
- this.interpreters,
157
- evaluation.interpreter
158
- );
159
- if (!interpreter) {
160
- throw new Error("Interpreter not found");
161
- }
170
+
162
171
  return this.interpreterResult({
163
172
  data: this.accumulatedResults,
164
173
  initialPrompt,
165
- interpreter,
174
+ interpreter: this.currentInterpreter,
166
175
  });
167
176
  }
168
177
 
169
178
  private getInterpreter(interpreters: Interpreter[], name: string) {
179
+ console.log({ interpreters, name });
170
180
  return interpreters.find((interpreter) => interpreter.name === name);
171
181
  }
172
182
 
173
183
  private async interpreterResult(actionsResult: {
174
184
  data: string;
175
185
  initialPrompt: string;
176
- interpreter: Interpreter;
186
+ interpreter: Interpreter | undefined;
177
187
  }) {
178
188
  const { interpreter, initialPrompt, data } = actionsResult;
179
-
189
+ if (!interpreter) {
190
+ throw new Error("Interpreter not found");
191
+ }
192
+ console.log("✅ INTERPRETER: ", interpreter.name);
180
193
  return this.stream
181
194
  ? (
182
195
  await interpreter.streamProcess(initialPrompt, {
@@ -1,13 +1,15 @@
1
1
  export const evaluatorContext = {
2
2
  behavior: {
3
- language: "user_language",
4
- role: "Your role is to verify if the goal has been achieved and make a response or suggest next actions.",
3
+ language: "same_as_user",
4
+ role: "Your role is to ensure the goal will be achieved and make a response or suggest next actions.",
5
5
  guidelines: {
6
6
  important: [
7
- "Verify if all required actions were executed successfully.",
8
- "Check if the results align with the initial goal.",
7
+ "Verify if all actions were executed successfully (actionsAlreadyDone).",
8
+ "Check if the results align with the initial goal (explain in 'why' field).",
9
+ "Suggest next actions in 'nextActionsNeeded' if the goal is not achieved and if actions in 'actionsAlreadyDone' are not enough.",
9
10
  "If you retrieved the informations from your internal knowledge base, no need to store them in 'extraInformationsToStore'.",
10
- "Store ONLY extra new needed informations in 'extraInformationsToStore' (choose the most relevant informations and memory type: episodic, semantic, or procedural).",
11
+ "Store ONLY new needed informations in 'extraInformationsToStore'.",
12
+ "Choose the most relevant informations and memory type: episodic, semantic, or procedural.",
11
13
  ],
12
14
  warnings: [
13
15
  "NEVER store an old data you retrieve from your internal knowledge base.",
@@ -62,8 +62,8 @@ export class Evaluator {
62
62
  const response = await generateObject({
63
63
  model: this.model,
64
64
  schema: z.object({
65
- actionsCompleted: z.array(z.string()),
66
- actionsFailed: z.array(z.string()),
65
+ requestLanguage: z.string(),
66
+ actionsAlreadyDone: z.array(z.string()),
67
67
  extraInformationsToStore: z.array(
68
68
  z.object({
69
69
  memoryType: z.enum(["episodic", "semantic", "procedural"]),
@@ -111,7 +111,7 @@ export class Evaluator {
111
111
  console.log("Type:", item.memoryType);
112
112
  console.log("Content:", item.queryForData);
113
113
 
114
- const memories = await this.memory.persistent.searchSimilarQueries(
114
+ const memories = await this.memory.persistent.findRelevantDocuments(
115
115
  item.queryForData,
116
116
  {
117
117
  similarityThreshold: 70,
@@ -141,13 +141,13 @@ export class Evaluator {
141
141
  cacheMemory.createMemory({
142
142
  content: prompt,
143
143
  type: MemoryType.ACTION,
144
- data: validatedResponse.actionsCompleted,
144
+ data: validatedResponse.actionsAlreadyDone,
145
145
  scope: MemoryScope.GLOBAL,
146
146
  });
147
147
  console.log(
148
148
  "✅ Workflow actions completed stored in cache",
149
149
  prompt,
150
- validatedResponse.actionsCompleted
150
+ validatedResponse.actionsAlreadyDone
151
151
  );
152
152
  }
153
153
  console.log("\n✅ Evaluation completed");
@@ -164,7 +164,7 @@ export class Evaluator {
164
164
  if (error.value.extraInformationsToStore.length > 0) {
165
165
  for (const item of error.value.extraInformationsToStore) {
166
166
  // Check if the item is already in the memory
167
- const memories = await this.memory.persistent.searchSimilarQueries(
167
+ const memories = await this.memory.persistent.findRelevantDocuments(
168
168
  item.content
169
169
  );
170
170
  if (memories.length === 0) {
@@ -177,7 +177,7 @@ export class Evaluator {
177
177
  purpose: "importantToRemember",
178
178
  query: item.content,
179
179
  data: item.data,
180
- scope: MemoryScope.USER,
180
+ scope: MemoryScope.GLOBAL,
181
181
  createdAt: new Date(),
182
182
  });
183
183
  }
@@ -1,6 +1,6 @@
1
1
  export const generalInterpreterContext = {
2
2
  role: "You are the general assistant. Your role is to provide a clear and factual analysis of the results.",
3
- language: "user_language",
3
+ language: "same_as_user",
4
4
  guidelines: {
5
5
  important: [],
6
6
  warnings: [],
@@ -1,17 +1,15 @@
1
1
  export const orchestratorContext = {
2
2
  behavior: {
3
- language: "user_language",
4
- role: "You are the orchestrator agent. Your role is to determine what actions are needed to achieve the user goal.",
3
+ language: "same_as_user",
4
+ role: "Your role is to determine what actions are needed to achieve the user goal.",
5
5
  guidelines: {
6
6
  important: [
7
7
  "If there is no action to do, you must answer in the 'answer' field.",
8
8
  "If some parameters are not clear or missing, don't add the action, YOU MUST ask the user for them.",
9
- "ALWAYS use the same language as user request. (If it's English, use English, if it's French, use French, etc.)",
9
+ "For QUESTIONS or ANALYSIS, search first in your internal knowledge base before using actions.",
10
10
  "For ON-CHAIN actions, just use the useful actions.",
11
- "For QUESTIONS or ANALYSIS, you MUST search in your cache memory or/and internal knowledge base.",
12
- "NEVER repeat same actions if the user doesn't ask for it.",
13
11
  ],
14
- warnings: [],
12
+ warnings: ["NEVER repeat same actions if the user doesn't ask for it."],
15
13
  },
16
14
  },
17
15
  };
@@ -41,7 +41,7 @@ export class Orchestrator {
41
41
  }),
42
42
  execute: async ({ query }: { query: string }) => {
43
43
  const persistentMemories =
44
- await this.memory.persistent.searchSimilarQueries(query, {
44
+ await this.memory.persistent.findRelevantDocuments(query, {
45
45
  similarityThreshold: 70,
46
46
  });
47
47
  return `# LONG_TERM_MEMORY: ${JSON.stringify(persistentMemories)}`;
@@ -186,7 +186,7 @@ export class PersistentMemory {
186
186
  /**
187
187
  * Find best matching memories
188
188
  */
189
- async searchSimilarQueries(query: string, options: SearchOptions = {}) {
189
+ async findRelevantDocuments(query: string, options: SearchOptions = {}) {
190
190
  console.log("\n🔍 Searching in persistent memory");
191
191
  console.log("Query:", query);
192
192
  console.log("Options:", JSON.stringify(options, null, 2));
@@ -244,13 +244,11 @@ export class PersistentMemory {
244
244
  const results = searchResults
245
245
  .flatMap((hit) => {
246
246
  const chunkSimilarities = hit.chunks.map((chunk) => ({
247
- createdAt: hit.createdAt,
248
- data: hit.data,
249
- purpose: hit.purpose,
250
247
  query: hit.query,
251
- chunk: chunk.content,
248
+ data: hit.data,
252
249
  similarityPercentage:
253
250
  (cosineSimilarity(queryEmbedding, chunk.embedding) + 1) * 50,
251
+ createdAt: hit.createdAt,
254
252
  }));
255
253
 
256
254
  return chunkSimilarities.reduce(
@@ -275,10 +273,6 @@ export class PersistentMemory {
275
273
  results.forEach((match, index) => {
276
274
  console.log(`\n${index + 1}. Match Details:`);
277
275
  console.log(` Query: ${match.query}`);
278
- console.log(` Purpose: ${match.purpose}`);
279
- console.log(` Similarity: ${match.similarityPercentage.toFixed(2)}%`);
280
- console.log(` Content: "${match.chunk}"`);
281
- console.log("─".repeat(50));
282
276
  });
283
277
  } else {
284
278
  console.log("\n❌ No relevant matches found");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai.ntellect/core",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {