@ai.ntellect/core 0.5.0 → 0.6.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/.mocharc.json +1 -1
- package/README.md +311 -272
- package/dist/graph/controller.js +63 -0
- package/dist/graph/engine.js +563 -0
- package/dist/index.js +6 -6
- package/dist/memory/adapters/meilisearch/index.js +249 -0
- package/dist/memory/adapters/redis/index.js +96 -0
- package/dist/memory/index.js +9 -0
- package/dist/services/agenda.js +115 -0
- package/dist/services/embedding.js +40 -0
- package/dist/services/queue.js +99 -103
- package/dist/test/graph/controller.test.js +170 -0
- package/dist/test/graph/engine.test.js +465 -0
- package/dist/test/memory/adapters/meilisearch.test.js +250 -0
- package/dist/test/memory/adapters/redis.test.js +143 -0
- package/dist/test/memory/base.test.js +209 -0
- package/dist/test/services/agenda.test.js +230 -0
- package/dist/test/services/queue.test.js +258 -0
- package/dist/types/index.js +2 -0
- package/dist/utils/generate-object.js +32 -11
- package/dist/utils/inject-actions.js +2 -2
- package/dist/utils/queue-item-transformer.js +2 -2
- package/dist/utils/state-manager.js +20 -0
- package/graph/controller.ts +60 -0
- package/{services/workflow.ts → graph/engine.ts} +331 -113
- package/index.ts +7 -7
- package/interfaces/index.ts +119 -0
- package/memory/adapters/meilisearch/index.ts +286 -0
- package/memory/adapters/redis/index.ts +103 -0
- package/memory/index.ts +22 -0
- package/package.json +7 -2
- package/services/agenda.ts +48 -43
- package/services/embedding.ts +26 -0
- package/services/queue.ts +2 -29
- package/test/.env.test +4 -0
- package/test/graph/controller.test.ts +186 -0
- package/test/graph/engine.test.ts +563 -0
- package/test/memory/adapters/meilisearch.test.ts +297 -0
- package/test/memory/adapters/redis.test.ts +160 -0
- package/test/memory/base.test.ts +229 -0
- package/test/services/agenda.test.ts +280 -0
- package/test/services/queue.test.ts +286 -44
- package/tsconfig.json +10 -10
- package/types/index.ts +270 -0
- package/utils/generate-object.js +111 -0
- package/utils/header-builder.js +34 -0
- package/utils/inject-actions.js +16 -0
- package/utils/queue-item-transformer.js +24 -0
- package/utils/queue-item-transformer.ts +8 -11
- package/utils/sanitize-results.js +60 -0
- package/utils/schema-generator.js +46 -0
- package/utils/state-manager.js +20 -0
- package/utils/state-manager.ts +17 -12
- package/.nvmrc +0 -1
- package/README.FR.md +0 -916
- package/agent/index.ts +0 -151
- package/agent/workflow/conditions.ts +0 -16
- package/agent/workflow/handlers/interpreter.handler.ts +0 -48
- package/agent/workflow/handlers/memory.handler.ts +0 -106
- package/agent/workflow/handlers/orchestrator.handler.ts +0 -23
- package/agent/workflow/handlers/queue.handler.ts +0 -34
- package/agent/workflow/handlers/scheduler.handler.ts +0 -61
- package/agent/workflow/index.ts +0 -62
- package/dist/agent/index.d.ts +0 -38
- package/dist/agent/index.js +0 -143
- package/dist/agent/tools/get-rss.d.ts +0 -16
- package/dist/agent/tools/get-rss.js +0 -62
- package/dist/bull.d.ts +0 -1
- package/dist/bull.js +0 -9
- package/dist/examples/index.d.ts +0 -2
- package/dist/examples/index.js +0 -89
- package/dist/index.d.ts +0 -7
- package/dist/llm/interpreter/context.d.ts +0 -15
- package/dist/llm/interpreter/context.js +0 -89
- package/dist/llm/interpreter/index.d.ts +0 -21
- package/dist/llm/interpreter/index.js +0 -87
- package/dist/llm/memory-manager/context.d.ts +0 -2
- package/dist/llm/memory-manager/context.js +0 -22
- package/dist/llm/memory-manager/index.d.ts +0 -17
- package/dist/llm/memory-manager/index.js +0 -107
- package/dist/llm/orchestrator/context.d.ts +0 -2
- package/dist/llm/orchestrator/context.js +0 -23
- package/dist/llm/orchestrator/index.d.ts +0 -44
- package/dist/llm/orchestrator/index.js +0 -139
- package/dist/llm/orchestrator/types.d.ts +0 -12
- package/dist/memory/cache.d.ts +0 -22
- package/dist/memory/cache.js +0 -165
- package/dist/memory/persistent.d.ts +0 -57
- package/dist/memory/persistent.js +0 -189
- package/dist/services/queue.d.ts +0 -13
- package/dist/services/redis-cache.d.ts +0 -37
- package/dist/services/redis-cache.js +0 -93
- package/dist/services/scheduler.d.ts +0 -40
- package/dist/services/scheduler.js +0 -99
- package/dist/services/telegram-monitor.d.ts +0 -0
- package/dist/services/telegram-monitor.js +0 -118
- package/dist/t.d.ts +0 -46
- package/dist/t.js +0 -102
- package/dist/test.d.ts +0 -0
- package/dist/test.js +0 -438
- package/dist/types.d.ts +0 -258
- package/dist/types.js +0 -22
- package/dist/utils/generate-object.d.ts +0 -12
- package/dist/utils/header-builder.d.ts +0 -11
- package/dist/utils/inject-actions.d.ts +0 -2
- package/dist/utils/queue-item-transformer.d.ts +0 -7
- package/dist/utils/sanitize-results.d.ts +0 -17
- package/dist/utils/schema-generator.d.ts +0 -16
- package/examples/actions/get-rss.ts +0 -71
- package/examples/index.ts +0 -98
- package/index.html +0 -42
- package/llm/dynamic-condition/example.ts +0 -36
- package/llm/dynamic-condition/index.ts +0 -108
- package/llm/interpreter/context.ts +0 -94
- package/llm/interpreter/index.ts +0 -140
- package/llm/memory-manager/context.ts +0 -19
- package/llm/memory-manager/index.ts +0 -115
- package/llm/orchestrator/context.ts +0 -19
- package/llm/orchestrator/index.ts +0 -192
- package/llm/orchestrator/types.ts +0 -14
- package/memory/cache.ts +0 -221
- package/memory/persistent.ts +0 -265
- package/script.js +0 -167
- package/services/cache.ts +0 -298
- package/services/telegram-monitor.ts +0 -138
- package/t.py +0 -79
- package/t.ts +0 -25
- package/test/llm/orchestrator.test.ts +0 -47
- package/test/llm/synthesizer.test.ts +0 -31
- package/types.ts +0 -367
- /package/dist/{llm/orchestrator/types.js → interfaces/index.js} +0 -0
package/README.md
CHANGED
@@ -1,365 +1,404 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
## Overview
|
4
|
-
|
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
|
-
|
7
|
-
- Analyze user inputs in their context.
|
8
|
-
- Execute predefined workflows and dynamic actions.
|
9
|
-
- Efficiently manage short-term and long-term memory.
|
10
|
-
- Enable seamless integration with external APIs and tools.
|
1
|
+
# @ai.ntellect/core
|
11
2
|
|
12
3
|
---
|
13
4
|
|
14
|
-
##
|
15
|
-
|
16
|
-
1. [Architecture Components](#architecture-components)
|
17
|
-
- [Agent Runtime](#agent-runtime)
|
18
|
-
- [Orchestrator](#orchestrator)
|
19
|
-
- [Queue Manager](#queue-manager)
|
20
|
-
- [Interpreter](#interpreter)
|
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)
|
5
|
+
## Introduction
|
29
6
|
|
30
|
-
|
7
|
+
**@ai.ntellect/core** is a highly extensible, graph-based workflow framework designed to tackle complex automation scenarios, pipelines, AI-driven agent flows, and even blockchain process orchestration. By modeling your processes as **Graphs** composed of **Nodes**, you can intuitively define both sequential and parallel task execution. The framework provides robust features including:
|
31
8
|
|
32
|
-
|
9
|
+
- **Dynamic state management** with optional schema validation
|
10
|
+
- **Parallel and conditional branching** execution
|
11
|
+
- **Controller-based orchestration** of multiple workflows
|
12
|
+
- **Subgraph** delegation for modular design
|
13
|
+
- **Memory management** for agents and chatbots (e.g., storing user context or embeddings)
|
14
|
+
- **Integration** with real-time notifiers and persistence layers
|
33
15
|
|
34
|
-
|
16
|
+
Whether you’re building a data pipeline, an AI-driven bot, or an automated blockchain process, @ai.ntellect/core offers a concise yet powerful suite of tooling to handle the complexity of stateful, event-driven orchestration.
|
35
17
|
|
36
|
-
|
18
|
+
---
|
37
19
|
|
38
|
-
|
20
|
+
## Installation
|
39
21
|
|
40
|
-
|
41
|
-
- Orchestrate actions using the queue manager.
|
42
|
-
- Leverage interpreters to analyze results and generate responses.
|
22
|
+
### Prerequisites
|
43
23
|
|
44
|
-
|
24
|
+
- **Node.js** (14.x or higher recommended)
|
25
|
+
- A package manager such as **npm** or **yarn**
|
45
26
|
|
46
|
-
|
27
|
+
### Installing the package
|
47
28
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
4. Including available interpreters for the request.
|
29
|
+
```bash
|
30
|
+
npm install @ai.ntellect/core
|
31
|
+
```
|
52
32
|
|
53
|
-
|
33
|
+
Or using Yarn:
|
54
34
|
|
55
|
-
|
35
|
+
```bash
|
36
|
+
yarn add @ai.ntellect/core
|
37
|
+
```
|
56
38
|
|
57
|
-
|
58
|
-
2. Handles recursive workflows for action execution.
|
59
|
-
3. Selects appropriate interpreters to analyze results.
|
39
|
+
Or using pnpm:
|
60
40
|
|
61
|
-
|
41
|
+
```bash
|
42
|
+
pnpm add @ai.ntellect/core
|
43
|
+
```
|
62
44
|
|
63
|
-
###
|
45
|
+
### Initial configuration
|
64
46
|
|
65
|
-
|
47
|
+
- **Import the necessary classes**:
|
66
48
|
|
67
|
-
|
49
|
+
```ts
|
50
|
+
import { GraphEngine, GraphController } from "@ai.ntellect/core";
|
51
|
+
```
|
68
52
|
|
69
|
-
-
|
70
|
-
-
|
71
|
-
- Multi-step workflow management with iterative refinement.
|
53
|
+
- **(Optional) Define your state schema** using a validation library like [Zod](https://zod.dev) to ensure your data remains consistent throughout workflow execution.
|
54
|
+
- **Configure** advanced features (e.g., persistence, notifications, memory services) before running your workflows.
|
72
55
|
|
73
56
|
---
|
74
57
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
58
|
+
## Core concepts
|
59
|
+
|
60
|
+
@ai.ntellect/core revolves around the idea of **Graphs** and **Nodes**. On top of these concepts, the framework provides a powerful **Engine**, a high-level **Controller**, and optional **Memory** management for specialized use cases (like AI agents). This section explores each concept in detail.
|
61
|
+
|
62
|
+
### Graph
|
63
|
+
|
64
|
+
A **Graph** is a directed structure describing a workflow. It consists of:
|
65
|
+
|
66
|
+
- **Nodes**: the tasks or steps in your workflow
|
67
|
+
- **Edges (relationships)**: transitions from one node to another
|
68
|
+
|
69
|
+
You define a **Graph** via a `GraphDefinition`, specifying:
|
70
|
+
|
71
|
+
1. A unique **name** for the graph
|
72
|
+
2. An **entryNode** (starting point)
|
73
|
+
3. A map of **node objects** (each one describes a single node’s logic and transitions)
|
74
|
+
|
75
|
+
#### Why use graphs?
|
76
|
+
|
77
|
+
- **Clear visualization**: easily see the flow of tasks, including parallel branches.
|
78
|
+
- **Condition-based transitions**: skip or filter nodes on the fly.
|
79
|
+
- **Subgraph usage**: encapsulate common flows for reuse.
|
80
|
+
|
81
|
+
#### Example of a simple graph definition
|
82
|
+
|
83
|
+
```ts
|
84
|
+
const myGraphDefinition = {
|
85
|
+
name: "my-simple-graph",
|
86
|
+
entryNode: "start",
|
87
|
+
nodes: {
|
88
|
+
start: {
|
89
|
+
name: "start",
|
90
|
+
execute: async (_params, state) => {
|
91
|
+
return { context: { ...state.context, status: "initialized" } };
|
92
|
+
},
|
93
|
+
relationships: [{ name: "process" }],
|
94
|
+
},
|
95
|
+
process: {
|
96
|
+
name: "process",
|
97
|
+
execute: async (_params, state) => {
|
98
|
+
// do something
|
99
|
+
return { context: { ...state.context, processed: true } };
|
100
|
+
},
|
101
|
+
relationships: [{ name: "finish" }],
|
102
|
+
},
|
103
|
+
finish: {
|
104
|
+
name: "finish",
|
105
|
+
execute: async (_params, state) => state,
|
106
|
+
relationships: [],
|
107
|
+
},
|
108
|
+
},
|
109
|
+
};
|
110
|
+
```
|
85
111
|
|
86
|
-
|
112
|
+
### Node
|
87
113
|
|
88
|
-
|
89
|
-
- Respects dependencies between actions.
|
90
|
-
- Handles errors or confirmations via callbacks.
|
114
|
+
A **Node** is a fundamental unit of work within a graph. Each node defines:
|
91
115
|
|
92
|
-
|
93
|
-
|
94
|
-
|
116
|
+
- **name**: a unique identifier within the graph
|
117
|
+
- **execute**: the asynchronous function that implements the node’s logic
|
118
|
+
- **condition** (optional): a function returning a boolean determining if this node should run
|
119
|
+
- **relationships**: an array of transitions to subsequent nodes
|
120
|
+
- **events** (optional): an array of event names that can trigger the node (bypassing usual transitions)
|
95
121
|
|
96
|
-
|
122
|
+
#### Listening to events
|
97
123
|
|
98
|
-
|
99
|
-
import { ActionQueueManager } from "@ai-ntellect/core";
|
100
|
-
import { actions, callbacks } from "@ai-ntellect/core/examples";
|
124
|
+
Besides sequential or parallel execution, a node can listen to custom events:
|
101
125
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
126
|
+
```ts
|
127
|
+
{
|
128
|
+
name: "eventDrivenNode",
|
129
|
+
events: ["USER_CREATED"],
|
130
|
+
execute: async (params, state) => {
|
131
|
+
console.log("User created:", params);
|
132
|
+
return state;
|
133
|
+
},
|
134
|
+
}
|
106
135
|
```
|
107
136
|
|
108
|
-
|
137
|
+
If the **Engine** later calls `engine.emit("USER_CREATED", {...})`, this node will be triggered. This mechanism is extremely powerful for event-driven architectures (e.g., a chatbot responding to user events, or a blockchain node responding to on-chain events).
|
109
138
|
|
110
|
-
###
|
139
|
+
### GraphEngine
|
111
140
|
|
112
|
-
|
141
|
+
#### Overview
|
113
142
|
|
114
|
-
**
|
143
|
+
The **GraphEngine** (often shortened to “engine”) is responsible for:
|
115
144
|
|
116
|
-
|
117
|
-
|
118
|
-
|
145
|
+
- Loading a `GraphDefinition`
|
146
|
+
- Executing its nodes according to **relationships** and optional **conditions**
|
147
|
+
- Handling **state** updates after each node execution
|
148
|
+
- Managing **event** emissions and listening for event-driven nodes
|
149
|
+
- Allowing **parallel** or **sequential** node execution
|
150
|
+
- Managing **subgraphs** if your workflow references external graph definitions
|
119
151
|
|
120
|
-
|
152
|
+
```ts
|
153
|
+
import { GraphEngine } from "ai.ntellect/core";
|
121
154
|
|
122
|
-
|
123
|
-
|
124
|
-
|
155
|
+
const engine = new GraphEngine(myGraphDefinition);
|
156
|
+
await engine.execute({ context: { user: "Alice" } }, "start");
|
157
|
+
```
|
125
158
|
|
126
|
-
|
159
|
+
### GraphController
|
127
160
|
|
128
|
-
|
161
|
+
#### Overview
|
129
162
|
|
130
|
-
The
|
163
|
+
The **GraphController** provides a **high-level orchestration** mechanism for multiple graphs. Instead of running a single workflow, you can define **actions**—each tied to a particular workflow—and the controller executes them in sequence (or other patterns) based on your configuration.
|
131
164
|
|
132
|
-
|
165
|
+
```ts
|
166
|
+
import { GraphController } from "ai.ntellect/core";
|
133
167
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
168
|
+
const controller = new GraphController<any>();
|
169
|
+
const resultState = await controller.run(
|
170
|
+
[
|
171
|
+
{
|
172
|
+
name: "my-simple-graph",
|
173
|
+
parameters: [
|
174
|
+
{ name: "user", value: "Alice" },
|
175
|
+
{ name: "count", value: 10 },
|
176
|
+
],
|
177
|
+
},
|
178
|
+
],
|
179
|
+
[myGraphDefinition, someOtherGraphDef]
|
180
|
+
);
|
140
181
|
|
141
|
-
|
182
|
+
console.log(resultState);
|
183
|
+
// => final state after running 'my-simple-graph'
|
184
|
+
```
|
142
185
|
|
143
|
-
|
186
|
+
**Use cases**:
|
144
187
|
|
145
|
-
|
188
|
+
- **Batch execution** of multiple workflows
|
189
|
+
- **Multi-tenant** orchestration where each tenant’s configuration is an “action”
|
190
|
+
- **Chained flows**: run workflow A, then run workflow B with the result of A
|
146
191
|
|
147
|
-
|
192
|
+
### Memory management
|
148
193
|
|
149
|
-
|
150
|
-
- Manage subscriptions with custom messages.
|
151
|
-
- Trigger callbacks to process received data.
|
194
|
+
In advanced workflows, especially with chatbots or AI agents, you might want to maintain a **memory** of previous interactions or references. @ai.ntellect/core accommodates this via an abstract class **BaseMemory** and a dedicated **BaseMemoryService** for storing and retrieving data. This can be used to store embeddings, historical context, or any ephemeral data needed for your workflows.
|
152
195
|
|
153
|
-
|
196
|
+
```ts
|
197
|
+
import { BaseMemory } from "ai.ntellect/core";
|
154
198
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
() => JSON.stringify({ action: "subscribe" }),
|
160
|
-
async (data) => {
|
161
|
-
console.log("Received data:", data);
|
199
|
+
// Example concrete class
|
200
|
+
class MyMemory extends BaseMemory {
|
201
|
+
async init(): Promise<void> {
|
202
|
+
/*...*/
|
162
203
|
}
|
163
|
-
)
|
204
|
+
async createMemory(input): Promise<BaseMemoryType | undefined> {
|
205
|
+
/*...*/
|
206
|
+
}
|
207
|
+
async getMemoryById(id, roomId): Promise<BaseMemoryType | null> {
|
208
|
+
/*...*/
|
209
|
+
}
|
210
|
+
// ... other methods
|
211
|
+
}
|
164
212
|
```
|
165
213
|
|
166
|
-
|
214
|
+
**Possible storage backends**:
|
167
215
|
|
168
|
-
|
216
|
+
- In-memory
|
217
|
+
- Redis / Key-value stores
|
218
|
+
- SQL / NoSQL databases
|
169
219
|
|
170
|
-
**
|
220
|
+
**Key benefits**:
|
171
221
|
|
172
|
-
|
222
|
+
- Store query embeddings for AI-based search
|
223
|
+
- Maintain user session context (e.g., conversation flows)
|
224
|
+
- Rapidly retrieve and update relevant data at runtime
|
173
225
|
|
174
|
-
|
175
|
-
- Support for recurring and non-recurring tasks.
|
176
|
-
- Management and cancellation of scheduled tasks.
|
177
|
-
|
178
|
-
**Usage Example:**
|
226
|
+
---
|
179
227
|
|
180
|
-
|
181
|
-
const scheduler = new TaskScheduler(agentRuntime, redisCache);
|
228
|
+
## Advanced usage and features
|
182
229
|
|
183
|
-
|
184
|
-
originalRequest: "Market analysis",
|
185
|
-
cronExpression: "0 9 * * *", // Every day at 9 AM
|
186
|
-
});
|
230
|
+
### Subgraphs for modularity
|
187
231
|
|
188
|
-
|
232
|
+
Nodes can delegate execution to a **subgraph**, enabling large workflows to be broken into reusable components:
|
189
233
|
|
190
|
-
|
191
|
-
|
234
|
+
```ts
|
235
|
+
const subGraphEngine = new GraphEngine(subGraphDef);
|
236
|
+
mainGraphEngine.addSubGraph(subGraphEngine, "sub-start", "sub-workflow");
|
192
237
|
```
|
193
238
|
|
194
|
-
|
239
|
+
**Why subgraphs**:
|
195
240
|
|
196
|
-
|
241
|
+
- **Reusability**: common routines can be maintained independently
|
242
|
+
- **Maintainability**: isolate large logic in smaller workflows
|
197
243
|
|
198
|
-
###
|
244
|
+
### Parallel execution
|
199
245
|
|
200
|
-
|
246
|
+
The `executeParallel` method allows you to simultaneously run multiple nodes that don’t have direct dependencies on each other. You can limit concurrency to prevent overwhelming external resources:
|
201
247
|
|
202
|
-
|
203
|
-
|
204
|
-
|
248
|
+
```ts
|
249
|
+
await engine.executeParallel(
|
250
|
+
{ context: { userId: 42 } },
|
251
|
+
["nodeA", "nodeB", "nodeC"],
|
252
|
+
2 // concurrency limit
|
253
|
+
);
|
254
|
+
```
|
205
255
|
|
206
|
-
###
|
256
|
+
### Real-time notifications and events
|
207
257
|
|
208
|
-
|
209
|
-
import { z } from "zod";
|
210
|
-
import { parseEther } from "ethers";
|
258
|
+
By attaching a **RealTimeNotifier**, each node’s start, completion, or error can be broadcast to external systems (WebSocket, Slack, logging, etc.):
|
211
259
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
walletAddress: z.string(),
|
217
|
-
amount: z.string(),
|
218
|
-
networkId: z.string(),
|
219
|
-
}),
|
220
|
-
execute: async ({ walletAddress, amount, networkId }) => {
|
221
|
-
return {
|
222
|
-
to: walletAddress,
|
223
|
-
value: parseEther(amount).toString(),
|
224
|
-
network: networkId,
|
225
|
-
};
|
260
|
+
```ts
|
261
|
+
const notifier = {
|
262
|
+
notify: (event, data) => {
|
263
|
+
console.log(`[NOTIFY] ${event}`, data);
|
226
264
|
},
|
227
265
|
};
|
266
|
+
engine.setNotifier(notifier);
|
228
267
|
```
|
229
268
|
|
230
|
-
|
231
|
-
|
232
|
-
## State Management and Recursion
|
233
|
-
|
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.
|
235
|
-
|
236
|
-
### State Management
|
237
|
-
|
238
|
-
The state (`State`) includes:
|
239
|
-
|
240
|
-
- `currentContext`: The current context of the user request.
|
241
|
-
- `previousActions`: A list of previously executed actions.
|
242
|
-
|
243
|
-
When an action is completed, the state is updated to include:
|
244
|
-
|
245
|
-
- Results from previous actions.
|
246
|
-
- Remaining context to be processed.
|
247
|
-
|
248
|
-
### Controlled Recursion
|
249
|
-
|
250
|
-
To prevent infinite loops, the system limits the number of iterations via the `maxIterations` configuration.
|
251
|
-
|
252
|
-
**Workflow:**
|
269
|
+
### Persistence and error recovery
|
253
270
|
|
254
|
-
|
271
|
+
For long-running or mission-critical workflows, implement a **Persistence** interface:
|
255
272
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
- If actions remain to be executed, the agent recursively calls the `process` method with the updated state.
|
265
|
-
|
266
|
-
**State and Recursion Example:**
|
267
|
-
|
268
|
-
```typescript
|
269
|
-
const updatedNextState: State = {
|
270
|
-
...state,
|
271
|
-
currentContext: state.currentContext,
|
272
|
-
previousActions: [...(state.previousActions || []), ...(results || [])],
|
273
|
+
```ts
|
274
|
+
const myPersistence = {
|
275
|
+
saveState: async (graphName, state, currentNode) => {
|
276
|
+
/* store in DB */
|
277
|
+
},
|
278
|
+
loadState: async () => {
|
279
|
+
/* retrieve from DB */ return null;
|
280
|
+
},
|
273
281
|
};
|
274
|
-
|
275
|
-
if (countIterations < this.config.maxIterations) {
|
276
|
-
return this.process(updatedNextState);
|
277
|
-
} else {
|
278
|
-
console.log("Max iterations reached");
|
279
|
-
response.shouldContinue = false;
|
280
|
-
}
|
282
|
+
engine.setPersistence(myPersistence);
|
281
283
|
```
|
282
284
|
|
283
|
-
|
284
|
-
|
285
|
-
## Installation and Configuration
|
285
|
+
If a workflow fails, you can reload from the last checkpoint and resume execution.
|
286
286
|
|
287
|
-
|
287
|
+
---
|
288
288
|
|
289
|
-
|
290
|
-
|
289
|
+
## Example: agent workflow with memory
|
290
|
+
|
291
|
+
Below is an example `createMainGraph` definition demonstrating how you can structure an AI or chatbot-like agent using a controller node, agenda scheduling, interpretation, and memory storage. This pattern is useful in:
|
292
|
+
|
293
|
+
- **Chatbots** handling complex dialogues
|
294
|
+
- **AI reasoning systems** that need to store partial results
|
295
|
+
- **Planning agents** that schedule tasks or actions asynchronously
|
296
|
+
|
297
|
+
```ts
|
298
|
+
import { GraphDefinition } from "@/types";
|
299
|
+
// Assume Agent, MyContext, isNotStopped, shouldRetry, etc. are defined
|
300
|
+
|
301
|
+
export const createMainGraph = (
|
302
|
+
agent: Agent,
|
303
|
+
prompt: string,
|
304
|
+
callbacks?: any
|
305
|
+
): GraphDefinition<MyContext> => ({
|
306
|
+
name: "agent",
|
307
|
+
entryNode: "orchestrator",
|
308
|
+
nodes: {
|
309
|
+
orchestrator: {
|
310
|
+
name: "orchestrator",
|
311
|
+
description: "Make a decision following the current context",
|
312
|
+
execute: async () => {
|
313
|
+
/* your orchestrator logic */
|
314
|
+
},
|
315
|
+
condition: (state) => isNotStopped(state) || shouldRetry(state),
|
316
|
+
relationships: [
|
317
|
+
{ name: "controller", description: "Execute multiple workflows" },
|
318
|
+
{ name: "agenda", description: "Schedule actions for the future" },
|
319
|
+
{
|
320
|
+
name: "interpreter",
|
321
|
+
description: "Interpret the results of actions",
|
322
|
+
},
|
323
|
+
],
|
324
|
+
},
|
325
|
+
controller: {
|
326
|
+
name: "controller",
|
327
|
+
description: "Execute multiple workflows if available",
|
328
|
+
execute: async () => {
|
329
|
+
/* handle or queue workflow actions */
|
330
|
+
},
|
331
|
+
condition: () => {
|
332
|
+
const currentState = agent.graph.getState();
|
333
|
+
return hasActions(currentState) && isNotStopped(currentState);
|
334
|
+
},
|
335
|
+
relationships: [{ name: "orchestrator" }],
|
336
|
+
},
|
337
|
+
agenda: {
|
338
|
+
name: "agenda",
|
339
|
+
description: "Schedule actions for the future",
|
340
|
+
execute: async () => {
|
341
|
+
/* handle scheduling logic */
|
342
|
+
},
|
343
|
+
condition: hasActions,
|
344
|
+
},
|
345
|
+
interpreter: {
|
346
|
+
name: "interpreter",
|
347
|
+
description: "Interpret the results of the actions",
|
348
|
+
execute: async () => {
|
349
|
+
/* interpret results, maybe using memory */
|
350
|
+
},
|
351
|
+
condition: () => {
|
352
|
+
const currentState = agent.graph.getState();
|
353
|
+
return (
|
354
|
+
isInterpreterDefined(currentState) &&
|
355
|
+
isResultsDefined(currentState) &&
|
356
|
+
isStopped(currentState)
|
357
|
+
);
|
358
|
+
},
|
359
|
+
relationships: [{ name: "memory", description: "Save memory" }],
|
360
|
+
},
|
361
|
+
memory: {
|
362
|
+
name: "memory",
|
363
|
+
description: "Save memory",
|
364
|
+
execute: async () => {
|
365
|
+
/* store or retrieve conversation states */
|
366
|
+
},
|
367
|
+
condition: () => {
|
368
|
+
const currentState = agent.graph.getState();
|
369
|
+
return isResultsDefined(currentState);
|
370
|
+
},
|
371
|
+
},
|
372
|
+
},
|
373
|
+
});
|
291
374
|
```
|
292
375
|
|
293
|
-
|
376
|
+
This structure highlights how an **Agent** can leverage the **GraphEngine** for decision-making, scheduling tasks, interpreting outcomes, and ultimately storing relevant data in memory before concluding.
|
294
377
|
|
295
|
-
|
296
|
-
|
297
|
-
```bash
|
298
|
-
docker run --name redis -d -p 6379:6379 redis
|
299
|
-
```
|
378
|
+
---
|
300
379
|
|
301
|
-
|
380
|
+
## Real-world use cases
|
302
381
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
382
|
+
1. **Automation**: Orchestrate tasks like file processing, data validation, and uploading in a single graph.
|
383
|
+
2. **Data pipeline**: Stream logs into a transformation flow with parallel processing and conditional branches.
|
384
|
+
3. **AI bots**: Manage conversation state, memory, and advanced decision trees for chat-based agents.
|
385
|
+
4. **Blockchain**: Sequence complex contract interactions, handle parallel on-chain calls, and revert safely on errors.
|
386
|
+
5. **Task scheduling**: Combine GraphController with multiple workflows to handle enterprise-wide daily or weekly tasks.
|
307
387
|
|
308
388
|
---
|
309
389
|
|
310
|
-
##
|
311
|
-
|
312
|
-
### Initialize the Agent
|
313
|
-
|
314
|
-
```typescript
|
315
|
-
import { deepseek } from "@ai-ntellect/core";
|
316
|
-
import { Agent } from "@ai-ntellect/core";
|
317
|
-
import { checkHoneypot, fetchMarkPrice } from "@ai-ntellect/core/actions";
|
318
|
-
import {
|
319
|
-
generalInterpreterCharacter,
|
320
|
-
marketInterpreterCharacter,
|
321
|
-
securityInterpreterCharacter,
|
322
|
-
} from "@ai-ntellect/core/interpreter/context";
|
390
|
+
## Conclusion
|
323
391
|
|
324
|
-
|
392
|
+
@ai.ntellect/core offers a **comprehensive**, **modular**, and **event-driven** environment to model, execute, and extend workflows of any complexity. By leveraging **Graphs** and **Nodes** alongside robust tooling such as **GraphEngine**, **GraphController**, and **Memory** services, you can adapt the framework to fit an array of domains, from classic data pipelines to cutting-edge AI agent systems.
|
325
393
|
|
326
|
-
|
327
|
-
orchestrator: {
|
328
|
-
model,
|
329
|
-
tools: [checkHoneypot, fetchMarkPrice],
|
330
|
-
},
|
331
|
-
interpreters: [
|
332
|
-
new Interpreter({
|
333
|
-
name: "security",
|
334
|
-
model,
|
335
|
-
character: securityInterpreterCharacter,
|
336
|
-
}),
|
337
|
-
new Interpreter({
|
338
|
-
name: "market",
|
339
|
-
model,
|
340
|
-
character: marketInterpreterCharacter,
|
341
|
-
}),
|
342
|
-
new Interpreter({
|
343
|
-
name: "general",
|
344
|
-
model,
|
345
|
-
character: generalInterpreterCharacter,
|
346
|
-
}),
|
347
|
-
],
|
348
|
-
memoryManager: {
|
349
|
-
model,
|
350
|
-
},
|
351
|
-
maxIterations: 3,
|
352
|
-
});
|
353
|
-
```
|
394
|
+
### Key points to remember
|
354
395
|
|
355
|
-
|
396
|
+
- **Graphs** define the structure of your workflow; **Nodes** encapsulate the logic.
|
397
|
+
- **GraphEngine** executes a single graph, handling state, conditions, and events.
|
398
|
+
- **GraphController** orchestrates multiple graphs in a higher-level scope.
|
399
|
+
- **Memory** management supports advanced agent use cases, storing embeddings or conversation history.
|
400
|
+
- **Parallel execution**, **subgraphs**, **real-time notifications**, and **persistence** provide powerful abstractions to scale with your needs.
|
356
401
|
|
357
|
-
|
358
|
-
const state = {
|
359
|
-
currentContext: "Analyze XRP/USD market trends",
|
360
|
-
previousActions: [],
|
361
|
-
};
|
402
|
+
For more in-depth guides, examples, or to contribute, visit our repository or consult the extended documentation. If you need specialized solutions—like a custom memory store or a unique scheduling system—**@ai.ntellect/core**’s open architecture makes it straightforward to extend or integrate with your existing stack.
|
362
403
|
|
363
|
-
|
364
|
-
console.log("Result:", result);
|
365
|
-
```
|
404
|
+
Use it for automation, AI bots, blockchain interactions, or any stateful workflow that demands reliability, flexibility, and clarity.
|