praisonai 1.0.6 → 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.
- package/dist/agent/simple.d.ts +4 -1
- package/dist/agent/simple.js +28 -14
- package/package.json +1 -1
package/dist/agent/simple.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export interface SimpleAgentConfig {
|
|
|
7
7
|
}
|
|
8
8
|
export declare class Agent {
|
|
9
9
|
private instructions;
|
|
10
|
-
|
|
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
|
}
|
package/dist/agent/simple.js
CHANGED
|
@@ -13,33 +13,40 @@ class Agent {
|
|
|
13
13
|
this.llmService = new openai_1.OpenAIService(this.llm);
|
|
14
14
|
}
|
|
15
15
|
createSystemPrompt() {
|
|
16
|
-
return
|
|
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
|
|
20
|
+
async start(prompt, previousResult) {
|
|
21
21
|
if (this.verbose) {
|
|
22
|
-
console.log(`Agent ${this.name}
|
|
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
|
|
27
|
-
?
|
|
28
|
-
:
|
|
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(
|
|
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(
|
|
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
|
|
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].
|
|
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
|
|
78
|
-
|
|
79
|
-
const
|
|
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
|
}
|