@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 CHANGED
@@ -1,192 +1,155 @@
1
- # **@ai.ntellect/core Documentation**
1
+ # @ai.ntellect/core
2
2
 
3
- ## **1. Introduction**
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
- The **`@ai.ntellect/core`** framework is a powerful tool designed to **model, execute, and manage dynamic interaction flows** using **graph structures**. Unlike traditional **Directed Acyclic Graphs (DAGs)**, this framework supports cycles, enabling nodes to be executed multiple times and allowing for loop-based workflows.
5
+ ## Key features
6
6
 
7
- ### **Key Features**
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
- - Dynamic workflow execution
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
- ### **Common Use Cases**
15
+ ### Prerequisites
19
16
 
20
- - **AI Agents**: Building conversational AI systems that can maintain context and make decisions
21
- - **Transaction Processing**: Managing complex financial workflows with validation chains
22
- - **Task Orchestration**: Coordinating multiple dependent operations
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
- ## **2. Core Concepts**
21
+ Verify your installation:
28
22
 
29
- ### **2.1 Graph Theory Foundation**
30
-
31
- A directed graph in our framework is defined as **G = (V, E)** where:
23
+ ```sh
24
+ node -v
25
+ npm -v
26
+ ```
32
27
 
33
- - **V**: Set of nodes (vertices)
34
- - **E**: Set of directed edges
28
+ If Node.js is not installed, download it from [nodejs.org](https://nodejs.org/).
35
29
 
36
- Each node represents an executable action, and edges represent conditional transitions between actions.
30
+ ### Installing the framework
37
31
 
38
- #### Example Graph Structure:
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
- #### **Basic Node**
40
+ Install TypeScript and Node.js types:
49
41
 
50
- ```typescript
51
- const basicNode: Node<ContextType> = {
52
- name: "processData",
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
- #### **Conditional Node**
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
- ## **3. Advanced Features**
49
+ ```sh
50
+ npm install @ai.ntellect/core zod
51
+ ```
74
52
 
75
- ### **3.1 Event-Driven Execution**
53
+ ## Verifying the Installation
76
54
 
77
- Nodes can respond to system events:
55
+ Create a new file `index.ts`:
78
56
 
79
- ```typescript
80
- const eventNode: Node<ContextType> = {
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
- ### **3.2 Retry Mechanisms**
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
- ## **4. Real-World Examples**
63
+ ```ts
64
+ import { GraphFlow } from "@ai.ntellect/core";
65
+ import { z } from "zod";
107
66
 
108
- ### **4.1 AI Agent Workflow**
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
- ### **4.2 Transaction Processing**
71
+ type ContextSchema = typeof ContextSchema;
139
72
 
140
- ```typescript
141
- const transactionGraph = new Graph<TransactionContext>("TransactionProcessor", {
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: "validateFunds",
79
+ name: "printMessage",
145
80
  execute: async (context) => {
146
- context.hasSufficientFunds = await checkBalance(context.amount);
81
+ console.log(context.message);
147
82
  },
148
- next: ["processPayment"],
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
- ## **5. Event Listeners**
93
+ Run the test:
167
94
 
168
- ```typescript
169
- graph.on("nodeStarted", ({ name, context }) => {
170
- console.log(`Node ${name} started with context:`, context);
171
- });
95
+ ```sh
96
+ npx ts-node index.ts
97
+ ```
172
98
 
173
- graph.on("nodeCompleted", ({ name, context }) => {
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
- ## **6. Future Developments**
145
+ Contributions are welcome. To suggest an improvement or report an issue:
183
146
 
184
- Planned features include:
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
- - Advanced memory management for AI agents
187
- - Graph composition and nesting
188
- - Real-time monitoring dashboard
189
- - Performance analytics
190
- - Distributed execution support
151
+ ## Useful links
191
152
 
192
- For more information and updates, visit the official documentation or join our community discussions.
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)
@@ -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, inputContexts) {
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], inputContexts === null || inputContexts === void 0 ? void 0 : inputContexts[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, inputContexts, inputs, concurrencyLimit) {
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 (concurrencyLimit) {
56
- for (let i = 0; i < graphs.length; i += concurrencyLimit) {
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 + concurrencyLimit)
59
- .map((graph, index) => graph.execute(startNodes[i + index], (inputContexts === null || inputContexts === void 0 ? void 0 : inputContexts[i + index]) || {}, inputs === null || inputs === void 0 ? void 0 : inputs[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], (inputContexts === null || inputContexts === void 0 ? void 0 : inputContexts[index]) || {}, (inputs === null || inputs === void 0 ? void 0 : inputs[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
  }