@ai.ntellect/core 0.6.20 → 0.6.21
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.md +110 -147
- package/dist/graph/controller.js +10 -13
- package/dist/graph/index.js +184 -85
- package/dist/index.js +1 -1
- package/dist/modules/embedding/index.js +5 -5
- package/dist/utils/generate-action-schema.js +7 -6
- package/graph/index.ts +13 -31
- package/modules/embedding/index.ts +3 -3
- package/package.json +3 -16
- package/test/graph/index.test.ts +105 -94
- package/utils/generate-action-schema.ts +8 -7
- package/.env.example +0 -2
- package/graph.ts +0 -74
package/README.md
CHANGED
@@ -1,192 +1,155 @@
|
|
1
|
-
#
|
1
|
+
# @ai.ntellect/core
|
2
2
|
|
3
|
-
|
3
|
+
@ai.ntellect/core is a modular and event-driven framework designed to orchestrate and execute intelligent workflows using execution graphs. It enables automation of complex tasks, seamless integration with external services, and the creation of AI-driven agents in a flexible and scalable way.
|
4
4
|
|
5
|
-
|
5
|
+
## Key features
|
6
6
|
|
7
|
-
|
7
|
+
- **GraphFlow** – A graph-based execution engine for automating business processes.
|
8
|
+
- **Event-Driven** – Nodes can react to real-time events and trigger actions dynamically.
|
9
|
+
- **Modular** – Plug-and-play modules and adapters for memory, scheduling, and external APIs.
|
10
|
+
- **Extensible** – Custom nodes, adapters, and interactions with third-party services.
|
11
|
+
- **Scalable** – Manage multiple graphs in parallel with GraphController.
|
8
12
|
|
9
|
-
|
10
|
-
- Cyclic and acyclic graph support
|
11
|
-
- Strong typing with Zod validation
|
12
|
-
- Event-driven architecture
|
13
|
-
- Built-in error handling and retries
|
14
|
-
- Conditional execution paths
|
15
|
-
- Parameter validation
|
16
|
-
- State management
|
13
|
+
## Installation
|
17
14
|
|
18
|
-
###
|
15
|
+
### Prerequisites
|
19
16
|
|
20
|
-
-
|
21
|
-
-
|
22
|
-
-
|
23
|
-
- **Decision Trees**: Implementing complex business logic with multiple branches
|
24
|
-
- **State Machines**: Managing application state transitions
|
25
|
-
- **Event Processing**: Handling and responding to system events
|
17
|
+
- Node.js (LTS version recommended)
|
18
|
+
- TypeScript
|
19
|
+
- Zod (for data validation)
|
26
20
|
|
27
|
-
|
21
|
+
Verify your installation:
|
28
22
|
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
```sh
|
24
|
+
node -v
|
25
|
+
npm -v
|
26
|
+
```
|
32
27
|
|
33
|
-
|
34
|
-
- **E**: Set of directed edges
|
28
|
+
If Node.js is not installed, download it from [nodejs.org](https://nodejs.org/).
|
35
29
|
|
36
|
-
|
30
|
+
### Installing the framework
|
37
31
|
|
38
|
-
|
32
|
+
Create a new Node.js project:
|
39
33
|
|
34
|
+
```sh
|
35
|
+
mkdir ai-ntellect-demo
|
36
|
+
cd ai-ntellect-demo
|
37
|
+
npm init -y
|
40
38
|
```
|
41
|
-
(ValidateInput) → (ProcessData) → (SaveResult)
|
42
|
-
↓ ↑
|
43
|
-
(RetryInput) ──────────────────────
|
44
|
-
```
|
45
|
-
|
46
|
-
### **2.2 Node Types**
|
47
39
|
|
48
|
-
|
40
|
+
Install TypeScript and Node.js types:
|
49
41
|
|
50
|
-
```
|
51
|
-
|
52
|
-
|
53
|
-
execute: async (context) => {
|
54
|
-
// Process data
|
55
|
-
},
|
56
|
-
next: ["saveResult"],
|
57
|
-
};
|
42
|
+
```sh
|
43
|
+
npm install --save-dev typescript @types/node
|
44
|
+
npx tsc --init
|
58
45
|
```
|
59
46
|
|
60
|
-
|
61
|
-
|
62
|
-
```typescript
|
63
|
-
const conditionalNode: Node<ContextType> = {
|
64
|
-
name: "validateInput",
|
65
|
-
condition: (context) => context.isValid,
|
66
|
-
execute: async (context) => {
|
67
|
-
// Validation logic
|
68
|
-
},
|
69
|
-
next: ["processData"],
|
70
|
-
};
|
71
|
-
```
|
47
|
+
Install @ai.ntellect/core and its dependencies:
|
72
48
|
|
73
|
-
|
49
|
+
```sh
|
50
|
+
npm install @ai.ntellect/core zod
|
51
|
+
```
|
74
52
|
|
75
|
-
|
53
|
+
## Verifying the Installation
|
76
54
|
|
77
|
-
|
55
|
+
Create a new file `index.ts`:
|
78
56
|
|
79
|
-
```
|
80
|
-
|
81
|
-
name: "handleUserInput",
|
82
|
-
events: ["userSubmitted"],
|
83
|
-
execute: async (context) => {
|
84
|
-
// Handle user input
|
85
|
-
},
|
86
|
-
};
|
57
|
+
```sh
|
58
|
+
touch index.ts
|
87
59
|
```
|
88
60
|
|
89
|
-
|
90
|
-
|
91
|
-
Built-in retry support for handling transient failures:
|
92
|
-
|
93
|
-
```typescript
|
94
|
-
const retryableNode: Node<ContextType> = {
|
95
|
-
name: "apiCall",
|
96
|
-
retry: {
|
97
|
-
maxAttempts: 3,
|
98
|
-
delay: 1000, // ms
|
99
|
-
},
|
100
|
-
execute: async (context) => {
|
101
|
-
// API call logic
|
102
|
-
},
|
103
|
-
};
|
104
|
-
```
|
61
|
+
Add the following code to test a simple graph execution:
|
105
62
|
|
106
|
-
|
63
|
+
```ts
|
64
|
+
import { GraphFlow } from "@ai.ntellect/core";
|
65
|
+
import { z } from "zod";
|
107
66
|
|
108
|
-
|
109
|
-
|
110
|
-
```typescript
|
111
|
-
const aiAgentGraph = new Graph<AIContextType>("AIAgent", {
|
112
|
-
nodes: [
|
113
|
-
{
|
114
|
-
name: "analyzeInput",
|
115
|
-
execute: async (context) => {
|
116
|
-
context.intent = await analyzeUserIntent(context.input);
|
117
|
-
},
|
118
|
-
next: ["selectAction"],
|
119
|
-
},
|
120
|
-
{
|
121
|
-
name: "selectAction",
|
122
|
-
execute: async (context) => {
|
123
|
-
context.selectedAction = determineNextAction(context.intent);
|
124
|
-
},
|
125
|
-
next: ["validateResponse"],
|
126
|
-
},
|
127
|
-
{
|
128
|
-
name: "generateResponse",
|
129
|
-
execute: async (context) => {
|
130
|
-
context.response = await generateAIResponse(context);
|
131
|
-
},
|
132
|
-
next: ["validateResponse"],
|
133
|
-
},
|
134
|
-
],
|
67
|
+
const ContextSchema = z.object({
|
68
|
+
message: z.string(),
|
135
69
|
});
|
136
|
-
```
|
137
70
|
|
138
|
-
|
71
|
+
type ContextSchema = typeof ContextSchema;
|
139
72
|
|
140
|
-
|
141
|
-
|
73
|
+
const myGraph = new GraphFlow<ContextSchema>("TestGraph", {
|
74
|
+
name: "TestGraph",
|
75
|
+
context: { message: "Installation successful!" },
|
76
|
+
schema: ContextSchema,
|
142
77
|
nodes: [
|
143
78
|
{
|
144
|
-
name: "
|
79
|
+
name: "printMessage",
|
145
80
|
execute: async (context) => {
|
146
|
-
|
81
|
+
console.log(context.message);
|
147
82
|
},
|
148
|
-
next: [
|
149
|
-
},
|
150
|
-
{
|
151
|
-
name: "processPayment",
|
152
|
-
retry: {
|
153
|
-
maxAttempts: 3,
|
154
|
-
delay: 1000,
|
155
|
-
},
|
156
|
-
condition: (context) => context.hasSufficientFunds,
|
157
|
-
execute: async (context) => {
|
158
|
-
await processPayment(context.transactionData);
|
159
|
-
},
|
160
|
-
next: ["notifyUser"],
|
83
|
+
next: [],
|
161
84
|
},
|
162
85
|
],
|
163
86
|
});
|
87
|
+
|
88
|
+
(async () => {
|
89
|
+
await myGraph.execute("printMessage");
|
90
|
+
})();
|
164
91
|
```
|
165
92
|
|
166
|
-
|
93
|
+
Run the test:
|
167
94
|
|
168
|
-
```
|
169
|
-
|
170
|
-
|
171
|
-
});
|
95
|
+
```sh
|
96
|
+
npx ts-node index.ts
|
97
|
+
```
|
172
98
|
|
173
|
-
|
174
|
-
console.log(`Node ${name} completed with context:`, context);
|
175
|
-
});
|
99
|
+
Expected output:
|
176
100
|
|
177
|
-
graph.on("nodeError", ({ name, error }) => {
|
178
|
-
console.error(`Error in node ${name}:`, error);
|
179
|
-
});
|
180
101
|
```
|
102
|
+
Installation successful!
|
103
|
+
```
|
104
|
+
|
105
|
+
## Core concepts
|
106
|
+
|
107
|
+
### GraphFlow
|
108
|
+
|
109
|
+
GraphFlow is the core execution engine that automates workflows through graph-based logic. Each node in the graph can:
|
110
|
+
|
111
|
+
- Execute a specific action.
|
112
|
+
- Wait for an event before proceeding.
|
113
|
+
- Depend on conditional logic.
|
114
|
+
- Modify a shared execution context.
|
115
|
+
|
116
|
+
### GraphController
|
117
|
+
|
118
|
+
GraphController orchestrates multiple GraphFlows, enabling:
|
119
|
+
|
120
|
+
- Sequential or parallel execution of multiple graphs.
|
121
|
+
- Inter-graph communication for complex workflows.
|
122
|
+
- Advanced event-based automation.
|
123
|
+
|
124
|
+
### Modules and Adapters
|
125
|
+
|
126
|
+
The framework provides modular extensions:
|
127
|
+
|
128
|
+
- **Memory Module** – Stores and retrieves contextual information.
|
129
|
+
- **Scheduler (Agenda)** – Manages task scheduling and timed executions.
|
130
|
+
- **Adapters** – Integrate with databases, APIs, and external services.
|
131
|
+
|
132
|
+
## Tutorials
|
133
|
+
|
134
|
+
Step-by-step guides are available for:
|
135
|
+
|
136
|
+
- Creating a simple graph
|
137
|
+
- Adding conditions and handling errors
|
138
|
+
- Waiting for events and executing multiple graphs
|
139
|
+
- Building an AI-powered agent with @ai.ntellect/core
|
140
|
+
|
141
|
+
Check out the complete documentation at [GitBook](https://ai-ntellect.gitbook.io/core).
|
142
|
+
|
143
|
+
## Contributing
|
181
144
|
|
182
|
-
|
145
|
+
Contributions are welcome. To suggest an improvement or report an issue:
|
183
146
|
|
184
|
-
|
147
|
+
- Join our [Discord community](https://discord.gg/kEc5gWXJ)
|
148
|
+
- Explore the [GitBook documentation](https://ai-ntellect.gitbook.io/core)
|
149
|
+
- Open an issue on GitHub
|
185
150
|
|
186
|
-
|
187
|
-
- Graph composition and nesting
|
188
|
-
- Real-time monitoring dashboard
|
189
|
-
- Performance analytics
|
190
|
-
- Distributed execution support
|
151
|
+
## Useful links
|
191
152
|
|
192
|
-
|
153
|
+
- Documentation: [GitBook](https://ai-ntellect.gitbook.io/core)
|
154
|
+
- Community: [Discord](https://discord.gg/kEc5gWXJ)
|
155
|
+
- GitHub Repository: [@ai.ntellect/core](https://github.com/ai-ntellect/core)
|
package/dist/graph/controller.js
CHANGED
@@ -23,14 +23,14 @@ class GraphController {
|
|
23
23
|
* @returns Map containing results of each graph execution, keyed by graph name and index
|
24
24
|
* @template T - Zod schema type for graph context validation
|
25
25
|
*/
|
26
|
-
static executeSequential(graphs, startNodes,
|
26
|
+
static executeSequential(graphs, startNodes, inputs) {
|
27
27
|
return __awaiter(this, void 0, void 0, function* () {
|
28
28
|
const results = new Map();
|
29
29
|
for (let i = 0; i < graphs.length; i++) {
|
30
|
-
const result = yield graphs[i].execute(startNodes[i],
|
30
|
+
const result = yield graphs[i].execute(startNodes[i], inputs[i]);
|
31
31
|
results.set(`${graphs[i].name}-${i}`, result);
|
32
32
|
}
|
33
|
-
return results;
|
33
|
+
return Array.from(results.values());
|
34
34
|
});
|
35
35
|
}
|
36
36
|
/**
|
@@ -43,32 +43,29 @@ class GraphController {
|
|
43
43
|
* @returns Map containing results of each graph execution, keyed by graph name
|
44
44
|
* @template T - Zod schema type for graph context validation
|
45
45
|
*/
|
46
|
-
static executeParallel(graphs, startNodes,
|
46
|
+
static executeParallel(graphs, startNodes, concurrency, inputs) {
|
47
47
|
return __awaiter(this, void 0, void 0, function* () {
|
48
48
|
const results = new Map();
|
49
|
-
if (inputContexts) {
|
50
|
-
inputContexts = inputContexts.map((ctx) => ctx || {});
|
51
|
-
}
|
52
49
|
if (inputs) {
|
53
50
|
inputs = inputs.map((input) => input || {});
|
54
51
|
}
|
55
|
-
if (
|
56
|
-
for (let i = 0; i < graphs.length; i +=
|
52
|
+
if (concurrency) {
|
53
|
+
for (let i = 0; i < graphs.length; i += concurrency) {
|
57
54
|
const batchResults = yield Promise.all(graphs
|
58
|
-
.slice(i, i +
|
59
|
-
.map((graph, index) => graph.execute(startNodes[i + index],
|
55
|
+
.slice(i, i + concurrency)
|
56
|
+
.map((graph, index) => graph.execute(startNodes[i + index], inputs === null || inputs === void 0 ? void 0 : inputs[i + index])));
|
60
57
|
batchResults.forEach((result, index) => {
|
61
58
|
results.set(`${graphs[i + index].name}`, result);
|
62
59
|
});
|
63
60
|
}
|
64
61
|
}
|
65
62
|
else {
|
66
|
-
const allResults = yield Promise.all(graphs.map((graph, index) => graph.execute(startNodes[index], (
|
63
|
+
const allResults = yield Promise.all(graphs.map((graph, index) => graph.execute(startNodes[index], (inputs === null || inputs === void 0 ? void 0 : inputs[index]) || {})));
|
67
64
|
allResults.forEach((result, index) => {
|
68
65
|
results.set(`${graphs[index].name}`, result);
|
69
66
|
});
|
70
67
|
}
|
71
|
-
return results;
|
68
|
+
return Array.from(results.values());
|
72
69
|
});
|
73
70
|
}
|
74
71
|
}
|