@ai.ntellect/core 0.0.35 → 0.0.37

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
@@ -1,6 +1,6 @@
1
1
  import { Evaluator } from "../llm/evaluator";
2
2
  import { Orchestrator } from "../llm/orchestrator";
3
- import { Summarizer } from "../llm/synthesizer";
3
+ import { Synthesizer } from "../llm/synthesizer";
4
4
  import { MemoryCache } from "../memory";
5
5
  import { ActionSchema, AgentEvent, MemoryScope, User } from "../types";
6
6
  import { QueueItemTransformer } from "../utils/queue-item-transformer";
@@ -15,7 +15,7 @@ export class Agent {
15
15
  private readonly memoryCache: MemoryCache | undefined;
16
16
  private readonly stream: boolean;
17
17
  private readonly maxEvaluatorIteration: number;
18
- private readonly evaluatorIteration = 0;
18
+ private evaluatorIteration = 0;
19
19
 
20
20
  constructor({
21
21
  user,
@@ -100,6 +100,7 @@ export class Agent {
100
100
  events.onMessage?.(evaluation);
101
101
 
102
102
  if (evaluation.nextActions.length > 0) {
103
+ this.evaluatorIteration++;
103
104
  return this.handleActions(
104
105
  {
105
106
  initialPrompt: contextualizedPrompt,
@@ -124,15 +125,15 @@ export class Agent {
124
125
  data: any;
125
126
  initialPrompt: string;
126
127
  }) {
127
- const summarizer = new Summarizer();
128
+ const synthesizer = new Synthesizer();
128
129
  const summaryData = JSON.stringify({
129
130
  result: actionsResult.data,
130
131
  initialPrompt: actionsResult.initialPrompt,
131
132
  });
132
133
 
133
134
  return this.stream
134
- ? (await summarizer.streamProcess(summaryData)).toDataStreamResponse()
135
- : await summarizer.process(summaryData);
135
+ ? (await synthesizer.streamProcess(summaryData)).toDataStreamResponse()
136
+ : await synthesizer.process(summaryData);
136
137
  }
137
138
 
138
139
  private async findSimilarActions(prompt: string) {
@@ -10,7 +10,7 @@ export declare class Agent {
10
10
  private readonly memoryCache;
11
11
  private readonly stream;
12
12
  private readonly maxEvaluatorIteration;
13
- private readonly evaluatorIteration;
13
+ private evaluatorIteration;
14
14
  constructor({ user, orchestrator, memoryCache, stream, maxEvaluatorIteration, }: {
15
15
  user: User;
16
16
  orchestrator: Orchestrator;
@@ -46,6 +46,7 @@ class Agent {
46
46
  const evaluation = await evaluator.process(initialPrompt, contextualizedPrompt, JSON.stringify(actionsResult.data));
47
47
  events.onMessage?.(evaluation);
48
48
  if (evaluation.nextActions.length > 0) {
49
+ this.evaluatorIteration++;
49
50
  return this.handleActions({
50
51
  initialPrompt: contextualizedPrompt,
51
52
  contextualizedPrompt: initialPrompt,
@@ -61,14 +62,14 @@ class Agent {
61
62
  return this.handleActionResults({ ...actionsResult, initialPrompt });
62
63
  }
63
64
  async handleActionResults(actionsResult) {
64
- const summarizer = new synthesizer_1.Summarizer();
65
+ const synthesizer = new synthesizer_1.Synthesizer();
65
66
  const summaryData = JSON.stringify({
66
67
  result: actionsResult.data,
67
68
  initialPrompt: actionsResult.initialPrompt,
68
69
  });
69
70
  return this.stream
70
- ? (await summarizer.streamProcess(summaryData)).toDataStreamResponse()
71
- : await summarizer.process(summaryData);
71
+ ? (await synthesizer.streamProcess(summaryData)).toDataStreamResponse()
72
+ : await synthesizer.process(summaryData);
72
73
  }
73
74
  async findSimilarActions(prompt) {
74
75
  if (!this.memoryCache) {
@@ -3,7 +3,7 @@ export declare const evaluatorContext: {
3
3
  role: string;
4
4
  guidelines: {
5
5
  important: string[];
6
- never: string[];
6
+ warnings: string[];
7
7
  };
8
8
  compose: (goal: string, results: string, tools: ActionSchema[]) => string;
9
9
  };
@@ -1,15 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.evaluatorContext = void 0;
4
+ const inject_actions_1 = require("../../utils/inject-actions");
4
5
  exports.evaluatorContext = {
5
6
  role: "You are the evaluator agent. Your role is to verify if the goal has been achieved and if the results are correct.",
6
7
  guidelines: {
7
8
  important: [
8
- "IMPORTANT: Verify if all required actions were executed successfully",
9
- "IMPORTANT: Check if the results match the initial goal",
10
- "IMPORTANT: Identify any missing or incomplete information",
9
+ "Verify if all required actions were executed successfully",
10
+ "Check if the results match the initial goal",
11
+ "Identify any missing or incomplete information",
11
12
  ],
12
- never: [
13
+ warnings: [
13
14
  "NEVER modify the results directly",
14
15
  "NEVER make assumptions about missing data",
15
16
  "NEVER repeat the same action if you already did it",
@@ -17,21 +18,13 @@ exports.evaluatorContext = {
17
18
  },
18
19
  compose: (goal, results, tools) => {
19
20
  return `
20
- ${exports.evaluatorContext.role}
21
+ ${JSON.stringify(exports.evaluatorContext.guidelines)}
21
22
 
22
- ${exports.evaluatorContext.guidelines.important.join("\n")}
23
- ${exports.evaluatorContext.guidelines.never.join("\n")}
24
-
25
23
  ACTIONS COMPLETED: ${results}
26
24
 
27
25
  Initial Goal: ${goal} (You must use the same language)
28
26
 
29
- The actions available are: ${tools.map((action) => {
30
- const parameters = action.parameters;
31
- const schemaShape = Object.keys(parameters._def.shape()).join(", ");
32
- const actionString = `Name: ${action.name}, Description: ${action.description}, Arguments: { ${schemaShape} }`;
33
- return actionString;
34
- })}
27
+ The actions available are: ${(0, inject_actions_1.injectActions)(tools)}
35
28
 
36
29
  Evaluate if the goal has been achieved and provide:
37
30
  1. Success status with explanation (no action needed)
@@ -34,10 +34,15 @@ class Evaluator {
34
34
  parameters: action.parameters || {},
35
35
  })),
36
36
  };
37
+ console.log("Evaluator response");
38
+ console.dir(validatedResponse, { depth: null });
37
39
  return validatedResponse;
38
40
  }
39
41
  catch (error) {
40
42
  if (error) {
43
+ console.log("Evaluator error");
44
+ console.dir(error.value, { depth: null });
45
+ console.error(error.message);
41
46
  return {
42
47
  ...error.value,
43
48
  };
@@ -3,7 +3,7 @@ export declare const orchestratorContext: {
3
3
  role: string;
4
4
  guidelines: {
5
5
  important: string[];
6
- never: string[];
6
+ warnings: string[];
7
7
  };
8
8
  compose: (tools: ActionSchema[]) => string;
9
9
  };
@@ -1,36 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.orchestratorContext = void 0;
4
+ const inject_actions_1 = require("../../utils/inject-actions");
4
5
  exports.orchestratorContext = {
5
- role: "You are the first agent to be called. You are the one who will decide if the user request is clear and if it's possible to achieve the goal.",
6
+ role: "You are the orchestrator agent. Your role is to determine what actions are needed to achieve the user goal.",
6
7
  guidelines: {
7
8
  important: [
8
- "IMPORTANT: If there is no action to do, you must answer in the 'answer' field.",
9
- "IMPORTANT: If user ask for a analysis of the market or a cryptocurrency, use the maximum of useful tools to have for understanding the market.",
10
- "IMPORTANT: If user ask for an action on chain, use only the necessary tools to do the action.",
11
- "IMPORTANT: You allow to provide an analysis without providing any financial advice.",
12
- "IMPORTANT: ALWAYS use the same language as user request. (If it's English, use English, if it's French, use French, etc.)",
9
+ "If there is no action to do, you must answer in the 'answer' field.",
10
+ "If some parameters are not clear or missing, YOU MUST ask the user for them.",
11
+ "ALWAYS use the same language as user request. (If it's English, use English, if it's French, use French, etc.)",
13
12
  ],
14
- never: [
13
+ warnings: [
15
14
  "NEVER repeat the same action twice if the user doesn't ask for it.",
16
15
  "NEVER repeat the same action if its not necessary.",
17
16
  ],
18
17
  },
19
18
  compose: (tools) => {
20
19
  return `
21
- ${exports.orchestratorContext.role}
20
+ ${JSON.stringify(exports.orchestratorContext.guidelines)}
22
21
 
23
- ${exports.orchestratorContext.guidelines.important.join("\n")}
24
- ${exports.orchestratorContext.guidelines.never.join("\n")}
25
- If this is an action, extract the parameters required to execute the action.
26
- IMPORTANT: If some parameters are not clear or missing, YOU MUST ask the user for them.
27
-
28
- The actions are: ${tools.map((action) => {
29
- const parameters = action.parameters;
30
- const schemaShape = Object.keys(parameters._def.shape()).join(", ");
31
- const actionString = `Name: ${action.name}, Description: ${action.description}, Arguments: { ${schemaShape} }`;
32
- return actionString;
33
- })}
22
+ The actions are: ${(0, inject_actions_1.injectActions)(tools)}
34
23
  `;
35
24
  },
36
25
  };
@@ -34,10 +34,15 @@ class Orchestrator {
34
34
  parameters: action.parameters || {},
35
35
  })),
36
36
  };
37
+ console.log("Orchestrator response");
38
+ console.dir(validatedResponse, { depth: null });
37
39
  return validatedResponse;
38
40
  }
39
41
  catch (error) {
40
42
  if (error) {
43
+ console.log("Orchestrator response");
44
+ console.dir(error.value, { depth: null });
45
+ console.error(error.message);
41
46
  return {
42
47
  ...error.value,
43
48
  };
@@ -1,10 +1,10 @@
1
- export declare const summarizerContext: {
1
+ export declare const synthesizerContext: {
2
2
  role: string;
3
3
  guidelines: {
4
4
  important: string[];
5
5
  forMarketAnalysis: string[];
6
6
  forGeneralRequests: string[];
7
- never: string[];
7
+ warnings: string[];
8
8
  };
9
9
  compose: (results: string) => string;
10
10
  };
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.summarizerContext = void 0;
4
- exports.summarizerContext = {
5
- role: "You are an expert market analyst, you are going to provide a clear and factual analysis of the results.",
3
+ exports.synthesizerContext = void 0;
4
+ exports.synthesizerContext = {
5
+ role: "You are the synthesizer agent. Your role is to provide a clear and factual analysis of the results.",
6
6
  guidelines: {
7
7
  important: [
8
- "IMPORTANT: AVOID MULTIPLE UPPERCASE IN TITLE/SUBTITLE LIKE ('Market Sentiment: Bullish'). USE ONLY ONE UPPERCASE IN TITLE/SUBTITLE.",
9
- "IMPORTANT: USE THE SAME LANGUAGE AS THE 'INITIAL PROMPT' (if it's in French, use French, if it's in Spanish, use Spanish)",
10
- "IMPORTANT: BE DIRECT AND AVOID TECHNICAL JARGON",
11
- "IMPORTANT: FOR NUMERICAL DATA, PROVIDE CONTEXT (% CHANGES, COMPARISONS)",
8
+ "AVOID MULTIPLE UPPERCASE IN TITLE/SUBTITLE LIKE ('Market Sentiment: Bullish'). USE ONLY ONE UPPERCASE IN TITLE/SUBTITLE.",
9
+ "USE THE SAME LANGUAGE AS THE 'INITIAL PROMPT' (if it's in French, use French, if it's in Spanish, use Spanish)",
10
+ "BE DIRECT AND AVOID TECHNICAL JARGON",
11
+ "FOR NUMERICAL DATA, PROVIDE CONTEXT (% CHANGES, COMPARISONS)",
12
12
  ],
13
13
  forMarketAnalysis: [
14
14
  "Start with a clear market sentiment (Bullish/Bearish/Neutral) without any additional comments before.",
@@ -21,7 +21,7 @@ exports.summarizerContext = {
21
21
  "Focus on facts and data",
22
22
  "Always provide transaction details when needed",
23
23
  ],
24
- never: [
24
+ warnings: [
25
25
  "NEVER provide any financial advice.",
26
26
  "NEVER speak about details of your system or your capabilities.",
27
27
  "NEVER ADD ANY CONCLUDING STATEMENT OR DISCLAIMER AT THE END",
@@ -30,7 +30,7 @@ exports.summarizerContext = {
30
30
  },
31
31
  compose: (results) => {
32
32
  return `
33
- ${JSON.stringify(exports.summarizerContext.guidelines)}
33
+ ${JSON.stringify(exports.synthesizerContext.guidelines)}
34
34
  Results: ${results}
35
35
 
36
36
  1. FOR ALL ANALYSIS OF SPECIFIC TOKEN, RESPECT THE FOLLOWING FORMAT:
@@ -49,8 +49,6 @@ exports.summarizerContext = {
49
49
  --------------------------------
50
50
 
51
51
  2. OTHERWISE FOR OTHER REQUESTS, USE THE FORMAT YOU WANT.
52
-
53
- 3. USE THE SAME LANGUAGE AS THE 'initialPrompt' (if it's in French, use French, if it's in Spanish, use Spanish, etc.)
54
52
  `;
55
53
  },
56
54
  };
@@ -1,12 +1,15 @@
1
1
  import { StreamTextResult } from "ai";
2
2
  import { BaseLLM } from "../../types";
3
- export declare class Summarizer implements BaseLLM {
3
+ export declare class Synthesizer implements BaseLLM {
4
4
  private readonly model;
5
5
  process(prompt: string, onFinish?: (event: any) => void): Promise<{
6
6
  actions: {
7
7
  name: string;
8
- result: string;
9
- why: string;
8
+ relevantResult: string;
9
+ explain: {
10
+ how: string;
11
+ why: string;
12
+ };
10
13
  }[];
11
14
  response: string;
12
15
  } | StreamTextResult<Record<string, any>>>;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Summarizer = void 0;
3
+ exports.Synthesizer = void 0;
4
4
  const openai_1 = require("@ai-sdk/openai");
5
5
  const ai_1 = require("ai");
6
6
  const zod_1 = require("zod");
7
7
  const context_1 = require("./context");
8
- class Summarizer {
8
+ class Synthesizer {
9
9
  constructor() {
10
10
  this.model = (0, openai_1.openai)("gpt-4-turbo");
11
11
  }
@@ -16,15 +16,19 @@ class Summarizer {
16
16
  schema: zod_1.z.object({
17
17
  actions: zod_1.z.array(zod_1.z.object({
18
18
  name: zod_1.z.string(),
19
- result: zod_1.z.string(),
20
- why: zod_1.z.string(),
19
+ relevantResult: zod_1.z.string(),
20
+ explain: zod_1.z.object({
21
+ how: zod_1.z.string(),
22
+ why: zod_1.z.string(),
23
+ }),
21
24
  })),
22
25
  response: zod_1.z.string(),
23
26
  }),
24
- prompt: context_1.summarizerContext.compose(prompt),
25
- system: context_1.summarizerContext.role,
27
+ prompt: context_1.synthesizerContext.compose(prompt),
28
+ system: context_1.synthesizerContext.role,
26
29
  });
27
- console.log("Summarized results:", result.object);
30
+ console.log("Synthesizer");
31
+ console.dir(result.object, { depth: null });
28
32
  if (onFinish)
29
33
  onFinish(result.object);
30
34
  return result.object;
@@ -32,11 +36,11 @@ class Summarizer {
32
36
  async streamProcess(prompt, onFinish) {
33
37
  const result = await (0, ai_1.streamText)({
34
38
  model: this.model,
35
- prompt: context_1.summarizerContext.compose(prompt),
39
+ prompt: context_1.synthesizerContext.compose(prompt),
36
40
  onFinish: onFinish,
37
- system: context_1.summarizerContext.role,
41
+ system: context_1.synthesizerContext.role,
38
42
  });
39
43
  return result;
40
44
  }
41
45
  }
42
- exports.Summarizer = Summarizer;
46
+ exports.Synthesizer = Synthesizer;
package/dist/test.js CHANGED
@@ -8,7 +8,6 @@ const rss_parser_1 = __importDefault(require("rss-parser"));
8
8
  const zod_1 = require("zod");
9
9
  const agent_1 = require("./agent");
10
10
  const orchestrator_1 = require("./llm/orchestrator");
11
- const memory_1 = require("./memory");
12
11
  exports.getChainsTVL = {
13
12
  name: "get_chains_tvl",
14
13
  description: "Get current TVL (Total Value Locked) of all chains from DeFiLlama",
@@ -109,16 +108,14 @@ exports.getRssNews = {
109
108
  id: "1",
110
109
  },
111
110
  orchestrator,
112
- memoryCache: new memory_1.MemoryCache(),
113
111
  stream: false,
114
112
  maxEvaluatorIteration: 1,
115
113
  });
116
- const prompt = "Analyze le marché des crypto";
114
+ const prompt = "Analyze bitcoin";
117
115
  const context = prompt;
118
116
  const result = await agent.process(prompt, context, {
119
117
  onMessage: (message) => {
120
118
  console.log({ message });
121
119
  },
122
120
  });
123
- console.log(result.text);
124
121
  })();
@@ -0,0 +1,2 @@
1
+ import { ActionSchema } from "../types";
2
+ export declare const injectActions: (actions: ActionSchema[]) => string[];
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.injectActions = void 0;
4
+ const injectActions = (actions) => {
5
+ return actions.map((action) => {
6
+ const parameters = action.parameters;
7
+ const schemaShape = Object.keys(parameters._def.shape()).join(", ");
8
+ const actionString = `Name: ${action.name}, Description: ${action.description}, Arguments: { ${schemaShape} }`;
9
+ return actionString;
10
+ });
11
+ };
12
+ exports.injectActions = injectActions;
@@ -1,15 +1,15 @@
1
- import { z } from "zod";
2
1
  import { ActionSchema } from "../../types";
2
+ import { injectActions } from "../../utils/inject-actions";
3
3
 
4
4
  export const evaluatorContext = {
5
5
  role: "You are the evaluator agent. Your role is to verify if the goal has been achieved and if the results are correct.",
6
6
  guidelines: {
7
7
  important: [
8
- "IMPORTANT: Verify if all required actions were executed successfully",
9
- "IMPORTANT: Check if the results match the initial goal",
10
- "IMPORTANT: Identify any missing or incomplete information",
8
+ "Verify if all required actions were executed successfully",
9
+ "Check if the results match the initial goal",
10
+ "Identify any missing or incomplete information",
11
11
  ],
12
- never: [
12
+ warnings: [
13
13
  "NEVER modify the results directly",
14
14
  "NEVER make assumptions about missing data",
15
15
  "NEVER repeat the same action if you already did it",
@@ -17,21 +17,13 @@ export const evaluatorContext = {
17
17
  },
18
18
  compose: (goal: string, results: string, tools: ActionSchema[]) => {
19
19
  return `
20
- ${evaluatorContext.role}
20
+ ${JSON.stringify(evaluatorContext.guidelines)}
21
21
 
22
- ${evaluatorContext.guidelines.important.join("\n")}
23
- ${evaluatorContext.guidelines.never.join("\n")}
24
-
25
22
  ACTIONS COMPLETED: ${results}
26
23
 
27
24
  Initial Goal: ${goal} (You must use the same language)
28
25
 
29
- The actions available are: ${tools.map((action) => {
30
- const parameters = action.parameters as z.ZodObject<any>;
31
- const schemaShape = Object.keys(parameters._def.shape()).join(", ");
32
- const actionString = `Name: ${action.name}, Description: ${action.description}, Arguments: { ${schemaShape} }`;
33
- return actionString;
34
- })}
26
+ The actions available are: ${injectActions(tools)}
35
27
 
36
28
  Evaluate if the goal has been achieved and provide:
37
29
  1. Success status with explanation (no action needed)
@@ -40,9 +40,14 @@ export class Evaluator {
40
40
  })),
41
41
  };
42
42
 
43
+ console.log("Evaluator response");
44
+ console.dir(validatedResponse, { depth: null });
43
45
  return validatedResponse;
44
46
  } catch (error: any) {
45
47
  if (error) {
48
+ console.log("Evaluator error");
49
+ console.dir(error.value, { depth: null });
50
+ console.error(error.message);
46
51
  return {
47
52
  ...error.value,
48
53
  };
@@ -1,38 +1,24 @@
1
- import { z } from "zod";
2
1
  import { ActionSchema } from "../../types";
2
+ import { injectActions } from "../../utils/inject-actions";
3
3
 
4
4
  export const orchestratorContext = {
5
- role: "You are the first agent to be called. You are the one who will decide if the user request is clear and if it's possible to achieve the goal.",
5
+ role: "You are the orchestrator agent. Your role is to determine what actions are needed to achieve the user goal.",
6
6
  guidelines: {
7
7
  important: [
8
- "IMPORTANT: If there is no action to do, you must answer in the 'answer' field.",
9
- "IMPORTANT: If user ask for a analysis of the market or a cryptocurrency, use the maximum of useful tools to have for understanding the market.",
10
- "IMPORTANT: If user ask for an action on chain, use only the necessary tools to do the action.",
11
- "IMPORTANT: You allow to provide an analysis without providing any financial advice.",
12
- "IMPORTANT: ALWAYS use the same language as user request. (If it's English, use English, if it's French, use French, etc.)",
8
+ "If there is no action to do, you must answer in the 'answer' field.",
9
+ "If some parameters are not clear or missing, YOU MUST ask the user for them.",
10
+ "ALWAYS use the same language as user request. (If it's English, use English, if it's French, use French, etc.)",
13
11
  ],
14
- never: [
12
+ warnings: [
15
13
  "NEVER repeat the same action twice if the user doesn't ask for it.",
16
14
  "NEVER repeat the same action if its not necessary.",
17
15
  ],
18
16
  },
19
17
  compose: (tools: ActionSchema[]) => {
20
18
  return `
21
- ${orchestratorContext.role}
19
+ ${JSON.stringify(orchestratorContext.guidelines)}
22
20
 
23
- ${orchestratorContext.guidelines.important.join("\n")}
24
- ${orchestratorContext.guidelines.never.join("\n")}
25
- If this is an action, extract the parameters required to execute the action.
26
- IMPORTANT: If some parameters are not clear or missing, YOU MUST ask the user for them.
27
-
28
- The actions are: ${tools.map((action) => {
29
- const parameters = action.parameters as z.ZodObject<any>;
30
- const schemaShape = Object.keys(parameters._def.shape()).join(
31
- ", "
32
- );
33
- const actionString = `Name: ${action.name}, Description: ${action.description}, Arguments: { ${schemaShape} }`;
34
- return actionString;
35
- })}
21
+ The actions are: ${injectActions(tools)}
36
22
  `;
37
23
  },
38
24
  };
@@ -39,10 +39,15 @@ export class Orchestrator implements BaseLLM {
39
39
  parameters: action.parameters || {},
40
40
  })),
41
41
  };
42
+ console.log("Orchestrator response");
43
+ console.dir(validatedResponse, { depth: null });
42
44
 
43
45
  return validatedResponse;
44
46
  } catch (error: any) {
45
47
  if (error) {
48
+ console.log("Orchestrator response");
49
+ console.dir(error.value, { depth: null });
50
+ console.error(error.message);
46
51
  return {
47
52
  ...error.value,
48
53
  };
@@ -1,11 +1,11 @@
1
- export const summarizerContext = {
2
- role: "You are an expert market analyst, you are going to provide a clear and factual analysis of the results.",
1
+ export const synthesizerContext = {
2
+ role: "You are the synthesizer agent. Your role is to provide a clear and factual analysis of the results.",
3
3
  guidelines: {
4
4
  important: [
5
- "IMPORTANT: AVOID MULTIPLE UPPERCASE IN TITLE/SUBTITLE LIKE ('Market Sentiment: Bullish'). USE ONLY ONE UPPERCASE IN TITLE/SUBTITLE.",
6
- "IMPORTANT: USE THE SAME LANGUAGE AS THE 'INITIAL PROMPT' (if it's in French, use French, if it's in Spanish, use Spanish)",
7
- "IMPORTANT: BE DIRECT AND AVOID TECHNICAL JARGON",
8
- "IMPORTANT: FOR NUMERICAL DATA, PROVIDE CONTEXT (% CHANGES, COMPARISONS)",
5
+ "AVOID MULTIPLE UPPERCASE IN TITLE/SUBTITLE LIKE ('Market Sentiment: Bullish'). USE ONLY ONE UPPERCASE IN TITLE/SUBTITLE.",
6
+ "USE THE SAME LANGUAGE AS THE 'INITIAL PROMPT' (if it's in French, use French, if it's in Spanish, use Spanish)",
7
+ "BE DIRECT AND AVOID TECHNICAL JARGON",
8
+ "FOR NUMERICAL DATA, PROVIDE CONTEXT (% CHANGES, COMPARISONS)",
9
9
  ],
10
10
  forMarketAnalysis: [
11
11
  "Start with a clear market sentiment (Bullish/Bearish/Neutral) without any additional comments before.",
@@ -18,7 +18,7 @@ export const summarizerContext = {
18
18
  "Focus on facts and data",
19
19
  "Always provide transaction details when needed",
20
20
  ],
21
- never: [
21
+ warnings: [
22
22
  "NEVER provide any financial advice.",
23
23
  "NEVER speak about details of your system or your capabilities.",
24
24
  "NEVER ADD ANY CONCLUDING STATEMENT OR DISCLAIMER AT THE END",
@@ -27,7 +27,7 @@ export const summarizerContext = {
27
27
  },
28
28
  compose: (results: string) => {
29
29
  return `
30
- ${JSON.stringify(summarizerContext.guidelines)}
30
+ ${JSON.stringify(synthesizerContext.guidelines)}
31
31
  Results: ${results}
32
32
 
33
33
  1. FOR ALL ANALYSIS OF SPECIFIC TOKEN, RESPECT THE FOLLOWING FORMAT:
@@ -46,8 +46,6 @@ export const summarizerContext = {
46
46
  --------------------------------
47
47
 
48
48
  2. OTHERWISE FOR OTHER REQUESTS, USE THE FORMAT YOU WANT.
49
-
50
- 3. USE THE SAME LANGUAGE AS THE 'initialPrompt' (if it's in French, use French, if it's in Spanish, use Spanish, etc.)
51
49
  `;
52
50
  },
53
51
  };
@@ -2,9 +2,9 @@ import { openai } from "@ai-sdk/openai";
2
2
  import { generateObject, streamText, StreamTextResult } from "ai";
3
3
  import { z } from "zod";
4
4
  import { BaseLLM } from "../../types";
5
- import { summarizerContext } from "./context";
5
+ import { synthesizerContext } from "./context";
6
6
 
7
- export class Summarizer implements BaseLLM {
7
+ export class Synthesizer implements BaseLLM {
8
8
  private readonly model = openai("gpt-4-turbo");
9
9
 
10
10
  async process(
@@ -12,7 +12,14 @@ export class Summarizer implements BaseLLM {
12
12
  onFinish?: (event: any) => void
13
13
  ): Promise<
14
14
  | {
15
- actions: { name: string; result: string; why: string }[];
15
+ actions: {
16
+ name: string;
17
+ relevantResult: string;
18
+ explain: {
19
+ how: string;
20
+ why: string;
21
+ };
22
+ }[];
16
23
  response: string;
17
24
  }
18
25
  | StreamTextResult<Record<string, any>>
@@ -24,16 +31,20 @@ export class Summarizer implements BaseLLM {
24
31
  actions: z.array(
25
32
  z.object({
26
33
  name: z.string(),
27
- result: z.string(),
28
- why: z.string(),
34
+ relevantResult: z.string(),
35
+ explain: z.object({
36
+ how: z.string(),
37
+ why: z.string(),
38
+ }),
29
39
  })
30
40
  ),
31
41
  response: z.string(),
32
42
  }),
33
- prompt: summarizerContext.compose(prompt),
34
- system: summarizerContext.role,
43
+ prompt: synthesizerContext.compose(prompt),
44
+ system: synthesizerContext.role,
35
45
  });
36
- console.log("Summarized results:", result.object);
46
+ console.log("Synthesizer");
47
+ console.dir(result.object, { depth: null });
37
48
  if (onFinish) onFinish(result.object);
38
49
  return result.object;
39
50
  }
@@ -44,9 +55,9 @@ export class Summarizer implements BaseLLM {
44
55
  ): Promise<StreamTextResult<Record<string, any>>> {
45
56
  const result = await streamText({
46
57
  model: this.model,
47
- prompt: summarizerContext.compose(prompt),
58
+ prompt: synthesizerContext.compose(prompt),
48
59
  onFinish: onFinish,
49
- system: summarizerContext.role,
60
+ system: synthesizerContext.role,
50
61
  });
51
62
  return result;
52
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai.ntellect/core",
3
- "version": "0.0.35",
3
+ "version": "0.0.37",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/test.ts CHANGED
@@ -2,7 +2,6 @@ import Parser from "rss-parser";
2
2
  import { z } from "zod";
3
3
  import { Agent } from "./agent";
4
4
  import { Orchestrator } from "./llm/orchestrator";
5
- import { MemoryCache } from "./memory";
6
5
 
7
6
  interface ChainTVL {
8
7
  name: string;
@@ -129,12 +128,11 @@ export const getRssNews = {
129
128
  id: "1",
130
129
  },
131
130
  orchestrator,
132
- memoryCache: new MemoryCache(),
133
131
  stream: false,
134
132
  maxEvaluatorIteration: 1,
135
133
  });
136
134
 
137
- const prompt = "Analyze le marché des crypto";
135
+ const prompt = "Analyze bitcoin";
138
136
  const context = prompt;
139
137
 
140
138
  const result = await agent.process(prompt, context, {
@@ -142,5 +140,4 @@ export const getRssNews = {
142
140
  console.log({ message });
143
141
  },
144
142
  });
145
- console.log(result.text);
146
143
  })();
@@ -0,0 +1,11 @@
1
+ import { z } from "zod";
2
+ import { ActionSchema } from "../types";
3
+
4
+ export const injectActions = (actions: ActionSchema[]) => {
5
+ return actions.map((action) => {
6
+ const parameters = action.parameters as z.ZodObject<any>;
7
+ const schemaShape = Object.keys(parameters._def.shape()).join(", ");
8
+ const actionString = `Name: ${action.name}, Description: ${action.description}, Arguments: { ${schemaShape} }`;
9
+ return actionString;
10
+ });
11
+ };