@ai.ntellect/core 0.2.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
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
 
@@ -48,6 +41,8 @@ export class Agent {
48
41
  }
49
42
 
50
43
  async process(prompt: string, events: AgentEvent): Promise<any> {
44
+ this.accumulatedResults = [];
45
+ this.evaluatorIteration = 0;
51
46
  console.log("Requesting orchestrator for actions..");
52
47
  const request = await this.orchestrator.process(
53
48
  prompt,
@@ -158,31 +153,16 @@ export class Agent {
158
153
  }) {
159
154
  const synthesizer = new Synthesizer();
160
155
 
161
- for (const action of actionsResult.data) {
162
- if (!action.error) {
163
- await this.cacheMemory?.createMemory({
164
- content: actionsResult.initialPrompt,
165
- data: action.result,
166
- scope: MemoryScope.GLOBAL,
167
- type: MemoryType.ACTION,
168
- });
169
- }
170
- }
171
-
172
- const accumulatedResults = this.accumulatedResults;
173
- this.accumulatedResults = [];
174
- this.evaluatorIteration = 0;
175
-
176
156
  return this.stream
177
157
  ? (
178
158
  await synthesizer.streamProcess(
179
159
  actionsResult.initialPrompt,
180
- accumulatedResults
160
+ this.formatResults(actionsResult.data)
181
161
  )
182
162
  ).toDataStreamResponse()
183
163
  : await synthesizer.process(
184
164
  actionsResult.initialPrompt,
185
- accumulatedResults
165
+ this.formatResults(actionsResult.data)
186
166
  );
187
167
  }
188
168
 
@@ -192,4 +172,14 @@ export class Agent {
192
172
 
193
173
  return predefinedActions;
194
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
+ }
195
185
  }
@@ -23,4 +23,5 @@ export declare class Agent {
23
23
  private handleActions;
24
24
  private handleActionResults;
25
25
  private transformActions;
26
+ private formatResults;
26
27
  }
@@ -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 {
@@ -19,6 +18,8 @@ class Agent {
19
18
  this.accumulatedResults = [];
20
19
  }
21
20
  async process(prompt, events) {
21
+ this.accumulatedResults = [];
22
+ this.evaluatorIteration = 0;
22
23
  console.log("Requesting orchestrator for actions..");
23
24
  const request = await this.orchestrator.process(prompt, this.accumulatedResults);
24
25
  events.onMessage?.(request);
@@ -75,26 +76,21 @@ class Agent {
75
76
  }
76
77
  async handleActionResults(actionsResult) {
77
78
  const synthesizer = new synthesizer_1.Synthesizer();
78
- for (const action of actionsResult.data) {
79
- if (!action.error) {
80
- await this.cacheMemory?.createMemory({
81
- content: actionsResult.initialPrompt,
82
- data: action.result,
83
- scope: types_1.MemoryScope.GLOBAL,
84
- type: types_1.MemoryType.ACTION,
85
- });
86
- }
87
- }
88
- const accumulatedResults = this.accumulatedResults;
89
- this.accumulatedResults = [];
90
- this.evaluatorIteration = 0;
91
79
  return this.stream
92
- ? (await synthesizer.streamProcess(actionsResult.initialPrompt, accumulatedResults)).toDataStreamResponse()
93
- : await synthesizer.process(actionsResult.initialPrompt, accumulatedResults);
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;
@@ -43,6 +43,8 @@ class Evaluator {
43
43
  const response = await (0, ai_1.generateObject)({
44
44
  model: this.model,
45
45
  schema: zod_1.z.object({
46
+ actionsCompleted: zod_1.z.array(zod_1.z.string()),
47
+ actionsFailed: zod_1.z.array(zod_1.z.string()),
46
48
  isRemindNeeded: zod_1.z.boolean(),
47
49
  importantToRemembers: zod_1.z.array(zod_1.z.object({
48
50
  memoryType: zod_1.z.string(),
@@ -26,6 +26,7 @@ class Synthesizer {
26
26
  # STEPS: ${steps?.join("\n") || ""}
27
27
  # MESSAGES EXAMPLES: ${JSON.stringify(examplesMessages, null, 2)}
28
28
  `;
29
+ console.log("Synthesizer Context:", context);
29
30
  return context;
30
31
  }
31
32
  async process(prompt, results, onFinish) {
@@ -50,6 +50,8 @@ export class Evaluator {
50
50
  const response = await generateObject({
51
51
  model: this.model,
52
52
  schema: z.object({
53
+ actionsCompleted: z.array(z.string()),
54
+ actionsFailed: z.array(z.string()),
53
55
  isRemindNeeded: z.boolean(),
54
56
  importantToRemembers: z.array(
55
57
  z.object({
@@ -26,7 +26,7 @@ export class Synthesizer {
26
26
  # STEPS: ${steps?.join("\n") || ""}
27
27
  # MESSAGES EXAMPLES: ${JSON.stringify(examplesMessages, null, 2)}
28
28
  `;
29
-
29
+ console.log("Synthesizer Context:", context);
30
30
  return context;
31
31
  }
32
32
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai.ntellect/core",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {