@ai.ntellect/core 0.1.101 ā 0.2.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/agent/index.ts +1 -23
- package/dist/agent/index.d.ts +2 -21
- package/dist/agent/index.js +2 -3
- package/dist/llm/evaluator/index.d.ts +1 -2
- package/dist/llm/orchestrator/index.d.ts +1 -2
- package/dist/llm/synthesizer/index.d.ts +2 -3
- package/dist/llm/synthesizer/index.js +17 -17
- package/dist/types.d.ts +18 -0
- package/dist/utils/inject-actions.js +3 -7
- package/llm/evaluator/index.ts +1 -2
- package/llm/orchestrator/index.ts +1 -1
- package/llm/synthesizer/index.ts +19 -20
- package/package.json +1 -1
- package/types.ts +19 -0
- package/utils/inject-actions.ts +5 -9
package/agent/index.ts
CHANGED
@@ -15,28 +15,8 @@ import { QueueItemTransformer } from "../utils/queue-item-transformer";
|
|
15
15
|
import { ResultSanitizer } from "../utils/sanitize-results";
|
16
16
|
import { ActionHandler } from "./handlers/ActionHandler";
|
17
17
|
|
18
|
-
export type State = {
|
19
|
-
behavior: {
|
20
|
-
role: string;
|
21
|
-
language: string;
|
22
|
-
guidelines: {
|
23
|
-
important: string[];
|
24
|
-
warnings: string[];
|
25
|
-
steps?: string[];
|
26
|
-
};
|
27
|
-
};
|
28
|
-
userRequest: string;
|
29
|
-
actions: ActionSchema[];
|
30
|
-
results: QueueResult[];
|
31
|
-
examplesMessages?: {
|
32
|
-
role: string;
|
33
|
-
content: string;
|
34
|
-
}[];
|
35
|
-
};
|
36
|
-
|
37
18
|
export class Agent {
|
38
19
|
private readonly actionHandler: ActionHandler;
|
39
|
-
private readonly user: User;
|
40
20
|
private readonly orchestrator: Orchestrator;
|
41
21
|
private readonly persistentMemory: PersistentMemory;
|
42
22
|
private readonly cacheMemory: CacheMemory | undefined;
|
@@ -46,7 +26,6 @@ export class Agent {
|
|
46
26
|
private accumulatedResults: QueueResult[] = [];
|
47
27
|
|
48
28
|
constructor({
|
49
|
-
user,
|
50
29
|
orchestrator,
|
51
30
|
persistentMemory,
|
52
31
|
cacheMemory,
|
@@ -60,7 +39,6 @@ export class Agent {
|
|
60
39
|
stream: boolean;
|
61
40
|
maxEvaluatorIteration: number;
|
62
41
|
}) {
|
63
|
-
this.user = user;
|
64
42
|
this.orchestrator = orchestrator;
|
65
43
|
this.cacheMemory = cacheMemory;
|
66
44
|
this.persistentMemory = persistentMemory;
|
@@ -203,7 +181,7 @@ export class Agent {
|
|
203
181
|
? (
|
204
182
|
await synthesizer.streamProcess(
|
205
183
|
actionsResult.initialPrompt,
|
206
|
-
|
184
|
+
this.accumulatedResults
|
207
185
|
)
|
208
186
|
).toDataStreamResponse()
|
209
187
|
: await synthesizer.process(
|
package/dist/agent/index.d.ts
CHANGED
@@ -1,28 +1,9 @@
|
|
1
1
|
import { Orchestrator } from "../llm/orchestrator";
|
2
2
|
import { CacheMemory } from "../memory/cache";
|
3
3
|
import { PersistentMemory } from "../memory/persistent";
|
4
|
-
import {
|
5
|
-
export type State = {
|
6
|
-
behavior: {
|
7
|
-
role: string;
|
8
|
-
language: string;
|
9
|
-
guidelines: {
|
10
|
-
important: string[];
|
11
|
-
warnings: string[];
|
12
|
-
steps?: string[];
|
13
|
-
};
|
14
|
-
};
|
15
|
-
userRequest: string;
|
16
|
-
actions: ActionSchema[];
|
17
|
-
results: QueueResult[];
|
18
|
-
examplesMessages?: {
|
19
|
-
role: string;
|
20
|
-
content: string;
|
21
|
-
}[];
|
22
|
-
};
|
4
|
+
import { AgentEvent, User } from "../types";
|
23
5
|
export declare class Agent {
|
24
6
|
private readonly actionHandler;
|
25
|
-
private readonly user;
|
26
7
|
private readonly orchestrator;
|
27
8
|
private readonly persistentMemory;
|
28
9
|
private readonly cacheMemory;
|
@@ -30,7 +11,7 @@ export declare class Agent {
|
|
30
11
|
private readonly maxEvaluatorIteration;
|
31
12
|
private evaluatorIteration;
|
32
13
|
private accumulatedResults;
|
33
|
-
constructor({
|
14
|
+
constructor({ orchestrator, persistentMemory, cacheMemory, stream, maxEvaluatorIteration, }: {
|
34
15
|
user: User;
|
35
16
|
orchestrator: Orchestrator;
|
36
17
|
persistentMemory: PersistentMemory;
|
package/dist/agent/index.js
CHANGED
@@ -8,10 +8,9 @@ const queue_item_transformer_1 = require("../utils/queue-item-transformer");
|
|
8
8
|
const sanitize_results_1 = require("../utils/sanitize-results");
|
9
9
|
const ActionHandler_1 = require("./handlers/ActionHandler");
|
10
10
|
class Agent {
|
11
|
-
constructor({
|
11
|
+
constructor({ orchestrator, persistentMemory, cacheMemory, stream, maxEvaluatorIteration = 1, }) {
|
12
12
|
this.evaluatorIteration = 0;
|
13
13
|
this.accumulatedResults = [];
|
14
|
-
this.user = user;
|
15
14
|
this.orchestrator = orchestrator;
|
16
15
|
this.cacheMemory = cacheMemory;
|
17
16
|
this.persistentMemory = persistentMemory;
|
@@ -94,7 +93,7 @@ class Agent {
|
|
94
93
|
}
|
95
94
|
}
|
96
95
|
return this.stream
|
97
|
-
? (await synthesizer.streamProcess(actionsResult.initialPrompt,
|
96
|
+
? (await synthesizer.streamProcess(actionsResult.initialPrompt, this.accumulatedResults)).toDataStreamResponse()
|
98
97
|
: await synthesizer.process(actionsResult.initialPrompt, this.accumulatedResults);
|
99
98
|
}
|
100
99
|
transformActions(actions) {
|
@@ -1,6 +1,5 @@
|
|
1
|
-
import { State } from "../../agent";
|
2
1
|
import { PersistentMemory } from "../../memory/persistent";
|
3
|
-
import { ActionSchema, QueueResult } from "../../types";
|
2
|
+
import { ActionSchema, QueueResult, State } from "../../types";
|
4
3
|
export declare class Evaluator {
|
5
4
|
private readonly model;
|
6
5
|
tools: ActionSchema[];
|
@@ -1,7 +1,6 @@
|
|
1
|
-
import { State } from "../../agent";
|
2
1
|
import { CacheMemory } from "../../memory/cache";
|
3
2
|
import { PersistentMemory } from "../../memory/persistent";
|
4
|
-
import { ActionSchema, QueueResult } from "../../types";
|
3
|
+
import { ActionSchema, QueueResult, State } from "../../types";
|
5
4
|
export declare class Orchestrator {
|
6
5
|
private readonly model;
|
7
6
|
tools: ActionSchema[];
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import { StreamTextResult } from "ai";
|
2
|
-
import { State } from "../../
|
3
|
-
import { QueueResult } from "../../types";
|
2
|
+
import { QueueResult, State } from "../../types";
|
4
3
|
export declare class Synthesizer {
|
5
4
|
private readonly model;
|
6
5
|
composeContext(state: Partial<State>): string;
|
@@ -11,5 +10,5 @@ export declare class Synthesizer {
|
|
11
10
|
}[];
|
12
11
|
response: string;
|
13
12
|
} | StreamTextResult<Record<string, any>>>;
|
14
|
-
streamProcess(prompt: string,
|
13
|
+
streamProcess(prompt: string, results: QueueResult[], onFinish?: (event: any) => void): Promise<any>;
|
15
14
|
}
|
@@ -65,25 +65,25 @@ class Synthesizer {
|
|
65
65
|
onFinish(result.object);
|
66
66
|
return result.object;
|
67
67
|
}
|
68
|
-
async streamProcess(prompt,
|
68
|
+
async streamProcess(prompt, results, onFinish) {
|
69
69
|
console.log("\nšØ Starting streaming synthesis");
|
70
70
|
console.log("Prompt:", prompt);
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
71
|
+
const context = this.composeContext({
|
72
|
+
behavior: context_1.synthesizerContext.behavior,
|
73
|
+
userRequest: prompt,
|
74
|
+
results: results,
|
75
|
+
});
|
76
|
+
const result = await (0, ai_1.streamText)({
|
77
|
+
model: this.model,
|
78
|
+
prompt,
|
79
|
+
onFinish: (event) => {
|
80
|
+
console.log("\nā
Streaming synthesis completed");
|
81
|
+
if (onFinish)
|
82
|
+
onFinish(event);
|
83
|
+
},
|
84
|
+
system: context,
|
85
|
+
});
|
86
|
+
return result;
|
87
87
|
}
|
88
88
|
}
|
89
89
|
exports.Synthesizer = Synthesizer;
|
package/dist/types.d.ts
CHANGED
@@ -45,6 +45,24 @@ export interface ProcessPromptCallbacks {
|
|
45
45
|
onQueueComplete?: (actions: QueueResult[]) => void | Promise<void>;
|
46
46
|
onConfirmationRequired?: (message: string) => Promise<boolean>;
|
47
47
|
}
|
48
|
+
export type State = {
|
49
|
+
behavior: {
|
50
|
+
role: string;
|
51
|
+
language: string;
|
52
|
+
guidelines: {
|
53
|
+
important: string[];
|
54
|
+
warnings: string[];
|
55
|
+
steps?: string[];
|
56
|
+
};
|
57
|
+
};
|
58
|
+
userRequest: string;
|
59
|
+
actions: ActionSchema[];
|
60
|
+
results: QueueResult[];
|
61
|
+
examplesMessages?: {
|
62
|
+
role: string;
|
63
|
+
content: string;
|
64
|
+
}[];
|
65
|
+
};
|
48
66
|
export interface ActionSchema {
|
49
67
|
name: string;
|
50
68
|
description: string;
|
@@ -6,13 +6,9 @@ const injectActions = (actions) => {
|
|
6
6
|
const parameters = action.parameters;
|
7
7
|
const schemaShape = Object.keys(parameters._def.shape()).join(", ");
|
8
8
|
const actionString = `Name: ${action.name}, Description: ${action.description}, Arguments (STRICTLY REQUIRED): { ${schemaShape} } ${action.examples
|
9
|
-
? `
|
10
|
-
.
|
11
|
-
|
12
|
-
? `{ ${Object.keys(e.parameters).join(", ")} }`
|
13
|
-
: ""}`;
|
14
|
-
})
|
15
|
-
.join("\n")}`
|
9
|
+
? `Format examples (MUST RESPECT): ${action.examples.map((example) => {
|
10
|
+
return JSON.stringify(example);
|
11
|
+
})}`
|
16
12
|
: ""}`;
|
17
13
|
return actionString;
|
18
14
|
});
|
package/llm/evaluator/index.ts
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
import { openai } from "@ai-sdk/openai";
|
2
2
|
import { generateObject } from "ai";
|
3
3
|
import { z } from "zod";
|
4
|
-
import { State } from "../../agent";
|
5
4
|
import { PersistentMemory } from "../../memory/persistent";
|
6
|
-
import { ActionSchema, MemoryScope, QueueResult } from "../../types";
|
5
|
+
import { ActionSchema, MemoryScope, QueueResult, State } from "../../types";
|
7
6
|
import { injectActions } from "../../utils/inject-actions";
|
8
7
|
import { evaluatorContext } from "./context";
|
9
8
|
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import { openai } from "@ai-sdk/openai";
|
2
2
|
import { generateObject } from "ai";
|
3
3
|
import { z } from "zod";
|
4
|
-
import { State } from "../../agent";
|
5
4
|
import { CacheMemory } from "../../memory/cache";
|
6
5
|
import { PersistentMemory } from "../../memory/persistent";
|
7
6
|
import {
|
@@ -9,6 +8,7 @@ import {
|
|
9
8
|
MemoryScope,
|
10
9
|
MemoryScopeType,
|
11
10
|
QueueResult,
|
11
|
+
State,
|
12
12
|
} from "../../types";
|
13
13
|
import { injectActions } from "../../utils/inject-actions";
|
14
14
|
import { orchestratorContext } from "./context";
|
package/llm/synthesizer/index.ts
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
import { openai } from "@ai-sdk/openai";
|
2
|
-
import { generateObject, StreamTextResult } from "ai";
|
2
|
+
import { generateObject, streamText, StreamTextResult } from "ai";
|
3
3
|
import { z } from "zod";
|
4
|
-
import { State } from "../../
|
5
|
-
import { QueueResult } from "../../types";
|
4
|
+
import { QueueResult, State } from "../../types";
|
6
5
|
import { synthesizerContext } from "./context";
|
7
6
|
|
8
7
|
export class Synthesizer {
|
@@ -89,28 +88,28 @@ export class Synthesizer {
|
|
89
88
|
|
90
89
|
async streamProcess(
|
91
90
|
prompt: string,
|
92
|
-
|
91
|
+
results: QueueResult[],
|
93
92
|
onFinish?: (event: any) => void
|
94
93
|
): Promise<any> {
|
95
94
|
console.log("\nšØ Starting streaming synthesis");
|
96
95
|
console.log("Prompt:", prompt);
|
97
|
-
// if (summaryData) {
|
98
|
-
// console.log(
|
99
|
-
// "Summary data:",
|
100
|
-
// JSON.stringify(JSON.parse(summaryData), null, 2)
|
101
|
-
// );
|
102
|
-
// }
|
103
96
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
97
|
+
const context = this.composeContext({
|
98
|
+
behavior: synthesizerContext.behavior,
|
99
|
+
userRequest: prompt,
|
100
|
+
results: results,
|
101
|
+
});
|
102
|
+
|
103
|
+
const result = await streamText({
|
104
|
+
model: this.model,
|
105
|
+
prompt,
|
106
|
+
onFinish: (event) => {
|
107
|
+
console.log("\nā
Streaming synthesis completed");
|
108
|
+
if (onFinish) onFinish(event);
|
109
|
+
},
|
110
|
+
system: context,
|
111
|
+
});
|
113
112
|
|
114
|
-
|
113
|
+
return result;
|
115
114
|
}
|
116
115
|
}
|
package/package.json
CHANGED
package/types.ts
CHANGED
@@ -56,6 +56,25 @@ export interface ProcessPromptCallbacks {
|
|
56
56
|
onConfirmationRequired?: (message: string) => Promise<boolean>;
|
57
57
|
}
|
58
58
|
|
59
|
+
export type State = {
|
60
|
+
behavior: {
|
61
|
+
role: string;
|
62
|
+
language: string;
|
63
|
+
guidelines: {
|
64
|
+
important: string[];
|
65
|
+
warnings: string[];
|
66
|
+
steps?: string[];
|
67
|
+
};
|
68
|
+
};
|
69
|
+
userRequest: string;
|
70
|
+
actions: ActionSchema[];
|
71
|
+
results: QueueResult[];
|
72
|
+
examplesMessages?: {
|
73
|
+
role: string;
|
74
|
+
content: string;
|
75
|
+
}[];
|
76
|
+
};
|
77
|
+
|
59
78
|
export interface ActionSchema {
|
60
79
|
name: string;
|
61
80
|
description: string;
|
package/utils/inject-actions.ts
CHANGED
@@ -9,15 +9,11 @@ export const injectActions = (actions: ActionSchema[]) => {
|
|
9
9
|
action.description
|
10
10
|
}, Arguments (STRICTLY REQUIRED): { ${schemaShape} } ${
|
11
11
|
action.examples
|
12
|
-
? `
|
13
|
-
|
14
|
-
return
|
15
|
-
|
16
|
-
|
17
|
-
: ""
|
18
|
-
}`;
|
19
|
-
})
|
20
|
-
.join("\n")}`
|
12
|
+
? `Format examples (MUST RESPECT): ${action.examples.map(
|
13
|
+
(example: any) => {
|
14
|
+
return JSON.stringify(example);
|
15
|
+
}
|
16
|
+
)}`
|
21
17
|
: ""
|
22
18
|
}`;
|
23
19
|
return actionString;
|