@ai.ntellect/core 0.2.7 ā 0.2.8
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/agent/index.ts +10 -10
- package/dist/agent/index.js +8 -8
- package/dist/llm/evaluator/index.d.ts +2 -2
- package/dist/llm/evaluator/index.js +1 -2
- package/dist/llm/orchestrator/index.d.ts +2 -2
- package/dist/llm/orchestrator/index.js +1 -1
- package/dist/llm/synthesizer/index.d.ts +3 -3
- package/dist/llm/synthesizer/index.js +1 -2
- package/dist/types.d.ts +1 -1
- package/llm/evaluator/index.ts +3 -4
- package/llm/orchestrator/index.ts +3 -9
- package/llm/synthesizer/index.ts +4 -5
- package/package.json +1 -1
- package/types.ts +1 -1
package/agent/index.ts
CHANGED
@@ -5,6 +5,7 @@ import { CacheMemory } from "../memory/cache";
|
|
5
5
|
import { PersistentMemory } from "../memory/persistent";
|
6
6
|
import { ActionSchema, AgentEvent, QueueResult, User } 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 {
|
@@ -15,7 +16,7 @@ export class Agent {
|
|
15
16
|
private readonly stream: boolean;
|
16
17
|
private readonly maxEvaluatorIteration: number;
|
17
18
|
private evaluatorIteration = 0;
|
18
|
-
private accumulatedResults:
|
19
|
+
private accumulatedResults: string = "";
|
19
20
|
|
20
21
|
constructor({
|
21
22
|
orchestrator,
|
@@ -37,11 +38,11 @@ export class Agent {
|
|
37
38
|
this.stream = stream;
|
38
39
|
this.maxEvaluatorIteration = maxEvaluatorIteration;
|
39
40
|
this.actionHandler = new ActionHandler();
|
40
|
-
this.accumulatedResults =
|
41
|
+
this.accumulatedResults = "";
|
41
42
|
}
|
42
43
|
|
43
44
|
async process(prompt: string, events: AgentEvent): Promise<any> {
|
44
|
-
this.accumulatedResults =
|
45
|
+
this.accumulatedResults = "";
|
45
46
|
this.evaluatorIteration = 0;
|
46
47
|
console.log("Requesting orchestrator for actions..");
|
47
48
|
const request = await this.orchestrator.process(
|
@@ -92,10 +93,7 @@ export class Agent {
|
|
92
93
|
}
|
93
94
|
);
|
94
95
|
|
95
|
-
this.accumulatedResults
|
96
|
-
...this.accumulatedResults,
|
97
|
-
...actionsResult.data,
|
98
|
-
]);
|
96
|
+
this.accumulatedResults += this.formatResults(actionsResult.data);
|
99
97
|
|
100
98
|
const isOnChainAction = actions.some(
|
101
99
|
(action) => action.type === "on-chain"
|
@@ -146,7 +144,7 @@ export class Agent {
|
|
146
144
|
}
|
147
145
|
|
148
146
|
private async handleActionResults(actionsResult: {
|
149
|
-
data:
|
147
|
+
data: string;
|
150
148
|
initialPrompt: string;
|
151
149
|
}) {
|
152
150
|
const synthesizer = new Synthesizer();
|
@@ -171,13 +169,15 @@ export class Agent {
|
|
171
169
|
return predefinedActions;
|
172
170
|
}
|
173
171
|
|
174
|
-
private formatResults(results: QueueResult[]):
|
175
|
-
|
172
|
+
private formatResults(results: QueueResult[]): string {
|
173
|
+
const formattedResults = results.map((result) => ({
|
176
174
|
...result,
|
177
175
|
result:
|
178
176
|
typeof result.result === "object"
|
179
177
|
? JSON.stringify(result.result)
|
180
178
|
: result.result,
|
181
179
|
}));
|
180
|
+
const sanitizedResults = ResultSanitizer.sanitize(formattedResults);
|
181
|
+
return sanitizedResults;
|
182
182
|
}
|
183
183
|
}
|
package/dist/agent/index.js
CHANGED
@@ -4,21 +4,22 @@ exports.Agent = void 0;
|
|
4
4
|
const evaluator_1 = require("../llm/evaluator");
|
5
5
|
const synthesizer_1 = require("../llm/synthesizer");
|
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
10
|
constructor({ orchestrator, persistentMemory, cacheMemory, stream, maxEvaluatorIteration = 1, }) {
|
10
11
|
this.evaluatorIteration = 0;
|
11
|
-
this.accumulatedResults =
|
12
|
+
this.accumulatedResults = "";
|
12
13
|
this.orchestrator = orchestrator;
|
13
14
|
this.cacheMemory = cacheMemory;
|
14
15
|
this.persistentMemory = persistentMemory;
|
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
25
|
const request = await this.orchestrator.process(prompt, this.accumulatedResults);
|
@@ -39,10 +40,7 @@ class Agent {
|
|
39
40
|
onQueueComplete: events.onQueueComplete,
|
40
41
|
onConfirmationRequired: events.onConfirmationRequired,
|
41
42
|
});
|
42
|
-
this.accumulatedResults
|
43
|
-
...this.accumulatedResults,
|
44
|
-
...actionsResult.data,
|
45
|
-
]);
|
43
|
+
this.accumulatedResults += this.formatResults(actionsResult.data);
|
46
44
|
const isOnChainAction = actions.some((action) => action.type === "on-chain");
|
47
45
|
if (isOnChainAction) {
|
48
46
|
return {
|
@@ -83,12 +81,14 @@ class Agent {
|
|
83
81
|
return predefinedActions;
|
84
82
|
}
|
85
83
|
formatResults(results) {
|
86
|
-
|
84
|
+
const formattedResults = results.map((result) => ({
|
87
85
|
...result,
|
88
86
|
result: typeof result.result === "object"
|
89
87
|
? JSON.stringify(result.result)
|
90
88
|
: result.result,
|
91
89
|
}));
|
90
|
+
const sanitizedResults = sanitize_results_1.ResultSanitizer.sanitize(formattedResults);
|
91
|
+
return sanitizedResults;
|
92
92
|
}
|
93
93
|
}
|
94
94
|
exports.Agent = Agent;
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { PersistentMemory } from "../../memory/persistent";
|
2
|
-
import { ActionSchema,
|
2
|
+
import { ActionSchema, State } from "../../types";
|
3
3
|
export declare class Evaluator {
|
4
4
|
private readonly model;
|
5
5
|
tools: ActionSchema[];
|
6
6
|
private memory;
|
7
7
|
constructor(tools: ActionSchema[], memory: PersistentMemory);
|
8
8
|
composeContext(state: State): string;
|
9
|
-
process(prompt: string, results:
|
9
|
+
process(prompt: string, results: string): Promise<any>;
|
10
10
|
}
|
@@ -24,10 +24,9 @@ class Evaluator {
|
|
24
24
|
# NEVER: ${warnings.join("\n")}
|
25
25
|
# USER_REQUEST: ${userRequest}
|
26
26
|
# ACTIONS AVAILABLE: ${(0, inject_actions_1.injectActions)(actions)}
|
27
|
-
# CURRENT_RESULTS: ${results
|
27
|
+
# CURRENT_RESULTS: ${results}
|
28
28
|
# STEPS: ${steps?.join("\n") || ""}
|
29
29
|
`;
|
30
|
-
console.log("Evaluator Context:", context);
|
31
30
|
return context;
|
32
31
|
}
|
33
32
|
async process(prompt, results) {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { CacheMemory } from "../../memory/cache";
|
2
2
|
import { PersistentMemory } from "../../memory/persistent";
|
3
|
-
import { ActionSchema,
|
3
|
+
import { ActionSchema, State } from "../../types";
|
4
4
|
export declare class Orchestrator {
|
5
5
|
private readonly model;
|
6
6
|
tools: ActionSchema[];
|
@@ -11,7 +11,7 @@ export declare class Orchestrator {
|
|
11
11
|
cache: CacheMemory;
|
12
12
|
});
|
13
13
|
composeContext(state: State): string;
|
14
|
-
process(prompt: string, results:
|
14
|
+
process(prompt: string, results: string): Promise<{
|
15
15
|
actions: {
|
16
16
|
name: string;
|
17
17
|
type: string;
|
@@ -79,7 +79,7 @@ class Orchestrator {
|
|
79
79
|
# IMPORTANT: ${important.join("\n")}
|
80
80
|
# USER_REQUEST: ${userRequest}
|
81
81
|
# ACTIONS_AVAILABLES: ${(0, inject_actions_1.injectActions)(actions)} (NEVER REPEAT ACTIONS)
|
82
|
-
# CURRENT_RESULTS: ${results
|
82
|
+
# CURRENT_RESULTS: ${results}
|
83
83
|
`.trim();
|
84
84
|
return context;
|
85
85
|
}
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import { StreamTextResult } from "ai";
|
2
|
-
import {
|
2
|
+
import { State } from "../../types";
|
3
3
|
export declare class Synthesizer {
|
4
4
|
private readonly model;
|
5
5
|
composeContext(state: Partial<State>): string;
|
6
|
-
process(prompt: string, results:
|
6
|
+
process(prompt: string, results: string, onFinish?: (event: any) => void): Promise<{
|
7
7
|
actionsCompleted: {
|
8
8
|
name: string;
|
9
9
|
reasoning: string;
|
10
10
|
}[];
|
11
11
|
response: string;
|
12
12
|
} | StreamTextResult<Record<string, any>>>;
|
13
|
-
streamProcess(prompt: string, results:
|
13
|
+
streamProcess(prompt: string, results: string, onFinish?: (event: any) => void): Promise<any>;
|
14
14
|
}
|
@@ -22,11 +22,10 @@ class Synthesizer {
|
|
22
22
|
# IMPORTANT: ${important.join("\n")}
|
23
23
|
# NEVER: ${warnings.join("\n")}
|
24
24
|
# USER_REQUEST: ${userRequest}
|
25
|
-
# CURRENT_RESULTS: ${results
|
25
|
+
# CURRENT_RESULTS: ${results}
|
26
26
|
# STEPS: ${steps?.join("\n") || ""}
|
27
27
|
# MESSAGES EXAMPLES: ${JSON.stringify(examplesMessages, null, 2)}
|
28
28
|
`;
|
29
|
-
console.log("Synthesizer Context:", context);
|
30
29
|
return context;
|
31
30
|
}
|
32
31
|
async process(prompt, results, onFinish) {
|
package/dist/types.d.ts
CHANGED
package/llm/evaluator/index.ts
CHANGED
@@ -2,7 +2,7 @@ import { openai } from "@ai-sdk/openai";
|
|
2
2
|
import { generateObject } from "ai";
|
3
3
|
import { z } from "zod";
|
4
4
|
import { PersistentMemory } from "../../memory/persistent";
|
5
|
-
import { ActionSchema, MemoryScope,
|
5
|
+
import { ActionSchema, MemoryScope, State } from "../../types";
|
6
6
|
import { injectActions } from "../../utils/inject-actions";
|
7
7
|
import { evaluatorContext } from "./context";
|
8
8
|
|
@@ -28,14 +28,13 @@ export class Evaluator {
|
|
28
28
|
# NEVER: ${warnings.join("\n")}
|
29
29
|
# USER_REQUEST: ${userRequest}
|
30
30
|
# ACTIONS AVAILABLE: ${injectActions(actions)}
|
31
|
-
# CURRENT_RESULTS: ${results
|
31
|
+
# CURRENT_RESULTS: ${results}
|
32
32
|
# STEPS: ${steps?.join("\n") || ""}
|
33
33
|
`;
|
34
|
-
console.log("Evaluator Context:", context);
|
35
34
|
return context;
|
36
35
|
}
|
37
36
|
|
38
|
-
async process(prompt: string, results:
|
37
|
+
async process(prompt: string, results: string): Promise<any> {
|
39
38
|
try {
|
40
39
|
const context = this.composeContext({
|
41
40
|
behavior: evaluatorContext.behavior,
|
@@ -3,13 +3,7 @@ import { generateObject } from "ai";
|
|
3
3
|
import { z } from "zod";
|
4
4
|
import { CacheMemory } from "../../memory/cache";
|
5
5
|
import { PersistentMemory } from "../../memory/persistent";
|
6
|
-
import {
|
7
|
-
ActionSchema,
|
8
|
-
MemoryScope,
|
9
|
-
MemoryScopeType,
|
10
|
-
QueueResult,
|
11
|
-
State,
|
12
|
-
} from "../../types";
|
6
|
+
import { ActionSchema, MemoryScope, MemoryScopeType, State } from "../../types";
|
13
7
|
import { injectActions } from "../../utils/inject-actions";
|
14
8
|
import { orchestratorContext } from "./context";
|
15
9
|
|
@@ -118,7 +112,7 @@ export class Orchestrator {
|
|
118
112
|
# IMPORTANT: ${important.join("\n")}
|
119
113
|
# USER_REQUEST: ${userRequest}
|
120
114
|
# ACTIONS_AVAILABLES: ${injectActions(actions)} (NEVER REPEAT ACTIONS)
|
121
|
-
# CURRENT_RESULTS: ${results
|
115
|
+
# CURRENT_RESULTS: ${results}
|
122
116
|
`.trim();
|
123
117
|
|
124
118
|
return context;
|
@@ -126,7 +120,7 @@ export class Orchestrator {
|
|
126
120
|
|
127
121
|
async process(
|
128
122
|
prompt: string,
|
129
|
-
results:
|
123
|
+
results: string
|
130
124
|
): Promise<{
|
131
125
|
actions: {
|
132
126
|
name: string;
|
package/llm/synthesizer/index.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { openai } from "@ai-sdk/openai";
|
2
2
|
import { generateObject, streamText, StreamTextResult } from "ai";
|
3
3
|
import { z } from "zod";
|
4
|
-
import {
|
4
|
+
import { State } from "../../types";
|
5
5
|
import { synthesizerContext } from "./context";
|
6
6
|
|
7
7
|
export class Synthesizer {
|
@@ -22,17 +22,16 @@ export class Synthesizer {
|
|
22
22
|
# IMPORTANT: ${important.join("\n")}
|
23
23
|
# NEVER: ${warnings.join("\n")}
|
24
24
|
# USER_REQUEST: ${userRequest}
|
25
|
-
# CURRENT_RESULTS: ${results
|
25
|
+
# CURRENT_RESULTS: ${results}
|
26
26
|
# STEPS: ${steps?.join("\n") || ""}
|
27
27
|
# MESSAGES EXAMPLES: ${JSON.stringify(examplesMessages, null, 2)}
|
28
28
|
`;
|
29
|
-
console.log("Synthesizer Context:", context);
|
30
29
|
return context;
|
31
30
|
}
|
32
31
|
|
33
32
|
async process(
|
34
33
|
prompt: string,
|
35
|
-
results:
|
34
|
+
results: string,
|
36
35
|
onFinish?: (event: any) => void
|
37
36
|
): Promise<
|
38
37
|
| {
|
@@ -89,7 +88,7 @@ export class Synthesizer {
|
|
89
88
|
|
90
89
|
async streamProcess(
|
91
90
|
prompt: string,
|
92
|
-
results:
|
91
|
+
results: string,
|
93
92
|
onFinish?: (event: any) => void
|
94
93
|
): Promise<any> {
|
95
94
|
console.log("\nšØ Starting streaming synthesis");
|
package/package.json
CHANGED