@ai.ntellect/core 0.2.7 → 0.2.8

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
@@ -5,6 +5,7 @@ import { CacheMemory } from "../memory/cache";
5
5
  import { PersistentMemory } from "../memory/persistent";
6
6
  import { ActionSchema, AgentEvent, QueueResult, User } from "../types";
7
7
  import { QueueItemTransformer } from "../utils/queue-item-transformer";
8
+ import { ResultSanitizer } from "../utils/sanitize-results";
8
9
  import { ActionHandler } from "./handlers/ActionHandler";
9
10
 
10
11
  export class Agent {
@@ -15,7 +16,7 @@ export class Agent {
15
16
  private readonly stream: boolean;
16
17
  private readonly maxEvaluatorIteration: number;
17
18
  private evaluatorIteration = 0;
18
- private accumulatedResults: QueueResult[] = [];
19
+ private accumulatedResults: string = "";
19
20
 
20
21
  constructor({
21
22
  orchestrator,
@@ -37,11 +38,11 @@ export class Agent {
37
38
  this.stream = stream;
38
39
  this.maxEvaluatorIteration = maxEvaluatorIteration;
39
40
  this.actionHandler = new ActionHandler();
40
- this.accumulatedResults = [];
41
+ this.accumulatedResults = "";
41
42
  }
42
43
 
43
44
  async process(prompt: string, events: AgentEvent): Promise<any> {
44
- this.accumulatedResults = [];
45
+ this.accumulatedResults = "";
45
46
  this.evaluatorIteration = 0;
46
47
  console.log("Requesting orchestrator for actions..");
47
48
  const request = await this.orchestrator.process(
@@ -92,10 +93,7 @@ export class Agent {
92
93
  }
93
94
  );
94
95
 
95
- this.accumulatedResults = this.formatResults([
96
- ...this.accumulatedResults,
97
- ...actionsResult.data,
98
- ]);
96
+ this.accumulatedResults += this.formatResults(actionsResult.data);
99
97
 
100
98
  const isOnChainAction = actions.some(
101
99
  (action) => action.type === "on-chain"
@@ -146,7 +144,7 @@ export class Agent {
146
144
  }
147
145
 
148
146
  private async handleActionResults(actionsResult: {
149
- data: QueueResult[];
147
+ data: string;
150
148
  initialPrompt: string;
151
149
  }) {
152
150
  const synthesizer = new Synthesizer();
@@ -171,13 +169,15 @@ export class Agent {
171
169
  return predefinedActions;
172
170
  }
173
171
 
174
- private formatResults(results: QueueResult[]): QueueResult[] {
175
- return results.map((result) => ({
172
+ private formatResults(results: QueueResult[]): string {
173
+ const formattedResults = results.map((result) => ({
176
174
  ...result,
177
175
  result:
178
176
  typeof result.result === "object"
179
177
  ? JSON.stringify(result.result)
180
178
  : result.result,
181
179
  }));
180
+ const sanitizedResults = ResultSanitizer.sanitize(formattedResults);
181
+ return sanitizedResults;
182
182
  }
183
183
  }
@@ -4,21 +4,22 @@ exports.Agent = void 0;
4
4
  const evaluator_1 = require("../llm/evaluator");
5
5
  const synthesizer_1 = require("../llm/synthesizer");
6
6
  const queue_item_transformer_1 = require("../utils/queue-item-transformer");
7
+ const sanitize_results_1 = require("../utils/sanitize-results");
7
8
  const ActionHandler_1 = require("./handlers/ActionHandler");
8
9
  class Agent {
9
10
  constructor({ orchestrator, persistentMemory, cacheMemory, stream, maxEvaluatorIteration = 1, }) {
10
11
  this.evaluatorIteration = 0;
11
- this.accumulatedResults = [];
12
+ this.accumulatedResults = "";
12
13
  this.orchestrator = orchestrator;
13
14
  this.cacheMemory = cacheMemory;
14
15
  this.persistentMemory = persistentMemory;
15
16
  this.stream = stream;
16
17
  this.maxEvaluatorIteration = maxEvaluatorIteration;
17
18
  this.actionHandler = new ActionHandler_1.ActionHandler();
18
- this.accumulatedResults = [];
19
+ this.accumulatedResults = "";
19
20
  }
20
21
  async process(prompt, events) {
21
- this.accumulatedResults = [];
22
+ this.accumulatedResults = "";
22
23
  this.evaluatorIteration = 0;
23
24
  console.log("Requesting orchestrator for actions..");
24
25
  const request = await this.orchestrator.process(prompt, this.accumulatedResults);
@@ -39,10 +40,7 @@ class Agent {
39
40
  onQueueComplete: events.onQueueComplete,
40
41
  onConfirmationRequired: events.onConfirmationRequired,
41
42
  });
42
- this.accumulatedResults = this.formatResults([
43
- ...this.accumulatedResults,
44
- ...actionsResult.data,
45
- ]);
43
+ this.accumulatedResults += this.formatResults(actionsResult.data);
46
44
  const isOnChainAction = actions.some((action) => action.type === "on-chain");
47
45
  if (isOnChainAction) {
48
46
  return {
@@ -83,12 +81,14 @@ class Agent {
83
81
  return predefinedActions;
84
82
  }
85
83
  formatResults(results) {
86
- return results.map((result) => ({
84
+ const formattedResults = results.map((result) => ({
87
85
  ...result,
88
86
  result: typeof result.result === "object"
89
87
  ? JSON.stringify(result.result)
90
88
  : result.result,
91
89
  }));
90
+ const sanitizedResults = sanitize_results_1.ResultSanitizer.sanitize(formattedResults);
91
+ return sanitizedResults;
92
92
  }
93
93
  }
94
94
  exports.Agent = Agent;
@@ -1,10 +1,10 @@
1
1
  import { PersistentMemory } from "../../memory/persistent";
2
- import { ActionSchema, QueueResult, State } from "../../types";
2
+ import { ActionSchema, State } from "../../types";
3
3
  export declare class Evaluator {
4
4
  private readonly model;
5
5
  tools: ActionSchema[];
6
6
  private memory;
7
7
  constructor(tools: ActionSchema[], memory: PersistentMemory);
8
8
  composeContext(state: State): string;
9
- process(prompt: string, results: QueueResult[]): Promise<any>;
9
+ process(prompt: string, results: string): Promise<any>;
10
10
  }
@@ -24,10 +24,9 @@ class Evaluator {
24
24
  # NEVER: ${warnings.join("\n")}
25
25
  # USER_REQUEST: ${userRequest}
26
26
  # ACTIONS AVAILABLE: ${(0, inject_actions_1.injectActions)(actions)}
27
- # CURRENT_RESULTS: ${results.map((r) => r.result).join(", ")}
27
+ # CURRENT_RESULTS: ${results}
28
28
  # STEPS: ${steps?.join("\n") || ""}
29
29
  `;
30
- console.log("Evaluator Context:", context);
31
30
  return context;
32
31
  }
33
32
  async process(prompt, results) {
@@ -1,6 +1,6 @@
1
1
  import { CacheMemory } from "../../memory/cache";
2
2
  import { PersistentMemory } from "../../memory/persistent";
3
- import { ActionSchema, QueueResult, State } from "../../types";
3
+ import { ActionSchema, State } from "../../types";
4
4
  export declare class Orchestrator {
5
5
  private readonly model;
6
6
  tools: ActionSchema[];
@@ -11,7 +11,7 @@ export declare class Orchestrator {
11
11
  cache: CacheMemory;
12
12
  });
13
13
  composeContext(state: State): string;
14
- process(prompt: string, results: QueueResult[]): Promise<{
14
+ process(prompt: string, results: string): Promise<{
15
15
  actions: {
16
16
  name: string;
17
17
  type: string;
@@ -79,7 +79,7 @@ class Orchestrator {
79
79
  # IMPORTANT: ${important.join("\n")}
80
80
  # USER_REQUEST: ${userRequest}
81
81
  # ACTIONS_AVAILABLES: ${(0, inject_actions_1.injectActions)(actions)} (NEVER REPEAT ACTIONS)
82
- # CURRENT_RESULTS: ${results.map((r) => r.result).join(", ")}
82
+ # CURRENT_RESULTS: ${results}
83
83
  `.trim();
84
84
  return context;
85
85
  }
@@ -1,14 +1,14 @@
1
1
  import { StreamTextResult } from "ai";
2
- import { QueueResult, State } from "../../types";
2
+ import { State } from "../../types";
3
3
  export declare class Synthesizer {
4
4
  private readonly model;
5
5
  composeContext(state: Partial<State>): string;
6
- process(prompt: string, results: QueueResult[], onFinish?: (event: any) => void): Promise<{
6
+ process(prompt: string, results: string, onFinish?: (event: any) => void): Promise<{
7
7
  actionsCompleted: {
8
8
  name: string;
9
9
  reasoning: string;
10
10
  }[];
11
11
  response: string;
12
12
  } | StreamTextResult<Record<string, any>>>;
13
- streamProcess(prompt: string, results: QueueResult[], onFinish?: (event: any) => void): Promise<any>;
13
+ streamProcess(prompt: string, results: string, onFinish?: (event: any) => void): Promise<any>;
14
14
  }
@@ -22,11 +22,10 @@ class Synthesizer {
22
22
  # IMPORTANT: ${important.join("\n")}
23
23
  # NEVER: ${warnings.join("\n")}
24
24
  # USER_REQUEST: ${userRequest}
25
- # CURRENT_RESULTS: ${results?.map((r) => r.result).join(", ") || ""}
25
+ # CURRENT_RESULTS: ${results}
26
26
  # STEPS: ${steps?.join("\n") || ""}
27
27
  # MESSAGES EXAMPLES: ${JSON.stringify(examplesMessages, null, 2)}
28
28
  `;
29
- console.log("Synthesizer Context:", context);
30
29
  return context;
31
30
  }
32
31
  async process(prompt, results, onFinish) {
package/dist/types.d.ts CHANGED
@@ -57,7 +57,7 @@ export type State = {
57
57
  };
58
58
  userRequest: string;
59
59
  actions: ActionSchema[];
60
- results: QueueResult[];
60
+ results: string;
61
61
  examplesMessages?: {
62
62
  role: string;
63
63
  content: string;
@@ -2,7 +2,7 @@ import { openai } from "@ai-sdk/openai";
2
2
  import { generateObject } from "ai";
3
3
  import { z } from "zod";
4
4
  import { PersistentMemory } from "../../memory/persistent";
5
- import { ActionSchema, MemoryScope, QueueResult, State } from "../../types";
5
+ import { ActionSchema, MemoryScope, State } from "../../types";
6
6
  import { injectActions } from "../../utils/inject-actions";
7
7
  import { evaluatorContext } from "./context";
8
8
 
@@ -28,14 +28,13 @@ export class Evaluator {
28
28
  # NEVER: ${warnings.join("\n")}
29
29
  # USER_REQUEST: ${userRequest}
30
30
  # ACTIONS AVAILABLE: ${injectActions(actions)}
31
- # CURRENT_RESULTS: ${results.map((r) => r.result).join(", ")}
31
+ # CURRENT_RESULTS: ${results}
32
32
  # STEPS: ${steps?.join("\n") || ""}
33
33
  `;
34
- console.log("Evaluator Context:", context);
35
34
  return context;
36
35
  }
37
36
 
38
- async process(prompt: string, results: QueueResult[]): Promise<any> {
37
+ async process(prompt: string, results: string): Promise<any> {
39
38
  try {
40
39
  const context = this.composeContext({
41
40
  behavior: evaluatorContext.behavior,
@@ -3,13 +3,7 @@ import { generateObject } from "ai";
3
3
  import { z } from "zod";
4
4
  import { CacheMemory } from "../../memory/cache";
5
5
  import { PersistentMemory } from "../../memory/persistent";
6
- import {
7
- ActionSchema,
8
- MemoryScope,
9
- MemoryScopeType,
10
- QueueResult,
11
- State,
12
- } from "../../types";
6
+ import { ActionSchema, MemoryScope, MemoryScopeType, State } from "../../types";
13
7
  import { injectActions } from "../../utils/inject-actions";
14
8
  import { orchestratorContext } from "./context";
15
9
 
@@ -118,7 +112,7 @@ export class Orchestrator {
118
112
  # IMPORTANT: ${important.join("\n")}
119
113
  # USER_REQUEST: ${userRequest}
120
114
  # ACTIONS_AVAILABLES: ${injectActions(actions)} (NEVER REPEAT ACTIONS)
121
- # CURRENT_RESULTS: ${results.map((r) => r.result).join(", ")}
115
+ # CURRENT_RESULTS: ${results}
122
116
  `.trim();
123
117
 
124
118
  return context;
@@ -126,7 +120,7 @@ export class Orchestrator {
126
120
 
127
121
  async process(
128
122
  prompt: string,
129
- results: QueueResult[]
123
+ results: string
130
124
  ): Promise<{
131
125
  actions: {
132
126
  name: string;
@@ -1,7 +1,7 @@
1
1
  import { openai } from "@ai-sdk/openai";
2
2
  import { generateObject, streamText, StreamTextResult } from "ai";
3
3
  import { z } from "zod";
4
- import { QueueResult, State } from "../../types";
4
+ import { State } from "../../types";
5
5
  import { synthesizerContext } from "./context";
6
6
 
7
7
  export class Synthesizer {
@@ -22,17 +22,16 @@ export class Synthesizer {
22
22
  # IMPORTANT: ${important.join("\n")}
23
23
  # NEVER: ${warnings.join("\n")}
24
24
  # USER_REQUEST: ${userRequest}
25
- # CURRENT_RESULTS: ${results?.map((r) => r.result).join(", ") || ""}
25
+ # CURRENT_RESULTS: ${results}
26
26
  # STEPS: ${steps?.join("\n") || ""}
27
27
  # MESSAGES EXAMPLES: ${JSON.stringify(examplesMessages, null, 2)}
28
28
  `;
29
- console.log("Synthesizer Context:", context);
30
29
  return context;
31
30
  }
32
31
 
33
32
  async process(
34
33
  prompt: string,
35
- results: QueueResult[],
34
+ results: string,
36
35
  onFinish?: (event: any) => void
37
36
  ): Promise<
38
37
  | {
@@ -89,7 +88,7 @@ export class Synthesizer {
89
88
 
90
89
  async streamProcess(
91
90
  prompt: string,
92
- results: QueueResult[],
91
+ results: string,
93
92
  onFinish?: (event: any) => void
94
93
  ): Promise<any> {
95
94
  console.log("\nšŸŽØ Starting streaming synthesis");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai.ntellect/core",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/types.ts CHANGED
@@ -68,7 +68,7 @@ export type State = {
68
68
  };
69
69
  userRequest: string;
70
70
  actions: ActionSchema[];
71
- results: QueueResult[];
71
+ results: string;
72
72
  examplesMessages?: {
73
73
  role: string;
74
74
  content: string;