praisonai 1.0.5 → 1.0.7

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.
@@ -7,7 +7,7 @@ export interface SimpleAgentConfig {
7
7
  }
8
8
  export declare class Agent {
9
9
  private instructions;
10
- private name;
10
+ name: string;
11
11
  private verbose;
12
12
  private llm;
13
13
  private markdown;
@@ -15,6 +15,8 @@ export declare class Agent {
15
15
  private result;
16
16
  constructor(config: SimpleAgentConfig);
17
17
  private createSystemPrompt;
18
+ start(prompt: string, previousResult?: string): Promise<string>;
19
+ chat(prompt: string, previousResult?: string): Promise<string>;
18
20
  execute(previousResult?: string): Promise<string>;
19
21
  getResult(): string | null;
20
22
  }
@@ -31,5 +33,6 @@ export declare class PraisonAIAgents {
31
33
  private process;
32
34
  constructor(config: PraisonAIAgentsConfig);
33
35
  start(): Promise<string[]>;
36
+ chat(): Promise<string[]>;
34
37
  private executeSequential;
35
38
  }
@@ -13,33 +13,40 @@ class Agent {
13
13
  this.llmService = new openai_1.OpenAIService(this.llm);
14
14
  }
15
15
  createSystemPrompt() {
16
- return `You are an AI assistant tasked with helping users with their requests.
16
+ return `${this.instructions}
17
17
  Please provide detailed, accurate, and helpful responses.
18
18
  Format your response in markdown if appropriate.`;
19
19
  }
20
- async execute(previousResult) {
20
+ async start(prompt, previousResult) {
21
21
  if (this.verbose) {
22
- console.log(`Agent ${this.name} executing instructions: ${this.instructions}`);
22
+ console.log(`Agent ${this.name} starting with prompt: ${prompt}`);
23
23
  }
24
24
  try {
25
25
  // Replace placeholder with previous result if available
26
- const finalInstructions = previousResult
27
- ? this.instructions.replace('{previous_result}', previousResult)
28
- : this.instructions;
26
+ const finalPrompt = previousResult
27
+ ? prompt.replace('{previous_result}', previousResult)
28
+ : prompt;
29
29
  if (this.verbose) {
30
30
  console.log('Generating response (streaming)...');
31
- await this.llmService.streamText(finalInstructions, this.createSystemPrompt(), 0.7, (token) => process.stdout.write(token));
31
+ await this.llmService.streamText(finalPrompt, this.createSystemPrompt(), 0.7, (token) => process.stdout.write(token));
32
32
  console.log('\n');
33
33
  }
34
34
  // Get the final response
35
- this.result = await this.llmService.generateText(finalInstructions, this.createSystemPrompt());
35
+ this.result = await this.llmService.generateText(finalPrompt, this.createSystemPrompt());
36
36
  return this.result;
37
37
  }
38
38
  catch (error) {
39
- console.error(`Error executing instructions: ${error}`);
39
+ console.error(`Error executing prompt: ${error}`);
40
40
  throw error;
41
41
  }
42
42
  }
43
+ async chat(prompt, previousResult) {
44
+ return this.start(prompt, previousResult);
45
+ }
46
+ async execute(previousResult) {
47
+ // For backward compatibility and multi-agent support
48
+ return this.start(this.instructions, previousResult);
49
+ }
43
50
  getResult() {
44
51
  return this.result;
45
52
  }
@@ -58,7 +65,7 @@ class PraisonAIAgents {
58
65
  }
59
66
  let results;
60
67
  if (this.process === 'parallel') {
61
- results = await Promise.all(this.tasks.map((task, index) => this.agents[index].execute()));
68
+ results = await Promise.all(this.tasks.map((task, index) => this.agents[index].start(task)));
62
69
  }
63
70
  else {
64
71
  results = await this.executeSequential();
@@ -72,13 +79,20 @@ class PraisonAIAgents {
72
79
  }
73
80
  return results;
74
81
  }
82
+ async chat() {
83
+ return this.start();
84
+ }
75
85
  async executeSequential() {
76
86
  const results = [];
77
- let previousResult = undefined;
78
- for (let i = 0; i < this.tasks.length; i++) {
79
- const result = await this.agents[i].execute(previousResult);
87
+ for (let i = 0; i < this.agents.length; i++) {
88
+ const agent = this.agents[i];
89
+ const task = this.tasks[i];
90
+ const previousResult = i > 0 ? results[i - 1] : undefined;
91
+ if (this.verbose) {
92
+ console.log(`Agent ${agent.name} starting with prompt: ${task}`);
93
+ }
94
+ const result = await agent.start(task, previousResult);
80
95
  results.push(result);
81
- previousResult = result;
82
96
  }
83
97
  return results;
84
98
  }
@@ -136,9 +136,11 @@ class PraisonAIAgents {
136
136
  return results;
137
137
  }
138
138
  async executeHierarchical() {
139
+ const startTime = process.env.LOGLEVEL === 'debug' ? Date.now() : 0;
139
140
  logger_1.Logger.debug('Starting hierarchical execution');
140
141
  const results = [];
141
142
  for (const task of this.tasks) {
143
+ const taskStartTime = process.env.LOGLEVEL === 'debug' ? Date.now() : 0;
142
144
  if (!task.agent)
143
145
  throw new Error(`No agent assigned to task: ${task.name}`);
144
146
  logger_1.Logger.debug(`Executing task: ${task.name}`, {
@@ -149,8 +151,14 @@ class PraisonAIAgents {
149
151
  const result = await task.agent.execute(task, depResults);
150
152
  results.push(result);
151
153
  task.result = result;
154
+ if (process.env.LOGLEVEL === 'debug') {
155
+ logger_1.Logger.debug(`Task execution time for ${task.name}: ${Date.now() - taskStartTime}ms`);
156
+ }
152
157
  logger_1.Logger.debug(`Completed task: ${task.name}`, { result });
153
158
  }
159
+ if (process.env.LOGLEVEL === 'debug') {
160
+ logger_1.Logger.debug(`Total hierarchical execution time: ${Date.now() - startTime}ms`);
161
+ }
154
162
  return results;
155
163
  }
156
164
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "praisonai",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "PraisonAI TypeScript AI Agents Framework - Node.js, npm, and Javascript AI Agents Framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",