praisonai 1.0.13 → 1.0.15

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,9 @@ export interface ProxyAgentConfig extends Partial<SimpleAgentConfig>, Partial<Ta
7
7
  export declare class Agent {
8
8
  private simpleAgent;
9
9
  private taskAgent;
10
+ private instructions;
10
11
  constructor(config: ProxyAgentConfig);
12
+ getInstructions(): string;
11
13
  execute(input: Task | string): Promise<any>;
12
14
  start(prompt: string, previousResult?: string): Promise<string>;
13
15
  chat(prompt: string, previousResult?: string): Promise<string>;
@@ -8,6 +8,7 @@ class Agent {
8
8
  constructor(config) {
9
9
  this.simpleAgent = null;
10
10
  this.taskAgent = null;
11
+ this.instructions = config.instructions || '';
11
12
  // Auto-detect mode based on task presence
12
13
  if (config.task) {
13
14
  const taskConfig = {
@@ -23,7 +24,7 @@ class Agent {
23
24
  }
24
25
  else {
25
26
  const simpleConfig = {
26
- instructions: config.instructions || '',
27
+ instructions: this.instructions,
27
28
  name: config.name,
28
29
  verbose: config.verbose,
29
30
  llm: config.llm,
@@ -32,6 +33,9 @@ class Agent {
32
33
  this.simpleAgent = new simple_1.Agent(simpleConfig);
33
34
  }
34
35
  }
36
+ getInstructions() {
37
+ return this.instructions;
38
+ }
35
39
  async execute(input) {
36
40
  if (this.taskAgent) {
37
41
  const task = input;
@@ -82,9 +86,9 @@ class PraisonAIAgents {
82
86
  this.simpleImpl = null;
83
87
  this.taskImpl = null;
84
88
  // Auto-detect mode based on tasks type
85
- if (Array.isArray(config.tasks) && config.tasks.length > 0) {
86
- // If tasks are strings, use simple mode
87
- if (typeof config.tasks[0] === 'string') {
89
+ if (Array.isArray(config.tasks)) {
90
+ // If tasks are provided and are strings, use simple mode
91
+ if (config.tasks.length > 0 && typeof config.tasks[0] === 'string') {
88
92
  this.simpleImpl = new simple_1.PraisonAIAgents({
89
93
  agents: config.agents,
90
94
  tasks: config.tasks,
@@ -92,8 +96,8 @@ class PraisonAIAgents {
92
96
  process: config.process
93
97
  });
94
98
  }
95
- else {
96
- // Otherwise, use task mode
99
+ else if (config.tasks.length > 0) {
100
+ // If tasks are provided but not strings, use task mode
97
101
  this.taskImpl = new types_1.PraisonAIAgents({
98
102
  agents: config.agents,
99
103
  tasks: config.tasks,
@@ -103,8 +107,13 @@ class PraisonAIAgents {
103
107
  });
104
108
  }
105
109
  }
106
- else {
107
- throw new Error('No tasks provided');
110
+ // If no tasks provided, create simple implementation with auto-generated tasks
111
+ if (!this.simpleImpl && !this.taskImpl) {
112
+ this.simpleImpl = new simple_1.PraisonAIAgents({
113
+ agents: config.agents,
114
+ verbose: config.verbose,
115
+ process: config.process
116
+ });
108
117
  }
109
118
  }
110
119
  async start() {
@@ -22,10 +22,11 @@ export declare class Agent {
22
22
  chat(prompt: string, previousResult?: string): Promise<string>;
23
23
  execute(previousResult?: string): Promise<string>;
24
24
  getResult(): string | null;
25
+ getInstructions(): string;
25
26
  }
26
27
  export interface PraisonAIAgentsConfig {
27
28
  agents: Agent[];
28
- tasks: string[];
29
+ tasks?: string[];
29
30
  verbose?: boolean;
30
31
  pretty?: boolean;
31
32
  process?: 'sequential' | 'parallel';
@@ -37,7 +38,8 @@ export declare class PraisonAIAgents {
37
38
  private pretty;
38
39
  private process;
39
40
  constructor(config: PraisonAIAgentsConfig);
41
+ private generateTasks;
42
+ private executeSequential;
40
43
  start(): Promise<string[]>;
41
44
  chat(): Promise<string[]>;
42
- private executeSequential;
43
45
  }
@@ -60,51 +60,75 @@ class Agent {
60
60
  getResult() {
61
61
  return null;
62
62
  }
63
+ getInstructions() {
64
+ return this.instructions;
65
+ }
63
66
  }
64
67
  exports.Agent = Agent;
65
68
  class PraisonAIAgents {
66
69
  constructor(config) {
67
70
  this.agents = config.agents;
68
- this.tasks = config.tasks;
69
- this.verbose = config.verbose || false;
70
- this.pretty = config.pretty || false;
71
+ this.verbose = config.verbose ?? process.env.PRAISON_VERBOSE !== 'false';
72
+ this.pretty = config.pretty ?? process.env.PRAISON_PRETTY === 'true';
71
73
  this.process = config.process || 'sequential';
74
+ // Auto-generate tasks if not provided
75
+ this.tasks = config.tasks || this.generateTasks();
72
76
  // Configure logging
73
- logger_1.Logger.setVerbose(config.verbose ?? process.env.PRAISON_VERBOSE !== 'false');
74
- logger_1.Logger.setPretty(config.pretty ?? process.env.PRAISON_PRETTY === 'true');
77
+ logger_1.Logger.setVerbose(this.verbose);
78
+ logger_1.Logger.setPretty(this.pretty);
79
+ }
80
+ generateTasks() {
81
+ return this.agents.map(agent => {
82
+ const instructions = agent.getInstructions();
83
+ // Extract task from instructions - get first sentence or whole instruction if no period
84
+ const task = instructions.split('.')[0].trim();
85
+ return task;
86
+ });
87
+ }
88
+ async executeSequential() {
89
+ const results = [];
90
+ let previousResult;
91
+ for (let i = 0; i < this.agents.length; i++) {
92
+ const agent = this.agents[i];
93
+ const task = this.tasks[i];
94
+ await logger_1.Logger.debug(`Running agent ${i + 1}: ${agent.name}`);
95
+ await logger_1.Logger.debug(`Task: ${task}`);
96
+ // For first agent, use task directly
97
+ // For subsequent agents, append previous result to their instructions
98
+ const prompt = i === 0 ? task : `${task}\n\nHere is the input: ${previousResult}`;
99
+ const result = await agent.start(prompt, previousResult);
100
+ results.push(result);
101
+ previousResult = result;
102
+ }
103
+ return results;
75
104
  }
76
105
  async start() {
77
106
  await logger_1.Logger.debug('Starting PraisonAI Agents execution...');
107
+ await logger_1.Logger.debug('Process mode:', this.process);
108
+ await logger_1.Logger.debug('Tasks:', this.tasks);
78
109
  let results;
79
110
  if (this.process === 'parallel') {
80
- results = await Promise.all(this.tasks.map((task, index) => this.agents[index].start(task)));
111
+ // Run all agents in parallel
112
+ const promises = this.agents.map((agent, i) => {
113
+ const task = this.tasks[i];
114
+ return agent.start(task);
115
+ });
116
+ results = await Promise.all(promises);
81
117
  }
82
118
  else {
119
+ // Run agents sequentially (default)
83
120
  results = await this.executeSequential();
84
121
  }
85
122
  if (this.verbose) {
86
- console.log('PraisonAI Agents execution completed.');
87
- results.forEach((result, index) => {
88
- console.log(`\nResult from Agent ${index + 1}:`);
89
- console.log(result);
90
- });
123
+ await logger_1.Logger.info('PraisonAI Agents execution completed.');
124
+ for (let i = 0; i < results.length; i++) {
125
+ await logger_1.Logger.section(`Result from Agent ${i + 1}`, results[i]);
126
+ }
91
127
  }
92
128
  return results;
93
129
  }
94
130
  async chat() {
95
131
  return this.start();
96
132
  }
97
- async executeSequential() {
98
- const results = [];
99
- for (let i = 0; i < this.agents.length; i++) {
100
- const agent = this.agents[i];
101
- const task = this.tasks[i];
102
- const previousResult = i > 0 ? results[i - 1] : undefined;
103
- await logger_1.Logger.info(`Agent ${agent.name} starting with prompt: ${task}`);
104
- const result = await agent.start(task, previousResult);
105
- results.push(result);
106
- }
107
- return results;
108
- }
109
133
  }
110
134
  exports.PraisonAIAgents = PraisonAIAgents;
@@ -20,7 +20,7 @@ async function getOpenAIClient() {
20
20
  openAIInstance = new openai_1.default({
21
21
  apiKey: process.env.OPENAI_API_KEY
22
22
  });
23
- await logger_1.Logger.success('OpenAI client initialized');
23
+ await logger_1.Logger.debug('OpenAI client initialized');
24
24
  }
25
25
  return openAIInstance;
26
26
  }
@@ -113,7 +113,7 @@ class OpenAIService {
113
113
  fullResponse += token;
114
114
  onToken(token);
115
115
  }
116
- await logger_1.Logger.success('Stream completed successfully');
116
+ await logger_1.Logger.debug('Stream completed successfully');
117
117
  }
118
118
  catch (error) {
119
119
  await logger_1.Logger.error('Error in text stream', error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "praisonai",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
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",