@ai.ntellect/core 0.3.1 ā 0.4.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/.nvmrc +1 -0
- package/README.FR.md +201 -261
- package/README.md +208 -260
- package/agent/index.ts +204 -185
- package/agent/tools/get-rss.ts +64 -0
- package/bull.ts +5 -0
- package/dist/agent/index.d.ts +29 -22
- package/dist/agent/index.js +124 -97
- package/dist/agent/tools/get-rss.d.ts +16 -0
- package/dist/agent/tools/get-rss.js +62 -0
- package/dist/bull.d.ts +1 -0
- package/dist/bull.js +9 -0
- package/dist/examples/index.d.ts +2 -0
- package/dist/examples/index.js +89 -0
- package/dist/llm/interpreter/context.d.ts +5 -22
- package/dist/llm/interpreter/context.js +8 -9
- package/dist/llm/interpreter/index.d.ts +9 -5
- package/dist/llm/interpreter/index.js +55 -48
- package/dist/llm/memory-manager/context.d.ts +2 -0
- package/dist/llm/memory-manager/context.js +22 -0
- package/dist/llm/memory-manager/index.d.ts +17 -0
- package/dist/llm/memory-manager/index.js +107 -0
- package/dist/llm/orchestrator/context.d.ts +2 -10
- package/dist/llm/orchestrator/context.js +19 -16
- package/dist/llm/orchestrator/index.d.ts +36 -21
- package/dist/llm/orchestrator/index.js +122 -88
- package/dist/llm/orchestrator/types.d.ts +12 -0
- package/dist/llm/orchestrator/types.js +2 -0
- package/dist/memory/cache.d.ts +6 -6
- package/dist/memory/cache.js +35 -42
- package/dist/memory/persistent.d.ts +9 -13
- package/dist/memory/persistent.js +94 -114
- package/dist/services/redis-cache.d.ts +37 -0
- package/dist/services/redis-cache.js +93 -0
- package/dist/services/scheduler.d.ts +40 -0
- package/dist/services/scheduler.js +99 -0
- package/dist/services/telegram-monitor.d.ts +0 -0
- package/dist/services/telegram-monitor.js +118 -0
- package/dist/test.d.ts +0 -167
- package/dist/test.js +437 -372
- package/dist/types.d.ts +60 -9
- package/dist/utils/generate-object.d.ts +12 -0
- package/dist/utils/generate-object.js +90 -0
- package/dist/utils/header-builder.d.ts +11 -0
- package/dist/utils/header-builder.js +34 -0
- package/dist/utils/inject-actions.js +2 -2
- package/dist/utils/queue-item-transformer.d.ts +2 -2
- package/dist/utils/schema-generator.d.ts +16 -0
- package/dist/utils/schema-generator.js +46 -0
- package/examples/index.ts +103 -0
- package/llm/interpreter/context.ts +20 -8
- package/llm/interpreter/index.ts +81 -54
- package/llm/memory-manager/context.ts +21 -0
- package/llm/memory-manager/index.ts +163 -0
- package/llm/orchestrator/context.ts +20 -13
- package/llm/orchestrator/index.ts +210 -130
- package/llm/orchestrator/types.ts +14 -0
- package/memory/cache.ts +41 -55
- package/memory/persistent.ts +121 -149
- package/package.json +11 -2
- package/services/redis-cache.ts +128 -0
- package/services/scheduler.ts +128 -0
- package/services/telegram-monitor.ts +138 -0
- package/t.py +79 -0
- package/t.spec +38 -0
- package/types.ts +64 -9
- package/utils/generate-object.ts +105 -0
- package/utils/header-builder.ts +40 -0
- package/utils/inject-actions.ts +4 -6
- package/utils/queue-item-transformer.ts +2 -1
- package/utils/schema-generator.ts +73 -0
- package/agent/handlers/ActionHandler.ts +0 -48
- package/agent/handlers/ConfirmationHandler.ts +0 -37
- package/agent/handlers/EventHandler.ts +0 -35
- package/dist/agent/handlers/ActionHandler.d.ts +0 -8
- package/dist/agent/handlers/ActionHandler.js +0 -36
- package/dist/agent/handlers/ConfirmationHandler.d.ts +0 -7
- package/dist/agent/handlers/ConfirmationHandler.js +0 -31
- package/dist/agent/handlers/EventHandler.d.ts +0 -10
- package/dist/agent/handlers/EventHandler.js +0 -34
- package/dist/llm/evaluator/context.d.ts +0 -10
- package/dist/llm/evaluator/context.js +0 -22
- package/dist/llm/evaluator/index.d.ts +0 -16
- package/dist/llm/evaluator/index.js +0 -151
- package/llm/evaluator/context.ts +0 -21
- package/llm/evaluator/index.ts +0 -194
@@ -1,151 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.Evaluator = void 0;
|
4
|
-
const openai_1 = require("@ai-sdk/openai");
|
5
|
-
const ai_1 = require("ai");
|
6
|
-
const zod_1 = require("zod");
|
7
|
-
const types_1 = require("../../types");
|
8
|
-
const inject_actions_1 = require("../../utils/inject-actions");
|
9
|
-
const context_1 = require("./context");
|
10
|
-
class Evaluator {
|
11
|
-
constructor(tools, memory, interpreters) {
|
12
|
-
this.model = (0, openai_1.openai)("gpt-4o");
|
13
|
-
this.tools = tools;
|
14
|
-
this.memory = memory;
|
15
|
-
this.interpreters = interpreters;
|
16
|
-
}
|
17
|
-
composeContext(state) {
|
18
|
-
const { userRequest, results } = state;
|
19
|
-
const { role, language, guidelines } = context_1.evaluatorContext.behavior;
|
20
|
-
const { important, warnings } = guidelines;
|
21
|
-
const context = `
|
22
|
-
# ROLE: ${role}
|
23
|
-
# LANGUAGE: ${language}
|
24
|
-
# IMPORTANT: ${important.join("\n")}
|
25
|
-
# NEVER: ${warnings.join("\n")}
|
26
|
-
# USER_REQUEST: ${userRequest}
|
27
|
-
# ACTIONS AVAILABLE: ${(0, inject_actions_1.injectActions)(this.tools)}
|
28
|
-
# CURRENT_RESULTS: ${results}
|
29
|
-
# INTERPRETERS: ${this.interpreters
|
30
|
-
.map((interpreter) => interpreter.name)
|
31
|
-
.join(", ")}
|
32
|
-
`;
|
33
|
-
return context;
|
34
|
-
}
|
35
|
-
async process(prompt, results) {
|
36
|
-
try {
|
37
|
-
const context = this.composeContext({
|
38
|
-
userRequest: prompt,
|
39
|
-
results: results,
|
40
|
-
});
|
41
|
-
console.log("\nš Evaluator processing");
|
42
|
-
console.log("Goal:", prompt);
|
43
|
-
const response = await (0, ai_1.generateObject)({
|
44
|
-
model: this.model,
|
45
|
-
schema: zod_1.z.object({
|
46
|
-
actionsCompleted: zod_1.z.array(zod_1.z.string()),
|
47
|
-
actionsFailed: zod_1.z.array(zod_1.z.string()),
|
48
|
-
extraInformationsToStore: zod_1.z.array(zod_1.z.object({
|
49
|
-
memoryType: zod_1.z.enum(["episodic", "semantic", "procedural"]),
|
50
|
-
queryForData: zod_1.z.string(),
|
51
|
-
data: zod_1.z.string(),
|
52
|
-
tags: zod_1.z.array(zod_1.z.string()),
|
53
|
-
})),
|
54
|
-
response: zod_1.z.string(),
|
55
|
-
isNextActionNeeded: zod_1.z.boolean(),
|
56
|
-
nextActionsNeeded: zod_1.z.array(zod_1.z.object({
|
57
|
-
name: zod_1.z.string(),
|
58
|
-
parameters: zod_1.z.array(zod_1.z.object({
|
59
|
-
name: zod_1.z.string(),
|
60
|
-
value: zod_1.z.any(),
|
61
|
-
})),
|
62
|
-
})),
|
63
|
-
why: zod_1.z.string(),
|
64
|
-
interpreter: zod_1.z.string(),
|
65
|
-
}),
|
66
|
-
prompt: prompt,
|
67
|
-
system: `${context}`,
|
68
|
-
temperature: 0,
|
69
|
-
});
|
70
|
-
const validatedResponse = {
|
71
|
-
...response.object,
|
72
|
-
nextActionsNeeded: response.object.nextActionsNeeded.map((action) => ({
|
73
|
-
...action,
|
74
|
-
parameters: action.parameters || {},
|
75
|
-
})),
|
76
|
-
};
|
77
|
-
if (validatedResponse.extraInformationsToStore.length > 0) {
|
78
|
-
console.log("\nš Processing important memories to store", validatedResponse);
|
79
|
-
for (const item of validatedResponse.extraInformationsToStore) {
|
80
|
-
console.log("\nš Processing memory item:");
|
81
|
-
console.log("Type:", item.memoryType);
|
82
|
-
console.log("Content:", item.queryForData);
|
83
|
-
const memories = await this.memory.persistent.searchSimilarQueries(item.queryForData, {
|
84
|
-
similarityThreshold: 70,
|
85
|
-
});
|
86
|
-
if (memories.length > 0) {
|
87
|
-
console.log("š Similar memory already exists - skipping");
|
88
|
-
continue;
|
89
|
-
}
|
90
|
-
console.log("⨠Storing new memory");
|
91
|
-
await this.memory.persistent.createMemory({
|
92
|
-
id: crypto.randomUUID(),
|
93
|
-
purpose: item.memoryType,
|
94
|
-
query: item.queryForData,
|
95
|
-
data: item.data,
|
96
|
-
scope: types_1.MemoryScope.GLOBAL,
|
97
|
-
createdAt: new Date(),
|
98
|
-
});
|
99
|
-
}
|
100
|
-
}
|
101
|
-
// Storing workflow actions completed
|
102
|
-
const cacheMemory = this.memory.cache;
|
103
|
-
if (cacheMemory) {
|
104
|
-
cacheMemory.createMemory({
|
105
|
-
content: prompt,
|
106
|
-
type: types_1.MemoryType.ACTION,
|
107
|
-
data: validatedResponse.actionsCompleted,
|
108
|
-
scope: types_1.MemoryScope.GLOBAL,
|
109
|
-
});
|
110
|
-
console.log("ā
Workflow actions completed stored in cache", prompt, validatedResponse.actionsCompleted);
|
111
|
-
}
|
112
|
-
console.log("\nā
Evaluation completed");
|
113
|
-
console.log("ā".repeat(50));
|
114
|
-
console.log("Results:", JSON.stringify(validatedResponse, null, 2));
|
115
|
-
return validatedResponse;
|
116
|
-
}
|
117
|
-
catch (error) {
|
118
|
-
console.error("\nā Evaluator error:", error.message);
|
119
|
-
if (error) {
|
120
|
-
console.log("Evaluator error");
|
121
|
-
console.dir(error.value, { depth: null });
|
122
|
-
console.error(error.message);
|
123
|
-
if (error.value.extraInformationsToStore.length > 0) {
|
124
|
-
for (const item of error.value.extraInformationsToStore) {
|
125
|
-
// Check if the item is already in the memory
|
126
|
-
const memories = await this.memory.persistent.searchSimilarQueries(item.content);
|
127
|
-
if (memories.length === 0) {
|
128
|
-
console.log("Adding to memory", {
|
129
|
-
query: item.content,
|
130
|
-
data: item.data,
|
131
|
-
});
|
132
|
-
await this.memory.persistent.createMemory({
|
133
|
-
id: crypto.randomUUID(),
|
134
|
-
purpose: "importantToRemember",
|
135
|
-
query: item.content,
|
136
|
-
data: item.data,
|
137
|
-
scope: types_1.MemoryScope.USER,
|
138
|
-
createdAt: new Date(),
|
139
|
-
});
|
140
|
-
}
|
141
|
-
}
|
142
|
-
}
|
143
|
-
return {
|
144
|
-
...error.value,
|
145
|
-
};
|
146
|
-
}
|
147
|
-
// throw error;
|
148
|
-
}
|
149
|
-
}
|
150
|
-
}
|
151
|
-
exports.Evaluator = Evaluator;
|
package/llm/evaluator/context.ts
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
export const evaluatorContext = {
|
2
|
-
behavior: {
|
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
|
-
guidelines: {
|
6
|
-
important: [
|
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.",
|
10
|
-
"If you retrieved the informations from your internal knowledge base, no need to store them in 'extraInformationsToStore'.",
|
11
|
-
"Store ONLY new needed informations in 'extraInformationsToStore'.",
|
12
|
-
"Choose the most relevant informations and memory type: episodic, semantic, or procedural.",
|
13
|
-
],
|
14
|
-
warnings: [
|
15
|
-
"NEVER store an old data you retrieve from your internal knowledge base.",
|
16
|
-
"NEVER make assumptions about missing data.",
|
17
|
-
"NEVER repeat actions already completed unless explicitly required.",
|
18
|
-
],
|
19
|
-
},
|
20
|
-
},
|
21
|
-
};
|
package/llm/evaluator/index.ts
DELETED
@@ -1,194 +0,0 @@
|
|
1
|
-
import { openai } from "@ai-sdk/openai";
|
2
|
-
import { generateObject } from "ai";
|
3
|
-
import { z } from "zod";
|
4
|
-
import { CacheMemory } from "../../memory/cache";
|
5
|
-
import { PersistentMemory } from "../../memory/persistent";
|
6
|
-
import { ActionSchema, MemoryScope, MemoryType, State } from "../../types";
|
7
|
-
import { injectActions } from "../../utils/inject-actions";
|
8
|
-
import { Interpreter } from "../interpreter";
|
9
|
-
import { evaluatorContext } from "./context";
|
10
|
-
|
11
|
-
export class Evaluator {
|
12
|
-
private readonly model = openai("gpt-4o");
|
13
|
-
public tools: ActionSchema[];
|
14
|
-
private memory: {
|
15
|
-
persistent: PersistentMemory;
|
16
|
-
cache?: CacheMemory;
|
17
|
-
};
|
18
|
-
private interpreters: Interpreter[];
|
19
|
-
|
20
|
-
constructor(
|
21
|
-
tools: ActionSchema[],
|
22
|
-
memory: {
|
23
|
-
persistent: PersistentMemory;
|
24
|
-
cache?: CacheMemory;
|
25
|
-
},
|
26
|
-
interpreters: Interpreter[]
|
27
|
-
) {
|
28
|
-
this.tools = tools;
|
29
|
-
this.memory = memory;
|
30
|
-
this.interpreters = interpreters;
|
31
|
-
}
|
32
|
-
|
33
|
-
composeContext(state: State) {
|
34
|
-
const { userRequest, results } = state;
|
35
|
-
const { role, language, guidelines } = evaluatorContext.behavior;
|
36
|
-
const { important, warnings } = guidelines;
|
37
|
-
|
38
|
-
const context = `
|
39
|
-
# ROLE: ${role}
|
40
|
-
# LANGUAGE: ${language}
|
41
|
-
# IMPORTANT: ${important.join("\n")}
|
42
|
-
# NEVER: ${warnings.join("\n")}
|
43
|
-
# USER_REQUEST: ${userRequest}
|
44
|
-
# ACTIONS AVAILABLE: ${injectActions(this.tools)}
|
45
|
-
# CURRENT_RESULTS: ${results}
|
46
|
-
# INTERPRETERS: ${this.interpreters
|
47
|
-
.map((interpreter) => interpreter.name)
|
48
|
-
.join(", ")}
|
49
|
-
`;
|
50
|
-
return context;
|
51
|
-
}
|
52
|
-
|
53
|
-
async process(prompt: string, results: string): Promise<any> {
|
54
|
-
try {
|
55
|
-
const context = this.composeContext({
|
56
|
-
userRequest: prompt,
|
57
|
-
results: results,
|
58
|
-
});
|
59
|
-
console.log("\nš Evaluator processing");
|
60
|
-
console.log("Goal:", prompt);
|
61
|
-
|
62
|
-
const response = await generateObject({
|
63
|
-
model: this.model,
|
64
|
-
schema: z.object({
|
65
|
-
requestLanguage: z.string(),
|
66
|
-
actionsAlreadyDone: z.array(z.string()),
|
67
|
-
extraInformationsToStore: z.array(
|
68
|
-
z.object({
|
69
|
-
memoryType: z.enum(["episodic", "semantic", "procedural"]),
|
70
|
-
queryForData: z.string(),
|
71
|
-
data: z.string(),
|
72
|
-
tags: z.array(z.string()),
|
73
|
-
})
|
74
|
-
),
|
75
|
-
response: z.string(),
|
76
|
-
isNextActionNeeded: z.boolean(),
|
77
|
-
nextActionsNeeded: z.array(
|
78
|
-
z.object({
|
79
|
-
name: z.string(),
|
80
|
-
parameters: z.array(
|
81
|
-
z.object({
|
82
|
-
name: z.string(),
|
83
|
-
value: z.any(),
|
84
|
-
})
|
85
|
-
),
|
86
|
-
})
|
87
|
-
),
|
88
|
-
why: z.string(),
|
89
|
-
interpreter: z.string(),
|
90
|
-
}),
|
91
|
-
prompt: prompt,
|
92
|
-
system: `${context}`,
|
93
|
-
temperature: 0,
|
94
|
-
});
|
95
|
-
|
96
|
-
const validatedResponse = {
|
97
|
-
...response.object,
|
98
|
-
nextActionsNeeded: response.object.nextActionsNeeded.map((action) => ({
|
99
|
-
...action,
|
100
|
-
parameters: action.parameters || {},
|
101
|
-
})),
|
102
|
-
};
|
103
|
-
|
104
|
-
if (validatedResponse.extraInformationsToStore.length > 0) {
|
105
|
-
console.log(
|
106
|
-
"\nš Processing important memories to store",
|
107
|
-
validatedResponse
|
108
|
-
);
|
109
|
-
for (const item of validatedResponse.extraInformationsToStore) {
|
110
|
-
console.log("\nš Processing memory item:");
|
111
|
-
console.log("Type:", item.memoryType);
|
112
|
-
console.log("Content:", item.queryForData);
|
113
|
-
|
114
|
-
const memories = await this.memory.persistent.findRelevantDocuments(
|
115
|
-
item.queryForData,
|
116
|
-
{
|
117
|
-
similarityThreshold: 70,
|
118
|
-
}
|
119
|
-
);
|
120
|
-
|
121
|
-
if (memories.length > 0) {
|
122
|
-
console.log("š Similar memory already exists - skipping");
|
123
|
-
continue;
|
124
|
-
}
|
125
|
-
|
126
|
-
console.log("⨠Storing new memory");
|
127
|
-
await this.memory.persistent.createMemory({
|
128
|
-
id: crypto.randomUUID(),
|
129
|
-
purpose: item.memoryType,
|
130
|
-
query: item.queryForData,
|
131
|
-
data: item.data,
|
132
|
-
scope: MemoryScope.GLOBAL,
|
133
|
-
createdAt: new Date(),
|
134
|
-
});
|
135
|
-
}
|
136
|
-
}
|
137
|
-
|
138
|
-
// Storing workflow actions completed
|
139
|
-
const cacheMemory = this.memory.cache;
|
140
|
-
if (cacheMemory) {
|
141
|
-
cacheMemory.createMemory({
|
142
|
-
content: prompt,
|
143
|
-
type: MemoryType.ACTION,
|
144
|
-
data: validatedResponse.actionsAlreadyDone,
|
145
|
-
scope: MemoryScope.GLOBAL,
|
146
|
-
});
|
147
|
-
console.log(
|
148
|
-
"ā
Workflow actions completed stored in cache",
|
149
|
-
prompt,
|
150
|
-
validatedResponse.actionsAlreadyDone
|
151
|
-
);
|
152
|
-
}
|
153
|
-
console.log("\nā
Evaluation completed");
|
154
|
-
console.log("ā".repeat(50));
|
155
|
-
console.log("Results:", JSON.stringify(validatedResponse, null, 2));
|
156
|
-
|
157
|
-
return validatedResponse;
|
158
|
-
} catch (error: any) {
|
159
|
-
console.error("\nā Evaluator error:", error.message);
|
160
|
-
if (error) {
|
161
|
-
console.log("Evaluator error");
|
162
|
-
console.dir(error.value, { depth: null });
|
163
|
-
console.error(error.message);
|
164
|
-
if (error.value.extraInformationsToStore.length > 0) {
|
165
|
-
for (const item of error.value.extraInformationsToStore) {
|
166
|
-
// Check if the item is already in the memory
|
167
|
-
const memories = await this.memory.persistent.findRelevantDocuments(
|
168
|
-
item.content
|
169
|
-
);
|
170
|
-
if (memories.length === 0) {
|
171
|
-
console.log("Adding to memory", {
|
172
|
-
query: item.content,
|
173
|
-
data: item.data,
|
174
|
-
});
|
175
|
-
await this.memory.persistent.createMemory({
|
176
|
-
id: crypto.randomUUID(),
|
177
|
-
purpose: "importantToRemember",
|
178
|
-
query: item.content,
|
179
|
-
data: item.data,
|
180
|
-
scope: MemoryScope.GLOBAL,
|
181
|
-
createdAt: new Date(),
|
182
|
-
});
|
183
|
-
}
|
184
|
-
}
|
185
|
-
}
|
186
|
-
|
187
|
-
return {
|
188
|
-
...error.value,
|
189
|
-
};
|
190
|
-
}
|
191
|
-
// throw error;
|
192
|
-
}
|
193
|
-
}
|
194
|
-
}
|