@ai.ntellect/core 0.4.0 → 0.4.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/README.FR.md +55 -0
- package/README.md +127 -72
- package/agent/index.ts +4 -3
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +3 -3
- package/package.json +1 -1
package/README.FR.md
CHANGED
@@ -19,6 +19,8 @@ Ce framework est conçu pour exécuter des workflows complexes à l'aide d'une o
|
|
19
19
|
- [Gestionnaire de file d'attente](#gestionnaire-de-file-dattente)
|
20
20
|
- [Interpréteur](#interpréteur)
|
21
21
|
- [Système de mémoire](#système-de-mémoire)
|
22
|
+
- [Listeners](#listeners)
|
23
|
+
- [Schedulers](#schedulers)
|
22
24
|
2. [Définir et exécuter des actions](#définir-et-exécuter-des-actions)
|
23
25
|
3. [Gestion de l'état et récursivité](#gestion-de-letat-et-recursivité)
|
24
26
|
4. [Installation et configuration](#installation-et-configuration)
|
@@ -138,6 +140,59 @@ L'architecture mémoire combine une mémoire à court terme et une mémoire à l
|
|
138
140
|
|
139
141
|
---
|
140
142
|
|
143
|
+
### Listeners
|
144
|
+
|
145
|
+
Les **listeners** permettent de se connecter à des événements externes via WebSocket. Ils écoutent les mises à jour en temps réel et déclenchent des actions ou des callbacks spécifiques en réponse aux événements.
|
146
|
+
|
147
|
+
**Caractéristiques principales :**
|
148
|
+
|
149
|
+
- Connexion à des WebSockets pour écouter les événements.
|
150
|
+
- Gestion des abonnements avec des messages personnalisés.
|
151
|
+
- Déclenchement de callbacks pour traiter les données reçues.
|
152
|
+
|
153
|
+
**Exemple d'utilisation :**
|
154
|
+
|
155
|
+
```typescript
|
156
|
+
agent.addListener(
|
157
|
+
"listener-id",
|
158
|
+
"wss://example.com/socket",
|
159
|
+
() => JSON.stringify({ action: "subscribe" }),
|
160
|
+
async (data) => {
|
161
|
+
console.log("Data reçue :", data);
|
162
|
+
}
|
163
|
+
);
|
164
|
+
```
|
165
|
+
|
166
|
+
---
|
167
|
+
|
168
|
+
### Schedulers
|
169
|
+
|
170
|
+
Les **schedulers** permettent de planifier des tâches ou actions pour une exécution ultérieure. Ils utilisent des expressions cron pour définir les intervalles de planification.
|
171
|
+
|
172
|
+
**Caractéristiques principales :**
|
173
|
+
|
174
|
+
- Planification basée sur des expressions cron.
|
175
|
+
- Support des tâches récurrentes et non récurrentes.
|
176
|
+
- Gestion et annulation des tâches planifiées.
|
177
|
+
|
178
|
+
**Exemple d'utilisation :**
|
179
|
+
|
180
|
+
```typescript
|
181
|
+
const scheduler = new TaskScheduler(agentRuntime, redisCache);
|
182
|
+
|
183
|
+
const taskId = await scheduler.scheduleRequest({
|
184
|
+
originalRequest: "Analyse de marché",
|
185
|
+
cronExpression: "0 9 * * *", // Tous les jours à 9h
|
186
|
+
});
|
187
|
+
|
188
|
+
console.log(`Tâche planifiée avec ID : ${taskId}`);
|
189
|
+
|
190
|
+
// Annuler la tâche si nécessaire
|
191
|
+
scheduler.cancelScheduledRequest(taskId);
|
192
|
+
```
|
193
|
+
|
194
|
+
---
|
195
|
+
|
141
196
|
## Définir et exécuter des actions
|
142
197
|
|
143
198
|
### Qu'est-ce qu'une action ?
|
package/README.md
CHANGED
@@ -4,57 +4,59 @@
|
|
4
4
|
|
5
5
|
This framework is designed to execute complex workflows using advanced orchestration, memory management, and actionable intelligence. It integrates tools, interpreters, and memory systems to:
|
6
6
|
|
7
|
-
-
|
7
|
+
- Analyze user inputs in their context.
|
8
8
|
- Execute predefined workflows and dynamic actions.
|
9
9
|
- Efficiently manage short-term and long-term memory.
|
10
|
-
-
|
10
|
+
- Enable seamless integration with external APIs and tools.
|
11
11
|
|
12
12
|
---
|
13
13
|
|
14
|
-
## Table of
|
14
|
+
## Table of Contents
|
15
15
|
|
16
|
-
1. [Architecture
|
17
|
-
- [Agent
|
16
|
+
1. [Architecture Components](#architecture-components)
|
17
|
+
- [Agent Runtime](#agent-runtime)
|
18
18
|
- [Orchestrator](#orchestrator)
|
19
|
-
- [Queue
|
19
|
+
- [Queue Manager](#queue-manager)
|
20
20
|
- [Interpreter](#interpreter)
|
21
|
-
- [Memory
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
- [Memory System](#memory-system)
|
22
|
+
- [Listeners](#listeners)
|
23
|
+
- [Schedulers](#schedulers)
|
24
|
+
2. [Defining and Executing Actions](#defining-and-executing-actions)
|
25
|
+
3. [State Management and Recursion](#state-management-and-recursion)
|
26
|
+
4. [Installation and Configuration](#installation-and-configuration)
|
27
|
+
5. [Usage Example](#usage-example)
|
28
|
+
6. [Work in Progress (WIP)](#work-in-progress-wip)
|
27
29
|
|
28
30
|
---
|
29
31
|
|
30
|
-
## Architecture
|
32
|
+
## Architecture Components
|
31
33
|
|
32
|
-
### Agent
|
34
|
+
### Agent Runtime
|
33
35
|
|
34
|
-
The `AgentRuntime` is the
|
36
|
+
The `AgentRuntime` is the main engine coordinating the overall workflow. It connects all components and ensures tasks are executed efficiently.
|
35
37
|
|
36
38
|
**Responsibilities:**
|
37
39
|
|
38
40
|
- Build context for the current state using memory systems (RAG and CAG).
|
39
|
-
- Orchestrate actions using the
|
41
|
+
- Orchestrate actions using the queue manager.
|
40
42
|
- Leverage interpreters to analyze results and generate responses.
|
41
43
|
|
42
|
-
#### Context
|
44
|
+
#### Context Building
|
43
45
|
|
44
|
-
The `buildContext` method
|
46
|
+
The `buildContext` method creates a complete context by:
|
45
47
|
|
46
48
|
1. Adding tools and user requests.
|
47
|
-
2. Retrieving recent actions
|
49
|
+
2. Retrieving recent actions via cache memory (CAG).
|
48
50
|
3. Fetching relevant knowledge from persistent memory (RAG).
|
49
51
|
4. Including available interpreters for the request.
|
50
52
|
|
51
|
-
#### Processing
|
53
|
+
#### Workflow Processing
|
52
54
|
|
53
55
|
The `process` method:
|
54
56
|
|
55
|
-
1. Generates responses based on
|
57
|
+
1. Generates responses based on context using a language model.
|
56
58
|
2. Handles recursive workflows for action execution.
|
57
|
-
3. Selects appropriate interpreters
|
59
|
+
3. Selects appropriate interpreters to analyze results.
|
58
60
|
|
59
61
|
---
|
60
62
|
|
@@ -62,33 +64,33 @@ The `process` method:
|
|
62
64
|
|
63
65
|
The **orchestrator** directs workflows by analyzing user inputs and planning actions. It interacts with tools, memory systems, and interpreters to ensure logical execution.
|
64
66
|
|
65
|
-
**Key
|
67
|
+
**Key Features:**
|
66
68
|
|
67
|
-
- Dynamic selection
|
68
|
-
-
|
69
|
-
- Multi-step workflow
|
69
|
+
- Dynamic action selection based on context.
|
70
|
+
- Memory interaction management for RAG and CAG operations.
|
71
|
+
- Multi-step workflow management with iterative refinement.
|
70
72
|
|
71
73
|
---
|
72
74
|
|
73
|
-
### Queue
|
75
|
+
### Queue Manager
|
74
76
|
|
75
|
-
The **queue manager**
|
77
|
+
The **queue manager** is responsible for organizing and executing actions in the correct order, whether sequential or parallel. It acts as the central mechanism for managing workflows, ensuring each action is properly queued, validated, and executed.
|
76
78
|
|
77
|
-
**Responsibilities:**
|
79
|
+
**Main Responsibilities:**
|
78
80
|
|
79
|
-
1. **Queueing
|
81
|
+
1. **Action Queueing:**
|
80
82
|
|
81
|
-
- Actions are added to a queue for execution,
|
82
|
-
-
|
83
|
+
- Actions are added to a queue for execution, individually or in batches.
|
84
|
+
- Includes logging support for debugging and traceability.
|
83
85
|
|
84
|
-
2. **Processing
|
86
|
+
2. **Action Processing:**
|
85
87
|
|
86
|
-
- Executes actions
|
87
|
-
-
|
88
|
+
- Executes actions while maintaining correct order.
|
89
|
+
- Respects dependencies between actions.
|
88
90
|
- Handles errors or confirmations via callbacks.
|
89
91
|
|
90
|
-
3. **Confirmation
|
91
|
-
- Supports
|
92
|
+
3. **Confirmation Management:**
|
93
|
+
- Supports prompts for critical actions.
|
92
94
|
- Relies on callbacks to decide whether to proceed with specific actions.
|
93
95
|
|
94
96
|
**Example:**
|
@@ -107,48 +109,101 @@ console.log("Results:", results);
|
|
107
109
|
|
108
110
|
### Interpreter
|
109
111
|
|
110
|
-
The **interpreter** specializes in analyzing results and generating domain-specific insights. Each interpreter is tailored
|
112
|
+
The **interpreter** specializes in analyzing results and generating domain-specific insights. Each interpreter is tailored for a specific use case and uses its own character configuration.
|
111
113
|
|
112
114
|
**Examples:**
|
113
115
|
|
114
116
|
1. **MarketInterpreter**: Analyzes financial market data.
|
115
|
-
2. **SecurityInterpreter**:
|
117
|
+
2. **SecurityInterpreter**: Performs security checks.
|
116
118
|
3. **GeneralInterpreter**: Processes general-purpose requests.
|
117
119
|
|
118
|
-
#### Interpretation
|
120
|
+
#### Interpretation Workflow
|
119
121
|
|
120
122
|
1. Builds context with the current state, including results and user requests.
|
121
123
|
2. Uses the language model to generate actionable insights.
|
122
|
-
3. Provides detailed responses for the
|
124
|
+
3. Provides detailed responses for the end user.
|
123
125
|
|
124
126
|
---
|
125
127
|
|
126
|
-
### Memory
|
128
|
+
### Memory System
|
127
129
|
|
128
130
|
The memory architecture combines short-term and long-term memory to provide contextual processing.
|
129
131
|
|
130
|
-
#### Types
|
132
|
+
#### Memory Types
|
131
133
|
|
132
|
-
1. **Cache
|
133
|
-
- Stores temporary data for
|
134
|
+
1. **Cache Memory (Redis):**
|
135
|
+
- Stores temporary data for quick access.
|
134
136
|
- Examples: Recent actions, session data.
|
135
|
-
2. **Persistent
|
137
|
+
2. **Persistent Memory (Meilisearch):**
|
136
138
|
- Stores long-term data such as historical interactions and knowledge.
|
137
|
-
-
|
139
|
+
- Supports semantic searches and vector-based retrievals.
|
140
|
+
|
141
|
+
---
|
142
|
+
|
143
|
+
### Listeners
|
144
|
+
|
145
|
+
**Listeners** connect to external events via WebSocket. They listen for real-time updates and trigger specific actions or callbacks in response to events.
|
146
|
+
|
147
|
+
**Key Features:**
|
148
|
+
|
149
|
+
- Connect to WebSockets to listen for events.
|
150
|
+
- Manage subscriptions with custom messages.
|
151
|
+
- Trigger callbacks to process received data.
|
152
|
+
|
153
|
+
**Usage Example:**
|
154
|
+
|
155
|
+
```typescript
|
156
|
+
agent.addListener(
|
157
|
+
"listener-id",
|
158
|
+
"wss://example.com/socket",
|
159
|
+
() => JSON.stringify({ action: "subscribe" }),
|
160
|
+
async (data) => {
|
161
|
+
console.log("Received data:", data);
|
162
|
+
}
|
163
|
+
);
|
164
|
+
```
|
165
|
+
|
166
|
+
---
|
167
|
+
|
168
|
+
### Schedulers
|
169
|
+
|
170
|
+
**Schedulers** allow tasks or actions to be scheduled for later execution. They use cron expressions to define scheduling intervals.
|
171
|
+
|
172
|
+
**Key Features:**
|
173
|
+
|
174
|
+
- Cron-based scheduling.
|
175
|
+
- Support for recurring and non-recurring tasks.
|
176
|
+
- Management and cancellation of scheduled tasks.
|
177
|
+
|
178
|
+
**Usage Example:**
|
179
|
+
|
180
|
+
```typescript
|
181
|
+
const scheduler = new TaskScheduler(agentRuntime, redisCache);
|
182
|
+
|
183
|
+
const taskId = await scheduler.scheduleRequest({
|
184
|
+
originalRequest: "Market analysis",
|
185
|
+
cronExpression: "0 9 * * *", // Every day at 9 AM
|
186
|
+
});
|
187
|
+
|
188
|
+
console.log(`Task scheduled with ID: ${taskId}`);
|
189
|
+
|
190
|
+
// Cancel the task if needed
|
191
|
+
scheduler.cancelScheduledRequest(taskId);
|
192
|
+
```
|
138
193
|
|
139
194
|
---
|
140
195
|
|
141
|
-
## Defining and
|
196
|
+
## Defining and Executing Actions
|
142
197
|
|
143
|
-
### What
|
198
|
+
### What is an Action?
|
144
199
|
|
145
|
-
Actions are fundamental tasks executed by the framework. Each action includes:
|
200
|
+
Actions are the fundamental tasks executed by the framework. Each action includes:
|
146
201
|
|
147
202
|
- A unique name and description.
|
148
203
|
- Input parameters validated using schemas.
|
149
204
|
- Execution logic encapsulated in the `execute` method.
|
150
205
|
|
151
|
-
### Example
|
206
|
+
### Action Example
|
152
207
|
|
153
208
|
```typescript
|
154
209
|
import { z } from "zod";
|
@@ -156,7 +211,7 @@ import { parseEther } from "ethers";
|
|
156
211
|
|
157
212
|
export const prepareTransaction = {
|
158
213
|
name: "prepare-transaction",
|
159
|
-
description: "
|
214
|
+
description: "Prepares a token transfer for user approval.",
|
160
215
|
parameters: z.object({
|
161
216
|
walletAddress: z.string(),
|
162
217
|
amount: z.string(),
|
@@ -174,25 +229,25 @@ export const prepareTransaction = {
|
|
174
229
|
|
175
230
|
---
|
176
231
|
|
177
|
-
## State
|
232
|
+
## State Management and Recursion
|
178
233
|
|
179
|
-
The agent manages state and recursive workflows to ensure actions are executed in an orderly manner
|
234
|
+
The agent manages state and recursive workflows to ensure actions are executed in an orderly manner and to completion, while adhering to a maximum number of iterations to avoid infinite loops.
|
180
235
|
|
181
|
-
### State
|
236
|
+
### State Management
|
182
237
|
|
183
238
|
The state (`State`) includes:
|
184
239
|
|
185
|
-
- `currentContext`:
|
186
|
-
- `previousActions`:
|
240
|
+
- `currentContext`: The current context of the user request.
|
241
|
+
- `previousActions`: A list of previously executed actions.
|
187
242
|
|
188
243
|
When an action is completed, the state is updated to include:
|
189
244
|
|
190
|
-
- Results
|
191
|
-
- Remaining context to
|
245
|
+
- Results from previous actions.
|
246
|
+
- Remaining context to be processed.
|
192
247
|
|
193
|
-
### Controlled
|
248
|
+
### Controlled Recursion
|
194
249
|
|
195
|
-
To prevent infinite loops, the system limits the number of iterations
|
250
|
+
To prevent infinite loops, the system limits the number of iterations via the `maxIterations` configuration.
|
196
251
|
|
197
252
|
**Workflow:**
|
198
253
|
|
@@ -201,14 +256,14 @@ To prevent infinite loops, the system limits the number of iterations using the
|
|
201
256
|
- Executes actions in the queue.
|
202
257
|
- Updates the state with new results.
|
203
258
|
|
204
|
-
2. **Limit
|
259
|
+
2. **Limit Validation:**
|
205
260
|
|
206
|
-
- If the
|
261
|
+
- If the number of iterations exceeds `maxIterations`, processing is stopped with a "Max iterations reached" message.
|
207
262
|
|
208
263
|
3. **Recursion:**
|
209
264
|
- If actions remain to be executed, the agent recursively calls the `process` method with the updated state.
|
210
265
|
|
211
|
-
**Example:**
|
266
|
+
**State and Recursion Example:**
|
212
267
|
|
213
268
|
```typescript
|
214
269
|
const updatedNextState: State = {
|
@@ -227,23 +282,23 @@ if (countIterations < this.config.maxIterations) {
|
|
227
282
|
|
228
283
|
---
|
229
284
|
|
230
|
-
## Installation and
|
285
|
+
## Installation and Configuration
|
231
286
|
|
232
|
-
### Install
|
287
|
+
### Install Dependencies
|
233
288
|
|
234
289
|
```bash
|
235
290
|
npm install
|
236
291
|
```
|
237
292
|
|
238
|
-
### Configure
|
293
|
+
### Configure External Services
|
239
294
|
|
240
|
-
#### Redis (
|
295
|
+
#### Redis (Cache Memory)
|
241
296
|
|
242
297
|
```bash
|
243
298
|
docker run --name redis -d -p 6379:6379 redis
|
244
299
|
```
|
245
300
|
|
246
|
-
#### Meilisearch (
|
301
|
+
#### Meilisearch (Persistent Memory)
|
247
302
|
|
248
303
|
```bash
|
249
304
|
curl -L https://install.meilisearch.com | sh
|
@@ -252,9 +307,9 @@ curl -L https://install.meilisearch.com | sh
|
|
252
307
|
|
253
308
|
---
|
254
309
|
|
255
|
-
## Example
|
310
|
+
## Usage Example
|
256
311
|
|
257
|
-
### Initialize the
|
312
|
+
### Initialize the Agent
|
258
313
|
|
259
314
|
```typescript
|
260
315
|
import { deepseek } from "@ai-ntellect/core";
|
@@ -297,7 +352,7 @@ const agent = new Agent({
|
|
297
352
|
});
|
298
353
|
```
|
299
354
|
|
300
|
-
### Process a
|
355
|
+
### Process a Request
|
301
356
|
|
302
357
|
```typescript
|
303
358
|
const state = {
|
package/agent/index.ts
CHANGED
@@ -10,12 +10,13 @@ import { ActionQueueManager } from "../services/queue";
|
|
10
10
|
import { CacheConfig, RedisCache } from "../services/redis-cache";
|
11
11
|
import { ActionData, ActionSchema, QueueCallbacks } from "../types";
|
12
12
|
import { QueueItemTransformer } from "../utils/queue-item-transformer";
|
13
|
+
|
13
14
|
export class Agent {
|
14
15
|
private readonly agent: AgentRuntime;
|
15
16
|
private readonly memoryManager: MemoryManager;
|
16
17
|
private readonly cache: RedisCache;
|
17
18
|
|
18
|
-
private
|
19
|
+
private listeners: Map<
|
19
20
|
string,
|
20
21
|
{ socket: WebSocket; callback: (data: any) => Promise<void> }
|
21
22
|
> = new Map();
|
@@ -195,7 +196,7 @@ export class Agent {
|
|
195
196
|
subscriptionMessageFactory: () => string,
|
196
197
|
callback: (data: any, agentContext: Agent) => Promise<void>
|
197
198
|
): void {
|
198
|
-
if (this.
|
199
|
+
if (this.listeners.has(id)) {
|
199
200
|
console.warn(`WebSocket with ID ${id} already exists.`);
|
200
201
|
return;
|
201
202
|
}
|
@@ -238,6 +239,6 @@ export class Agent {
|
|
238
239
|
console.log(`🔌 WebSocket closed for ID: ${id}`);
|
239
240
|
});
|
240
241
|
|
241
|
-
this.
|
242
|
+
this.listeners.set(id, { socket, callback: wrappedCallback });
|
242
243
|
}
|
243
244
|
}
|
package/dist/agent/index.d.ts
CHANGED
package/dist/agent/index.js
CHANGED
@@ -12,7 +12,7 @@ const redis_cache_1 = require("../services/redis-cache");
|
|
12
12
|
const queue_item_transformer_1 = require("../utils/queue-item-transformer");
|
13
13
|
class Agent {
|
14
14
|
constructor(config) {
|
15
|
-
this.
|
15
|
+
this.listeners = new Map();
|
16
16
|
this.cache = new redis_cache_1.RedisCache(config.cache);
|
17
17
|
this.config = config;
|
18
18
|
this.agent = new orchestrator_1.AgentRuntime(config.orchestrator.model, config.orchestrator.tools, config.interpreters, config.cache, config.orchestrator.memory);
|
@@ -104,7 +104,7 @@ class Agent {
|
|
104
104
|
return interpreters.find((interpreter) => interpreter.name === name);
|
105
105
|
}
|
106
106
|
addListener(id, url, subscriptionMessageFactory, callback) {
|
107
|
-
if (this.
|
107
|
+
if (this.listeners.has(id)) {
|
108
108
|
console.warn(`WebSocket with ID ${id} already exists.`);
|
109
109
|
return;
|
110
110
|
}
|
@@ -137,7 +137,7 @@ class Agent {
|
|
137
137
|
socket.on("close", () => {
|
138
138
|
console.log(`🔌 WebSocket closed for ID: ${id}`);
|
139
139
|
});
|
140
|
-
this.
|
140
|
+
this.listeners.set(id, { socket, callback: wrappedCallback });
|
141
141
|
}
|
142
142
|
}
|
143
143
|
exports.Agent = Agent;
|