@ai.ntellect/core 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- package/agent/index.ts +13 -22
- package/dist/agent/index.d.ts +1 -0
- package/dist/agent/index.js +10 -14
- package/package.json +1 -1
package/agent/index.ts
CHANGED
@@ -3,14 +3,7 @@ import { Orchestrator } from "../llm/orchestrator";
|
|
3
3
|
import { Synthesizer } from "../llm/synthesizer";
|
4
4
|
import { CacheMemory } from "../memory/cache";
|
5
5
|
import { PersistentMemory } from "../memory/persistent";
|
6
|
-
import {
|
7
|
-
ActionSchema,
|
8
|
-
AgentEvent,
|
9
|
-
MemoryScope,
|
10
|
-
MemoryType,
|
11
|
-
QueueResult,
|
12
|
-
User,
|
13
|
-
} from "../types";
|
6
|
+
import { ActionSchema, AgentEvent, QueueResult, User } from "../types";
|
14
7
|
import { QueueItemTransformer } from "../utils/queue-item-transformer";
|
15
8
|
import { ActionHandler } from "./handlers/ActionHandler";
|
16
9
|
|
@@ -160,28 +153,16 @@ export class Agent {
|
|
160
153
|
}) {
|
161
154
|
const synthesizer = new Synthesizer();
|
162
155
|
|
163
|
-
for (const action of actionsResult.data) {
|
164
|
-
if (!action.error) {
|
165
|
-
await this.cacheMemory?.createMemory({
|
166
|
-
content: actionsResult.initialPrompt,
|
167
|
-
data: action.result,
|
168
|
-
scope: MemoryScope.GLOBAL,
|
169
|
-
type: MemoryType.ACTION,
|
170
|
-
});
|
171
|
-
}
|
172
|
-
}
|
173
|
-
|
174
|
-
const accumulatedResults = this.accumulatedResults;
|
175
156
|
return this.stream
|
176
157
|
? (
|
177
158
|
await synthesizer.streamProcess(
|
178
159
|
actionsResult.initialPrompt,
|
179
|
-
|
160
|
+
this.formatResults(actionsResult.data)
|
180
161
|
)
|
181
162
|
).toDataStreamResponse()
|
182
163
|
: await synthesizer.process(
|
183
164
|
actionsResult.initialPrompt,
|
184
|
-
|
165
|
+
this.formatResults(actionsResult.data)
|
185
166
|
);
|
186
167
|
}
|
187
168
|
|
@@ -191,4 +172,14 @@ export class Agent {
|
|
191
172
|
|
192
173
|
return predefinedActions;
|
193
174
|
}
|
175
|
+
|
176
|
+
private formatResults(results: QueueResult[]): QueueResult[] {
|
177
|
+
return results.map((result) => ({
|
178
|
+
...result,
|
179
|
+
result:
|
180
|
+
typeof result.result === "object"
|
181
|
+
? JSON.stringify(result.result)
|
182
|
+
: result.result,
|
183
|
+
}));
|
184
|
+
}
|
194
185
|
}
|
package/dist/agent/index.d.ts
CHANGED
package/dist/agent/index.js
CHANGED
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Agent = void 0;
|
4
4
|
const evaluator_1 = require("../llm/evaluator");
|
5
5
|
const synthesizer_1 = require("../llm/synthesizer");
|
6
|
-
const types_1 = require("../types");
|
7
6
|
const queue_item_transformer_1 = require("../utils/queue-item-transformer");
|
8
7
|
const ActionHandler_1 = require("./handlers/ActionHandler");
|
9
8
|
class Agent {
|
@@ -77,24 +76,21 @@ class Agent {
|
|
77
76
|
}
|
78
77
|
async handleActionResults(actionsResult) {
|
79
78
|
const synthesizer = new synthesizer_1.Synthesizer();
|
80
|
-
for (const action of actionsResult.data) {
|
81
|
-
if (!action.error) {
|
82
|
-
await this.cacheMemory?.createMemory({
|
83
|
-
content: actionsResult.initialPrompt,
|
84
|
-
data: action.result,
|
85
|
-
scope: types_1.MemoryScope.GLOBAL,
|
86
|
-
type: types_1.MemoryType.ACTION,
|
87
|
-
});
|
88
|
-
}
|
89
|
-
}
|
90
|
-
const accumulatedResults = this.accumulatedResults;
|
91
79
|
return this.stream
|
92
|
-
? (await synthesizer.streamProcess(actionsResult.initialPrompt,
|
93
|
-
: await synthesizer.process(actionsResult.initialPrompt,
|
80
|
+
? (await synthesizer.streamProcess(actionsResult.initialPrompt, this.formatResults(actionsResult.data))).toDataStreamResponse()
|
81
|
+
: await synthesizer.process(actionsResult.initialPrompt, this.formatResults(actionsResult.data));
|
94
82
|
}
|
95
83
|
transformActions(actions) {
|
96
84
|
let predefinedActions = queue_item_transformer_1.QueueItemTransformer.transformActionsToQueueItems(actions) || [];
|
97
85
|
return predefinedActions;
|
98
86
|
}
|
87
|
+
formatResults(results) {
|
88
|
+
return results.map((result) => ({
|
89
|
+
...result,
|
90
|
+
result: typeof result.result === "object"
|
91
|
+
? JSON.stringify(result.result)
|
92
|
+
: result.result,
|
93
|
+
}));
|
94
|
+
}
|
99
95
|
}
|
100
96
|
exports.Agent = Agent;
|