@ai.ntellect/core 0.2.7 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.FR.md +58 -19
- package/README.md +40 -17
- package/agent/index.ts +64 -36
- package/dist/agent/index.d.ts +12 -8
- package/dist/agent/index.js +42 -20
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/llm/evaluator/context.d.ts +0 -1
- package/dist/llm/evaluator/context.js +3 -12
- package/dist/llm/evaluator/index.d.ts +9 -3
- package/dist/llm/evaluator/index.js +38 -26
- package/dist/llm/interpreter/context.d.ts +32 -0
- package/dist/llm/interpreter/context.js +90 -0
- package/dist/llm/interpreter/index.d.ts +17 -0
- package/dist/llm/{synthesizer → interpreter}/index.js +19 -29
- package/dist/llm/orchestrator/context.js +1 -1
- package/dist/llm/orchestrator/index.d.ts +9 -5
- package/dist/llm/orchestrator/index.js +6 -49
- package/dist/memory/cache.d.ts +2 -2
- package/dist/memory/cache.js +4 -5
- package/dist/memory/persistent.d.ts +1 -0
- package/dist/memory/persistent.js +2 -1
- package/dist/test.d.ts +54 -0
- package/dist/test.js +125 -20
- package/dist/types.d.ts +12 -13
- package/index.ts +2 -2
- package/llm/evaluator/context.ts +3 -12
- package/llm/evaluator/index.ts +59 -30
- package/llm/interpreter/context.ts +89 -0
- package/llm/{synthesizer → interpreter}/index.ts +21 -28
- package/llm/orchestrator/context.ts +1 -1
- package/llm/orchestrator/index.ts +16 -75
- package/memory/cache.ts +5 -6
- package/memory/persistent.ts +3 -1
- package/package.json +1 -1
- package/types.ts +13 -13
- package/dist/llm/synthesizer/context.d.ts +0 -15
- package/dist/llm/synthesizer/context.js +0 -71
- package/dist/llm/synthesizer/index.d.ts +0 -14
- package/llm/synthesizer/context.ts +0 -68
package/README.FR.md
CHANGED
@@ -5,8 +5,8 @@
|
|
5
5
|
1. [Composants principaux](#composants-principaux)
|
6
6
|
- [Orchestrator](#orchestrator)
|
7
7
|
- [Queue Manager](#queue-manager)
|
8
|
-
- [Synthétiseur](#synthétiseur)
|
9
8
|
- [Évaluateur](#évaluateur)
|
9
|
+
- [Interpreter](#interpreter)
|
10
10
|
- [Mémoire](#architecture-mémoire)
|
11
11
|
2. [Création et gestion des actions](#création-et-gestion-des-actions)
|
12
12
|
3. [Exécution du Workflow](#exécution-du-workflow)
|
@@ -39,29 +39,47 @@ Le gestionnaire de la file d'attente (Queue Manager) organise les actions à ex
|
|
39
39
|
- Gérer les priorités des actions.
|
40
40
|
- Assurer une exécution correcte et en temps voulu des actions.
|
41
41
|
|
42
|
-
###
|
42
|
+
### Évaluateur
|
43
43
|
|
44
|
-
|
44
|
+
L'évaluateur collabore maintenant avec les Interpreters :
|
45
45
|
|
46
|
-
-
|
47
|
-
-
|
48
|
-
|
49
|
-
- Crée des résumés ou des réponses adaptées.
|
46
|
+
- Analyse les résultats des actions exécutées
|
47
|
+
- Détermine si des actions supplémentaires sont nécessaires et renvoie à la Queue Manager
|
48
|
+
- Sinon, il sélectionne l'Interpreter approprié selon le type de demande
|
50
49
|
|
51
|
-
###
|
50
|
+
### Interpreter
|
52
51
|
|
53
|
-
L'
|
52
|
+
L'Interpreter est le composant spécialisé dans l'interprétation des résultats d'actions et la génération de réponses adaptées. Chaque Interpreter est configuré avec un contexte spécifique et produit des réponses dans un format adapté à son domaine d'expertise.
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
54
|
+
**Caractéristiques principales** :
|
55
|
+
|
56
|
+
- Configuration avec un contexte métier spécifique
|
57
|
+
- Format de réponse adapté au domaine
|
58
|
+
- Traitement spécialisé des données selon le contexte
|
59
|
+
|
60
|
+
**Fonctionnement** :
|
61
|
+
|
62
|
+
- Reçoit les résultats des actions via l'Evaluator
|
63
|
+
- Analyse les données selon son contexte spécifique
|
64
|
+
- Produit une réponse formatée selon les règles de son domaine
|
65
|
+
|
66
|
+
Voici quelques exemples d'Interpreters qui peuvent être implémentés :
|
67
|
+
|
68
|
+
1. **MarketInterpreter**
|
69
|
+
|
70
|
+
- Spécialisé dans l'analyse des données de marché
|
71
|
+
- Format adapté aux analyses financières
|
72
|
+
|
73
|
+
2. **SecurityInterpreter**
|
74
|
+
|
75
|
+
- Dédié aux vérifications de sécurité
|
76
|
+
- Format optimisé pour les rapports de sécurité
|
77
|
+
|
78
|
+
3. **GeneralInterpreter**
|
79
|
+
- Traitement des requêtes générales
|
80
|
+
- Format flexible selon le contexte
|
81
|
+
|
82
|
+
Ces exemples illustrent la flexibilité du système, qui peut être étendu avec d'autres types d'Interpreters selon les besoins.
|
65
83
|
|
66
84
|
[![Sans-titre-2024-11-08-0220.png](https://i.postimg.cc/nryjsx5y/Sans-titre-2024-11-08-0220.png)](https://postimg.cc/rR9FbBqj)
|
67
85
|
|
@@ -329,3 +347,24 @@ Voici les éléments actuellement en développement ou à améliorer :
|
|
329
347
|
- [ ] Tester l'intégration, la sécurité et la transparence des actions Lit pour garantir leur bon fonctionnement.
|
330
348
|
|
331
349
|
**Statut** : En cours d'étude pour déterminer la faisabilité et les implications techniques, notamment en ce qui concerne l'intégration de la décentralisation dans le système existant.
|
350
|
+
|
351
|
+
### Exemple d'utilisation
|
352
|
+
|
353
|
+
```typescript
|
354
|
+
const securityInterpreter = new Interpreter("security", securityContext);
|
355
|
+
const marketInterpreter = new Interpreter("market", marketContext);
|
356
|
+
const generalInterpreter = new Interpreter("general", generalContext);
|
357
|
+
|
358
|
+
const agent = new Agent({
|
359
|
+
interpreters: [securityInterpreter, marketInterpreter, generalInterpreter],
|
360
|
+
orchestrator,
|
361
|
+
memory: {
|
362
|
+
persistent: memory,
|
363
|
+
cache: cacheMemory,
|
364
|
+
},
|
365
|
+
stream: false,
|
366
|
+
maxEvaluatorIteration: 1,
|
367
|
+
});
|
368
|
+
|
369
|
+
const result = await agent.process(prompt, context);
|
370
|
+
```
|
package/README.md
CHANGED
@@ -5,8 +5,8 @@
|
|
5
5
|
1. [Main components](#main-components)
|
6
6
|
- [Agent](#agent)
|
7
7
|
- [Orchestrator](#orchestrator)
|
8
|
-
- [Synthesizer](#synthesizer)
|
9
8
|
- [Evaluator](#evaluator)
|
9
|
+
- [Interpreter](#interpreter)
|
10
10
|
- [Memory](#memory-architecture)
|
11
11
|
2. [Action creation and management](#action-creation-and-management)
|
12
12
|
3. [Agent processing](#agent-processing)
|
@@ -41,31 +41,54 @@ The orchestrator works under the agent's direction to manage the execution of ac
|
|
41
41
|
- Uses memory for context and caching
|
42
42
|
- Coordinates with evaluator for result assessment
|
43
43
|
|
44
|
-
### Synthesizer
|
45
|
-
|
46
|
-
The synthesizer is responsible for generating responses and analyzing actions based on the results obtained in the workflow. It can create summaries or more complex responses from the raw results obtained during the execution of actions.
|
47
|
-
|
48
|
-
- **Main role**: Transform the results of actions into a comprehensible and structured output
|
49
|
-
- **Interactions**:
|
50
|
-
- Takes the results of executed actions
|
51
|
-
- Creates summaries or tailored responses
|
52
|
-
- Formats final output for user consumption
|
53
|
-
- Can handle streaming responses
|
54
|
-
|
55
44
|
### Evaluator
|
56
45
|
|
57
|
-
The evaluator
|
46
|
+
The evaluator now collaborates with Interpreters to process action results and determine the next steps in the workflow.
|
58
47
|
|
59
|
-
- **Main role**: Evaluate action results and
|
48
|
+
- **Main role**: Evaluate action results and coordinate with appropriate Interpreters
|
60
49
|
- **Main functions**:
|
61
50
|
- Analyzes results from executed actions
|
62
51
|
- Determines if additional actions are needed
|
63
|
-
-
|
52
|
+
- Routes results to appropriate Interpreter
|
64
53
|
- Ensures completion of user requirements
|
65
54
|
- **Interactions**:
|
66
55
|
- Works with orchestrator to manage workflow
|
67
|
-
-
|
68
|
-
- Can trigger additional action cycles
|
56
|
+
- Coordinates with Interpreters for specialized processing
|
57
|
+
- Can trigger additional action cycles if needed
|
58
|
+
|
59
|
+
### Interpreter
|
60
|
+
|
61
|
+
The Interpreter is a specialized component responsible for interpreting action results and generating appropriate responses. Each Interpreter is configured with a specific business context and produces responses in a format adapted to its domain of expertise.
|
62
|
+
|
63
|
+
**Key characteristics**:
|
64
|
+
|
65
|
+
- Business-specific context configuration
|
66
|
+
- Domain-adapted response formatting
|
67
|
+
- Specialized data processing based on context
|
68
|
+
|
69
|
+
**Operation flow**:
|
70
|
+
|
71
|
+
- Receives action results via the Evaluator
|
72
|
+
- Analyzes data according to its specific context
|
73
|
+
- Produces formatted responses following domain rules
|
74
|
+
|
75
|
+
Examples of Interpreter implementations:
|
76
|
+
|
77
|
+
1. **MarketInterpreter**
|
78
|
+
|
79
|
+
- Specialized in market data analysis
|
80
|
+
- Format adapted for financial analysis
|
81
|
+
|
82
|
+
2. **SecurityInterpreter**
|
83
|
+
|
84
|
+
- Dedicated to security verifications
|
85
|
+
- Optimized format for security reports
|
86
|
+
|
87
|
+
3. **GeneralInterpreter**
|
88
|
+
- Handles general purpose requests
|
89
|
+
- Flexible formatting based on context
|
90
|
+
|
91
|
+
These examples demonstrate the system's flexibility, which can be extended with additional Interpreter types as needed.
|
69
92
|
|
70
93
|
[![Sans-titre-2024-11-08-0220.png](https://i.postimg.cc/nryjsx5y/Sans-titre-2024-11-08-0220.png)](https://postimg.cc/rR9FbBqj)
|
71
94
|
|
package/agent/index.ts
CHANGED
@@ -1,52 +1,67 @@
|
|
1
1
|
import { Evaluator } from "../llm/evaluator";
|
2
|
+
import { Interpreter } from "../llm/interpreter";
|
2
3
|
import { Orchestrator } from "../llm/orchestrator";
|
3
|
-
import { Synthesizer } from "../llm/synthesizer";
|
4
4
|
import { CacheMemory } from "../memory/cache";
|
5
5
|
import { PersistentMemory } from "../memory/persistent";
|
6
|
-
import { ActionSchema, AgentEvent,
|
6
|
+
import { ActionSchema, AgentEvent, MemoryScope, QueueResult } from "../types";
|
7
7
|
import { QueueItemTransformer } from "../utils/queue-item-transformer";
|
8
|
+
import { ResultSanitizer } from "../utils/sanitize-results";
|
8
9
|
import { ActionHandler } from "./handlers/ActionHandler";
|
9
10
|
|
10
11
|
export class Agent {
|
11
12
|
private readonly actionHandler: ActionHandler;
|
12
13
|
private readonly orchestrator: Orchestrator;
|
13
|
-
private readonly
|
14
|
-
private readonly
|
14
|
+
private readonly interpreters: Interpreter[];
|
15
|
+
private readonly memory: {
|
16
|
+
persistent: PersistentMemory;
|
17
|
+
cache?: CacheMemory;
|
18
|
+
};
|
15
19
|
private readonly stream: boolean;
|
16
20
|
private readonly maxEvaluatorIteration: number;
|
17
21
|
private evaluatorIteration = 0;
|
18
|
-
private accumulatedResults:
|
22
|
+
private accumulatedResults: string = "";
|
19
23
|
|
20
24
|
constructor({
|
21
25
|
orchestrator,
|
22
|
-
|
23
|
-
|
26
|
+
interpreters,
|
27
|
+
memory,
|
24
28
|
stream,
|
25
29
|
maxEvaluatorIteration = 1,
|
26
30
|
}: {
|
27
|
-
user: User;
|
28
31
|
orchestrator: Orchestrator;
|
29
|
-
|
30
|
-
|
32
|
+
interpreters: Interpreter[];
|
33
|
+
memory: {
|
34
|
+
persistent: PersistentMemory;
|
35
|
+
cache?: CacheMemory;
|
36
|
+
};
|
31
37
|
stream: boolean;
|
32
38
|
maxEvaluatorIteration: number;
|
33
39
|
}) {
|
34
40
|
this.orchestrator = orchestrator;
|
35
|
-
this.
|
36
|
-
this.
|
41
|
+
this.interpreters = interpreters;
|
42
|
+
this.memory = memory;
|
37
43
|
this.stream = stream;
|
38
44
|
this.maxEvaluatorIteration = maxEvaluatorIteration;
|
39
45
|
this.actionHandler = new ActionHandler();
|
40
|
-
this.accumulatedResults =
|
46
|
+
this.accumulatedResults = "";
|
41
47
|
}
|
42
48
|
|
43
49
|
async process(prompt: string, events: AgentEvent): Promise<any> {
|
44
|
-
this.accumulatedResults =
|
50
|
+
this.accumulatedResults = "";
|
45
51
|
this.evaluatorIteration = 0;
|
46
52
|
console.log("Requesting orchestrator for actions..");
|
53
|
+
const cacheMemories = await this.memory.cache?.findSimilarActions(prompt, {
|
54
|
+
similarityThreshold: 70,
|
55
|
+
maxResults: 5,
|
56
|
+
userId: "1",
|
57
|
+
scope: MemoryScope.GLOBAL,
|
58
|
+
});
|
59
|
+
console.log("✅ RECENT_ACTIONS: ", cacheMemories);
|
47
60
|
const request = await this.orchestrator.process(
|
48
61
|
prompt,
|
49
|
-
|
62
|
+
`## RECENT_ACTIONS: ${JSON.stringify(
|
63
|
+
cacheMemories
|
64
|
+
)} ## CURRENT_RESULTS: ${this.accumulatedResults}`
|
50
65
|
);
|
51
66
|
events.onMessage?.(request);
|
52
67
|
|
@@ -92,10 +107,7 @@ export class Agent {
|
|
92
107
|
}
|
93
108
|
);
|
94
109
|
|
95
|
-
this.accumulatedResults
|
96
|
-
...this.accumulatedResults,
|
97
|
-
...actionsResult.data,
|
98
|
-
]);
|
110
|
+
this.accumulatedResults += this.formatResults(actionsResult.data);
|
99
111
|
|
100
112
|
const isOnChainAction = actions.some(
|
101
113
|
(action) => action.type === "on-chain"
|
@@ -109,15 +121,17 @@ export class Agent {
|
|
109
121
|
}
|
110
122
|
|
111
123
|
if (this.evaluatorIteration >= this.maxEvaluatorIteration) {
|
112
|
-
return this.
|
124
|
+
return this.interpreterResult({
|
113
125
|
data: this.accumulatedResults,
|
114
126
|
initialPrompt,
|
127
|
+
interpreter: this.interpreters[0],
|
115
128
|
});
|
116
129
|
}
|
117
130
|
|
118
131
|
const evaluator = new Evaluator(
|
119
132
|
this.orchestrator.tools,
|
120
|
-
this.
|
133
|
+
this.memory,
|
134
|
+
this.interpreters
|
121
135
|
);
|
122
136
|
|
123
137
|
// const sanitizedResults = ResultSanitizer.sanitize(this.accumulatedResults);
|
@@ -138,30 +152,42 @@ export class Agent {
|
|
138
152
|
events
|
139
153
|
);
|
140
154
|
}
|
141
|
-
|
142
|
-
|
155
|
+
const interpreter = this.getInterpreter(
|
156
|
+
this.interpreters,
|
157
|
+
evaluation.interpreter
|
158
|
+
);
|
159
|
+
if (!interpreter) {
|
160
|
+
throw new Error("Interpreter not found");
|
161
|
+
}
|
162
|
+
return this.interpreterResult({
|
143
163
|
data: this.accumulatedResults,
|
144
164
|
initialPrompt,
|
165
|
+
interpreter,
|
145
166
|
});
|
146
167
|
}
|
147
168
|
|
148
|
-
private
|
149
|
-
|
169
|
+
private getInterpreter(interpreters: Interpreter[], name: string) {
|
170
|
+
return interpreters.find((interpreter) => interpreter.name === name);
|
171
|
+
}
|
172
|
+
|
173
|
+
private async interpreterResult(actionsResult: {
|
174
|
+
data: string;
|
150
175
|
initialPrompt: string;
|
176
|
+
interpreter: Interpreter;
|
151
177
|
}) {
|
152
|
-
const
|
178
|
+
const { interpreter, initialPrompt, data } = actionsResult;
|
153
179
|
|
154
180
|
return this.stream
|
155
181
|
? (
|
156
|
-
await
|
157
|
-
|
158
|
-
|
159
|
-
)
|
182
|
+
await interpreter.streamProcess(initialPrompt, {
|
183
|
+
userRequest: initialPrompt,
|
184
|
+
results: data,
|
185
|
+
})
|
160
186
|
).toDataStreamResponse()
|
161
|
-
: await
|
162
|
-
|
163
|
-
|
164
|
-
);
|
187
|
+
: await interpreter.process(initialPrompt, {
|
188
|
+
userRequest: initialPrompt,
|
189
|
+
results: data,
|
190
|
+
});
|
165
191
|
}
|
166
192
|
|
167
193
|
private transformActions(actions: ActionSchema[]) {
|
@@ -171,13 +197,15 @@ export class Agent {
|
|
171
197
|
return predefinedActions;
|
172
198
|
}
|
173
199
|
|
174
|
-
private formatResults(results: QueueResult[]):
|
175
|
-
|
200
|
+
private formatResults(results: QueueResult[]): string {
|
201
|
+
const formattedResults = results.map((result) => ({
|
176
202
|
...result,
|
177
203
|
result:
|
178
204
|
typeof result.result === "object"
|
179
205
|
? JSON.stringify(result.result)
|
180
206
|
: result.result,
|
181
207
|
}));
|
208
|
+
const sanitizedResults = ResultSanitizer.sanitize(formattedResults);
|
209
|
+
return sanitizedResults;
|
182
210
|
}
|
183
211
|
}
|
package/dist/agent/index.d.ts
CHANGED
@@ -1,27 +1,31 @@
|
|
1
|
+
import { Interpreter } from "../llm/interpreter";
|
1
2
|
import { Orchestrator } from "../llm/orchestrator";
|
2
3
|
import { CacheMemory } from "../memory/cache";
|
3
4
|
import { PersistentMemory } from "../memory/persistent";
|
4
|
-
import { AgentEvent
|
5
|
+
import { AgentEvent } from "../types";
|
5
6
|
export declare class Agent {
|
6
7
|
private readonly actionHandler;
|
7
8
|
private readonly orchestrator;
|
8
|
-
private readonly
|
9
|
-
private readonly
|
9
|
+
private readonly interpreters;
|
10
|
+
private readonly memory;
|
10
11
|
private readonly stream;
|
11
12
|
private readonly maxEvaluatorIteration;
|
12
13
|
private evaluatorIteration;
|
13
14
|
private accumulatedResults;
|
14
|
-
constructor({ orchestrator,
|
15
|
-
user: User;
|
15
|
+
constructor({ orchestrator, interpreters, memory, stream, maxEvaluatorIteration, }: {
|
16
16
|
orchestrator: Orchestrator;
|
17
|
-
|
18
|
-
|
17
|
+
interpreters: Interpreter[];
|
18
|
+
memory: {
|
19
|
+
persistent: PersistentMemory;
|
20
|
+
cache?: CacheMemory;
|
21
|
+
};
|
19
22
|
stream: boolean;
|
20
23
|
maxEvaluatorIteration: number;
|
21
24
|
});
|
22
25
|
process(prompt: string, events: AgentEvent): Promise<any>;
|
23
26
|
private handleActions;
|
24
|
-
private
|
27
|
+
private getInterpreter;
|
28
|
+
private interpreterResult;
|
25
29
|
private transformActions;
|
26
30
|
private formatResults;
|
27
31
|
}
|
package/dist/agent/index.js
CHANGED
@@ -2,26 +2,34 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.Agent = void 0;
|
4
4
|
const evaluator_1 = require("../llm/evaluator");
|
5
|
-
const
|
5
|
+
const types_1 = require("../types");
|
6
6
|
const queue_item_transformer_1 = require("../utils/queue-item-transformer");
|
7
|
+
const sanitize_results_1 = require("../utils/sanitize-results");
|
7
8
|
const ActionHandler_1 = require("./handlers/ActionHandler");
|
8
9
|
class Agent {
|
9
|
-
constructor({ orchestrator,
|
10
|
+
constructor({ orchestrator, interpreters, memory, stream, maxEvaluatorIteration = 1, }) {
|
10
11
|
this.evaluatorIteration = 0;
|
11
|
-
this.accumulatedResults =
|
12
|
+
this.accumulatedResults = "";
|
12
13
|
this.orchestrator = orchestrator;
|
13
|
-
this.
|
14
|
-
this.
|
14
|
+
this.interpreters = interpreters;
|
15
|
+
this.memory = memory;
|
15
16
|
this.stream = stream;
|
16
17
|
this.maxEvaluatorIteration = maxEvaluatorIteration;
|
17
18
|
this.actionHandler = new ActionHandler_1.ActionHandler();
|
18
|
-
this.accumulatedResults =
|
19
|
+
this.accumulatedResults = "";
|
19
20
|
}
|
20
21
|
async process(prompt, events) {
|
21
|
-
this.accumulatedResults =
|
22
|
+
this.accumulatedResults = "";
|
22
23
|
this.evaluatorIteration = 0;
|
23
24
|
console.log("Requesting orchestrator for actions..");
|
24
|
-
const
|
25
|
+
const cacheMemories = await this.memory.cache?.findSimilarActions(prompt, {
|
26
|
+
similarityThreshold: 70,
|
27
|
+
maxResults: 5,
|
28
|
+
userId: "1",
|
29
|
+
scope: types_1.MemoryScope.GLOBAL,
|
30
|
+
});
|
31
|
+
console.log("✅ RECENT_ACTIONS: ", cacheMemories);
|
32
|
+
const request = await this.orchestrator.process(prompt, `## RECENT_ACTIONS: ${JSON.stringify(cacheMemories)} ## CURRENT_RESULTS: ${this.accumulatedResults}`);
|
25
33
|
events.onMessage?.(request);
|
26
34
|
return request.actions.length > 0
|
27
35
|
? this.handleActions({
|
@@ -39,10 +47,7 @@ class Agent {
|
|
39
47
|
onQueueComplete: events.onQueueComplete,
|
40
48
|
onConfirmationRequired: events.onConfirmationRequired,
|
41
49
|
});
|
42
|
-
this.accumulatedResults
|
43
|
-
...this.accumulatedResults,
|
44
|
-
...actionsResult.data,
|
45
|
-
]);
|
50
|
+
this.accumulatedResults += this.formatResults(actionsResult.data);
|
46
51
|
const isOnChainAction = actions.some((action) => action.type === "on-chain");
|
47
52
|
if (isOnChainAction) {
|
48
53
|
return {
|
@@ -51,12 +56,13 @@ class Agent {
|
|
51
56
|
};
|
52
57
|
}
|
53
58
|
if (this.evaluatorIteration >= this.maxEvaluatorIteration) {
|
54
|
-
return this.
|
59
|
+
return this.interpreterResult({
|
55
60
|
data: this.accumulatedResults,
|
56
61
|
initialPrompt,
|
62
|
+
interpreter: this.interpreters[0],
|
57
63
|
});
|
58
64
|
}
|
59
|
-
const evaluator = new evaluator_1.Evaluator(this.orchestrator.tools, this.
|
65
|
+
const evaluator = new evaluator_1.Evaluator(this.orchestrator.tools, this.memory, this.interpreters);
|
60
66
|
// const sanitizedResults = ResultSanitizer.sanitize(this.accumulatedResults);
|
61
67
|
const evaluation = await evaluator.process(initialPrompt, this.accumulatedResults);
|
62
68
|
events.onMessage?.(evaluation);
|
@@ -67,28 +73,44 @@ class Agent {
|
|
67
73
|
actions: evaluation.nextActionsNeeded,
|
68
74
|
}, events);
|
69
75
|
}
|
70
|
-
|
76
|
+
const interpreter = this.getInterpreter(this.interpreters, evaluation.interpreter);
|
77
|
+
if (!interpreter) {
|
78
|
+
throw new Error("Interpreter not found");
|
79
|
+
}
|
80
|
+
return this.interpreterResult({
|
71
81
|
data: this.accumulatedResults,
|
72
82
|
initialPrompt,
|
83
|
+
interpreter,
|
73
84
|
});
|
74
85
|
}
|
75
|
-
|
76
|
-
|
86
|
+
getInterpreter(interpreters, name) {
|
87
|
+
return interpreters.find((interpreter) => interpreter.name === name);
|
88
|
+
}
|
89
|
+
async interpreterResult(actionsResult) {
|
90
|
+
const { interpreter, initialPrompt, data } = actionsResult;
|
77
91
|
return this.stream
|
78
|
-
? (await
|
79
|
-
|
92
|
+
? (await interpreter.streamProcess(initialPrompt, {
|
93
|
+
userRequest: initialPrompt,
|
94
|
+
results: data,
|
95
|
+
})).toDataStreamResponse()
|
96
|
+
: await interpreter.process(initialPrompt, {
|
97
|
+
userRequest: initialPrompt,
|
98
|
+
results: data,
|
99
|
+
});
|
80
100
|
}
|
81
101
|
transformActions(actions) {
|
82
102
|
let predefinedActions = queue_item_transformer_1.QueueItemTransformer.transformActionsToQueueItems(actions) || [];
|
83
103
|
return predefinedActions;
|
84
104
|
}
|
85
105
|
formatResults(results) {
|
86
|
-
|
106
|
+
const formattedResults = results.map((result) => ({
|
87
107
|
...result,
|
88
108
|
result: typeof result.result === "object"
|
89
109
|
? JSON.stringify(result.result)
|
90
110
|
: result.result,
|
91
111
|
}));
|
112
|
+
const sanitizedResults = sanitize_results_1.ResultSanitizer.sanitize(formattedResults);
|
113
|
+
return sanitizedResults;
|
92
114
|
}
|
93
115
|
}
|
94
116
|
exports.Agent = Agent;
|
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
export * from "./agent";
|
2
|
+
export * from "./llm/interpreter";
|
3
|
+
export * from "./llm/interpreter/context";
|
2
4
|
export * from "./llm/orchestrator";
|
3
|
-
export * from "./llm/synthesizer";
|
4
5
|
export * from "./types";
|
5
6
|
export * from "./memory/cache";
|
6
7
|
export * from "./memory/persistent";
|
package/dist/index.js
CHANGED
@@ -15,8 +15,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
__exportStar(require("./agent"), exports);
|
18
|
+
__exportStar(require("./llm/interpreter"), exports);
|
19
|
+
__exportStar(require("./llm/interpreter/context"), exports);
|
18
20
|
__exportStar(require("./llm/orchestrator"), exports);
|
19
|
-
__exportStar(require("./llm/synthesizer"), exports);
|
20
21
|
__exportStar(require("./types"), exports);
|
21
22
|
__exportStar(require("./memory/cache"), exports);
|
22
23
|
__exportStar(require("./memory/persistent"), exports);
|
@@ -9,23 +9,14 @@ exports.evaluatorContext = {
|
|
9
9
|
important: [
|
10
10
|
"Verify if all required actions were executed successfully.",
|
11
11
|
"Check if the results align with the initial goal.",
|
12
|
-
"
|
13
|
-
"
|
14
|
-
" - Associate a wallet address (e.g., '0x1234...abcd') to a user-friendly name (e.g., 'Work Wallet').",
|
15
|
-
" - Map a token address (e.g., '0x6B17...71d0F') back to its symbol or name (e.g., 'DAI').",
|
16
|
-
"Store these facts in memory with their type (episodic, semantic, or procedural).",
|
12
|
+
"If you retrieved the informations from your internal knowledge base, no need to store them in 'extraInformationsToStore'.",
|
13
|
+
"Store ONLY extra new needed informations in 'extraInformationsToStore' (choose the most relevant informations and memory type: episodic, semantic, or procedural).",
|
17
14
|
],
|
18
15
|
warnings: [
|
19
|
-
"NEVER
|
16
|
+
"NEVER store an old data you retrieve from your internal knowledge base.",
|
20
17
|
"NEVER make assumptions about missing data.",
|
21
18
|
"NEVER repeat actions already completed unless explicitly required.",
|
22
19
|
],
|
23
|
-
steps: [
|
24
|
-
"Verify success: Confirm if the goal has been fully or partially achieved. If partially, describe what's missing.",
|
25
|
-
"Recommend next actions: Clearly state what needs to be done next (if applicable) and why.",
|
26
|
-
"Store key facts: Store any relevant information in memory with their type (episodic, semantic, or procedural).",
|
27
|
-
"Be clear, concise, and prioritize storing key facts that may help improve future interactions.",
|
28
|
-
],
|
29
20
|
},
|
30
21
|
},
|
31
22
|
};
|
@@ -1,10 +1,16 @@
|
|
1
|
+
import { CacheMemory } from "../../memory/cache";
|
1
2
|
import { PersistentMemory } from "../../memory/persistent";
|
2
|
-
import { ActionSchema,
|
3
|
+
import { ActionSchema, State } from "../../types";
|
4
|
+
import { Interpreter } from "../interpreter";
|
3
5
|
export declare class Evaluator {
|
4
6
|
private readonly model;
|
5
7
|
tools: ActionSchema[];
|
6
8
|
private memory;
|
7
|
-
|
9
|
+
private interpreters;
|
10
|
+
constructor(tools: ActionSchema[], memory: {
|
11
|
+
persistent: PersistentMemory;
|
12
|
+
cache?: CacheMemory;
|
13
|
+
}, interpreters: Interpreter[]);
|
8
14
|
composeContext(state: State): string;
|
9
|
-
process(prompt: string, results:
|
15
|
+
process(prompt: string, results: string): Promise<any>;
|
10
16
|
}
|