@ai.ntellect/core 0.1.102 → 0.2.1

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 CHANGED
@@ -12,31 +12,10 @@ import {
12
12
  User,
13
13
  } from "../types";
14
14
  import { QueueItemTransformer } from "../utils/queue-item-transformer";
15
- import { ResultSanitizer } from "../utils/sanitize-results";
16
15
  import { ActionHandler } from "./handlers/ActionHandler";
17
16
 
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
17
  export class Agent {
38
18
  private readonly actionHandler: ActionHandler;
39
- private readonly user: User;
40
19
  private readonly orchestrator: Orchestrator;
41
20
  private readonly persistentMemory: PersistentMemory;
42
21
  private readonly cacheMemory: CacheMemory | undefined;
@@ -46,7 +25,6 @@ export class Agent {
46
25
  private accumulatedResults: QueueResult[] = [];
47
26
 
48
27
  constructor({
49
- user,
50
28
  orchestrator,
51
29
  persistentMemory,
52
30
  cacheMemory,
@@ -60,7 +38,6 @@ export class Agent {
60
38
  stream: boolean;
61
39
  maxEvaluatorIteration: number;
62
40
  }) {
63
- this.user = user;
64
41
  this.orchestrator = orchestrator;
65
42
  this.cacheMemory = cacheMemory;
66
43
  this.persistentMemory = persistentMemory;
@@ -180,13 +157,6 @@ export class Agent {
180
157
  initialPrompt: string;
181
158
  }) {
182
159
  const synthesizer = new Synthesizer();
183
- const sanitizedResults = ResultSanitizer.sanitize(this.accumulatedResults);
184
- const summaryData = JSON.stringify({
185
- result: sanitizedResults,
186
- });
187
-
188
- this.accumulatedResults = [];
189
- this.evaluatorIteration = 0;
190
160
 
191
161
  for (const action of actionsResult.data) {
192
162
  if (!action.error) {
@@ -199,16 +169,20 @@ export class Agent {
199
169
  }
200
170
  }
201
171
 
172
+ const accumulatedResults = this.accumulatedResults;
173
+ this.accumulatedResults = [];
174
+ this.evaluatorIteration = 0;
175
+
202
176
  return this.stream
203
177
  ? (
204
178
  await synthesizer.streamProcess(
205
179
  actionsResult.initialPrompt,
206
- summaryData
180
+ accumulatedResults
207
181
  )
208
182
  ).toDataStreamResponse()
209
183
  : await synthesizer.process(
210
184
  actionsResult.initialPrompt,
211
- this.accumulatedResults
185
+ accumulatedResults
212
186
  );
213
187
  }
214
188
 
@@ -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 { ActionSchema, AgentEvent, QueueResult, User } from "../types";
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({ user, orchestrator, persistentMemory, cacheMemory, stream, maxEvaluatorIteration, }: {
14
+ constructor({ orchestrator, persistentMemory, cacheMemory, stream, maxEvaluatorIteration, }: {
34
15
  user: User;
35
16
  orchestrator: Orchestrator;
36
17
  persistentMemory: PersistentMemory;
@@ -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({ user, orchestrator, persistentMemory, cacheMemory, stream, maxEvaluatorIteration = 1, }) {
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, summaryData)).toDataStreamResponse()
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 "../../agent";
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, summaryData?: string, onFinish?: (event: any) => void): Promise<any>;
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, summaryData, onFinish) {
68
+ async streamProcess(prompt, results, onFinish) {
69
69
  console.log("\nšŸŽØ Starting streaming synthesis");
70
70
  console.log("Prompt:", prompt);
71
- // if (summaryData) {
72
- // console.log(
73
- // "Summary data:",
74
- // JSON.stringify(JSON.parse(summaryData), null, 2)
75
- // );
76
- // }
77
- // const result = await streamText({
78
- // model: this.model,
79
- // prompt: synthesizerContext.compose(prompt, summaryData || ""),
80
- // onFinish: (event) => {
81
- // console.log("\nāœ… Streaming synthesis completed");
82
- // if (onFinish) onFinish(event);
83
- // },
84
- // system: synthesizerContext.role,
85
- // });
86
- // return result;
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;
@@ -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";
@@ -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 "../../agent";
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
- summaryData?: string,
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
- // const result = await streamText({
105
- // model: this.model,
106
- // prompt: synthesizerContext.compose(prompt, summaryData || ""),
107
- // onFinish: (event) => {
108
- // console.log("\nāœ… Streaming synthesis completed");
109
- // if (onFinish) onFinish(event);
110
- // },
111
- // system: synthesizerContext.role,
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
+ onFinish: (event) => {
106
+ console.log("\nāœ… Streaming synthesis completed");
107
+ if (onFinish) onFinish(event);
108
+ },
109
+ prompt,
110
+ system: context,
111
+ });
113
112
 
114
- // return result;
113
+ return result;
115
114
  }
116
115
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai.ntellect/core",
3
- "version": "0.1.102",
3
+ "version": "0.2.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
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;