@ai.ntellect/core 0.1.101 ā†’ 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
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
- summaryData
184
+ this.accumulatedResults
207
185
  )
208
186
  ).toDataStreamResponse()
209
187
  : await synthesizer.process(
@@ -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;
@@ -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
- ? `Examples: ${action.examples
10
- .map((e) => {
11
- return `Role: ${e.role}, Content: ${e.content}, Parameters: ${e.parameters
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
  });
@@ -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
+ prompt,
106
+ onFinish: (event) => {
107
+ console.log("\nāœ… Streaming synthesis completed");
108
+ if (onFinish) onFinish(event);
109
+ },
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.101",
3
+ "version": "0.2.0",
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;
@@ -9,15 +9,11 @@ export const injectActions = (actions: ActionSchema[]) => {
9
9
  action.description
10
10
  }, Arguments (STRICTLY REQUIRED): { ${schemaShape} } ${
11
11
  action.examples
12
- ? `Examples: ${action.examples
13
- .map((e: any) => {
14
- return `Role: ${e.role}, Content: ${e.content}, Parameters: ${
15
- e.parameters
16
- ? `{ ${Object.keys(e.parameters).join(", ")} }`
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;