praisonai 1.0.0 → 1.0.1
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/README.md +89 -2
- package/dist/agent/agent.d.ts +0 -0
- package/dist/agent/agent.js +1 -0
- package/dist/agent/index.d.ts +5 -0
- package/dist/agent/index.js +13 -0
- package/dist/agent/proxy.d.ts +19 -0
- package/dist/agent/proxy.js +89 -0
- package/dist/agent/simple.d.ts +35 -0
- package/dist/agent/simple.js +86 -0
- package/dist/agent/types.d.ts +56 -0
- package/dist/agent/types.js +157 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +23 -0
- package/dist/knowledge/chunking.d.ts +0 -0
- package/dist/knowledge/chunking.js +1 -0
- package/dist/knowledge/index.d.ts +22 -0
- package/dist/knowledge/index.js +29 -0
- package/dist/knowledge/knowledge.d.ts +0 -0
- package/dist/knowledge/knowledge.js +1 -0
- package/dist/llm/index.d.ts +27 -0
- package/dist/llm/index.js +15 -0
- package/dist/llm/llm.d.ts +0 -0
- package/dist/llm/llm.js +1 -0
- package/dist/llm/openai.d.ts +15 -0
- package/dist/llm/openai.js +86 -0
- package/dist/main.d.ts +0 -0
- package/dist/main.js +1 -0
- package/dist/memory/index.d.ts +24 -0
- package/dist/memory/index.js +31 -0
- package/dist/memory/memory.d.ts +0 -0
- package/dist/memory/memory.js +1 -0
- package/dist/process/index.d.ts +25 -0
- package/dist/process/index.js +37 -0
- package/dist/process/process.d.ts +0 -0
- package/dist/process/process.js +1 -0
- package/dist/task/index.d.ts +25 -0
- package/dist/task/index.js +32 -0
- package/dist/task/task.d.ts +0 -0
- package/dist/task/task.js +1 -0
- package/dist/tools/arxivTools.d.ts +19 -0
- package/dist/tools/arxivTools.js +75 -0
- package/dist/tools/index.d.ts +12 -0
- package/dist/tools/index.js +29 -0
- package/dist/tools/test.d.ts +0 -0
- package/dist/tools/test.js +1 -0
- package/dist/utils/logger.d.ts +15 -0
- package/dist/utils/logger.js +54 -0
- package/package.json +50 -7
package/README.md
CHANGED
|
@@ -1,3 +1,90 @@
|
|
|
1
|
-
#
|
|
1
|
+
# PraisonAI TypeScript Package
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A powerful TypeScript package for AI-driven tools and utilities.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install praisonai
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Development Setup
|
|
12
|
+
|
|
13
|
+
1. Clone the repository:
|
|
14
|
+
```bash
|
|
15
|
+
git clone https://github.com/MervinPraison/PraisonAI.git
|
|
16
|
+
cd src/praisonai-ts
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
2. Install dependencies:
|
|
20
|
+
```bash
|
|
21
|
+
npm install
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
3. Build the package:
|
|
25
|
+
```bash
|
|
26
|
+
npm run build
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Running Examples
|
|
30
|
+
|
|
31
|
+
The package includes several examples to help you get started. To run an example:
|
|
32
|
+
|
|
33
|
+
1. Build the package first:
|
|
34
|
+
```bash
|
|
35
|
+
npm run build
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
2. Run an example using ts-node:
|
|
39
|
+
```bash
|
|
40
|
+
npx ts-node examples/arxiv-search.ts
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Package Structure
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
src/
|
|
47
|
+
├── agent/ # Agent-related interfaces and implementations
|
|
48
|
+
├── agents/ # Multi-agent system management
|
|
49
|
+
├── knowledge/ # Knowledge base and management
|
|
50
|
+
├── llm/ # Language Model interfaces
|
|
51
|
+
├── memory/ # Memory management systems
|
|
52
|
+
├── process/ # Process management
|
|
53
|
+
├── task/ # Task management
|
|
54
|
+
└── tools/ # Various utility tools
|
|
55
|
+
├── arxivTools.ts
|
|
56
|
+
└── ... (other tools)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Usage
|
|
60
|
+
|
|
61
|
+
Here's a simple example of using the ArxivSearchTool:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { ArxivSearchTool } from 'praisonai';
|
|
65
|
+
|
|
66
|
+
async function main() {
|
|
67
|
+
const searchTool = new ArxivSearchTool();
|
|
68
|
+
const papers = await searchTool.execute('quantum computing', 5);
|
|
69
|
+
|
|
70
|
+
papers.forEach(paper => {
|
|
71
|
+
console.log(`Title: ${paper.title}`);
|
|
72
|
+
console.log(`Authors: ${paper.authors.join(', ')}`);
|
|
73
|
+
console.log('---');
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
main();
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Contributing
|
|
81
|
+
|
|
82
|
+
1. Fork the repository
|
|
83
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
84
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
85
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
86
|
+
5. Open a Pull Request
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
MIT License - see the LICENSE file for details
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Task = exports.PraisonAIAgents = exports.Agent = void 0;
|
|
4
|
+
exports.setTaskMode = setTaskMode;
|
|
5
|
+
// Export implementation based on mode
|
|
6
|
+
let useTaskMode = false;
|
|
7
|
+
function setTaskMode(enabled) {
|
|
8
|
+
useTaskMode = enabled;
|
|
9
|
+
}
|
|
10
|
+
var proxy_1 = require("./proxy");
|
|
11
|
+
Object.defineProperty(exports, "Agent", { enumerable: true, get: function () { return proxy_1.Agent; } });
|
|
12
|
+
Object.defineProperty(exports, "PraisonAIAgents", { enumerable: true, get: function () { return proxy_1.PraisonAIAgents; } });
|
|
13
|
+
Object.defineProperty(exports, "Task", { enumerable: true, get: function () { return proxy_1.Task; } });
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SimpleAgentConfig } from './simple';
|
|
2
|
+
import { TaskAgentConfig } from './types';
|
|
3
|
+
import { Task } from './types';
|
|
4
|
+
export interface ProxyAgentConfig extends Partial<SimpleAgentConfig>, Partial<TaskAgentConfig> {
|
|
5
|
+
task?: Task;
|
|
6
|
+
}
|
|
7
|
+
export declare class Agent {
|
|
8
|
+
private simpleAgent;
|
|
9
|
+
private taskAgent;
|
|
10
|
+
constructor(config: ProxyAgentConfig);
|
|
11
|
+
execute(input: Task | string): Promise<any>;
|
|
12
|
+
}
|
|
13
|
+
export declare class PraisonAIAgents {
|
|
14
|
+
private simpleImpl;
|
|
15
|
+
private taskImpl;
|
|
16
|
+
constructor(config: any);
|
|
17
|
+
start(): Promise<any[]>;
|
|
18
|
+
}
|
|
19
|
+
export { Task } from './types';
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Task = exports.PraisonAIAgents = exports.Agent = void 0;
|
|
4
|
+
const simple_1 = require("./simple");
|
|
5
|
+
const types_1 = require("./types");
|
|
6
|
+
const types_2 = require("./types");
|
|
7
|
+
class Agent {
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.simpleAgent = null;
|
|
10
|
+
this.taskAgent = null;
|
|
11
|
+
// Auto-detect mode based on task presence
|
|
12
|
+
if (config.task) {
|
|
13
|
+
const taskConfig = {
|
|
14
|
+
name: config.name || 'TaskAgent',
|
|
15
|
+
role: config.role || 'Assistant',
|
|
16
|
+
goal: config.goal || 'Help complete the task',
|
|
17
|
+
backstory: config.backstory || 'You are an AI assistant',
|
|
18
|
+
verbose: config.verbose,
|
|
19
|
+
llm: config.llm,
|
|
20
|
+
markdown: config.markdown
|
|
21
|
+
};
|
|
22
|
+
this.taskAgent = new types_1.Agent(taskConfig);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const simpleConfig = {
|
|
26
|
+
instructions: config.instructions || '',
|
|
27
|
+
name: config.name,
|
|
28
|
+
verbose: config.verbose,
|
|
29
|
+
llm: config.llm,
|
|
30
|
+
markdown: config.markdown
|
|
31
|
+
};
|
|
32
|
+
this.simpleAgent = new simple_1.Agent(simpleConfig);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async execute(input) {
|
|
36
|
+
if (this.taskAgent) {
|
|
37
|
+
const task = input;
|
|
38
|
+
const depResults = task.dependencies.map(dep => dep.result);
|
|
39
|
+
return this.taskAgent.execute(task, depResults);
|
|
40
|
+
}
|
|
41
|
+
else if (this.simpleAgent) {
|
|
42
|
+
return this.simpleAgent.execute(input);
|
|
43
|
+
}
|
|
44
|
+
throw new Error('No agent implementation available');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.Agent = Agent;
|
|
48
|
+
class PraisonAIAgents {
|
|
49
|
+
constructor(config) {
|
|
50
|
+
this.simpleImpl = null;
|
|
51
|
+
this.taskImpl = null;
|
|
52
|
+
// Auto-detect mode based on tasks type
|
|
53
|
+
if (Array.isArray(config.tasks) && config.tasks.length > 0) {
|
|
54
|
+
const firstTask = config.tasks[0];
|
|
55
|
+
if (firstTask instanceof types_2.Task) {
|
|
56
|
+
this.taskImpl = new types_1.PraisonAIAgents({
|
|
57
|
+
agents: config.agents,
|
|
58
|
+
tasks: config.tasks,
|
|
59
|
+
verbose: config.verbose,
|
|
60
|
+
process: config.process,
|
|
61
|
+
manager_llm: config.manager_llm
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this.simpleImpl = new simple_1.PraisonAIAgents({
|
|
66
|
+
agents: config.agents,
|
|
67
|
+
tasks: config.tasks,
|
|
68
|
+
verbose: config.verbose,
|
|
69
|
+
process: config.process
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
throw new Error('No tasks provided');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async start() {
|
|
78
|
+
if (this.taskImpl) {
|
|
79
|
+
return this.taskImpl.start();
|
|
80
|
+
}
|
|
81
|
+
else if (this.simpleImpl) {
|
|
82
|
+
return this.simpleImpl.start();
|
|
83
|
+
}
|
|
84
|
+
throw new Error('No implementation available');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.PraisonAIAgents = PraisonAIAgents;
|
|
88
|
+
var types_3 = require("./types");
|
|
89
|
+
Object.defineProperty(exports, "Task", { enumerable: true, get: function () { return types_3.Task; } });
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface SimpleAgentConfig {
|
|
2
|
+
instructions: string;
|
|
3
|
+
name?: string;
|
|
4
|
+
verbose?: boolean;
|
|
5
|
+
llm?: string;
|
|
6
|
+
markdown?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare class Agent {
|
|
9
|
+
private instructions;
|
|
10
|
+
private name;
|
|
11
|
+
private verbose;
|
|
12
|
+
private llm;
|
|
13
|
+
private markdown;
|
|
14
|
+
private llmService;
|
|
15
|
+
private result;
|
|
16
|
+
constructor(config: SimpleAgentConfig);
|
|
17
|
+
private createSystemPrompt;
|
|
18
|
+
execute(previousResult?: string): Promise<string>;
|
|
19
|
+
getResult(): string | null;
|
|
20
|
+
}
|
|
21
|
+
export interface PraisonAIAgentsConfig {
|
|
22
|
+
agents: Agent[];
|
|
23
|
+
tasks: string[];
|
|
24
|
+
verbose?: boolean;
|
|
25
|
+
process?: 'sequential' | 'parallel';
|
|
26
|
+
}
|
|
27
|
+
export declare class PraisonAIAgents {
|
|
28
|
+
private agents;
|
|
29
|
+
private tasks;
|
|
30
|
+
private verbose;
|
|
31
|
+
private process;
|
|
32
|
+
constructor(config: PraisonAIAgentsConfig);
|
|
33
|
+
start(): Promise<string[]>;
|
|
34
|
+
private executeSequential;
|
|
35
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PraisonAIAgents = exports.Agent = void 0;
|
|
4
|
+
const openai_1 = require("../llm/openai");
|
|
5
|
+
class Agent {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.result = null;
|
|
8
|
+
this.instructions = config.instructions;
|
|
9
|
+
this.name = config.name || `Agent_${Math.random().toString(36).substr(2, 9)}`;
|
|
10
|
+
this.verbose = config.verbose || false;
|
|
11
|
+
this.llm = config.llm || 'gpt-4o-mini';
|
|
12
|
+
this.markdown = config.markdown || true;
|
|
13
|
+
this.llmService = new openai_1.OpenAIService(this.llm);
|
|
14
|
+
}
|
|
15
|
+
createSystemPrompt() {
|
|
16
|
+
return `You are an AI assistant tasked with helping users with their requests.
|
|
17
|
+
Please provide detailed, accurate, and helpful responses.
|
|
18
|
+
Format your response in markdown if appropriate.`;
|
|
19
|
+
}
|
|
20
|
+
async execute(previousResult) {
|
|
21
|
+
if (this.verbose) {
|
|
22
|
+
console.log(`Agent ${this.name} executing instructions: ${this.instructions}`);
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
// Replace placeholder with previous result if available
|
|
26
|
+
const finalInstructions = previousResult
|
|
27
|
+
? this.instructions.replace('{previous_result}', previousResult)
|
|
28
|
+
: this.instructions;
|
|
29
|
+
if (this.verbose) {
|
|
30
|
+
console.log('Generating response (streaming)...');
|
|
31
|
+
await this.llmService.streamText(finalInstructions, this.createSystemPrompt(), 0.7, (token) => process.stdout.write(token));
|
|
32
|
+
console.log('\n');
|
|
33
|
+
}
|
|
34
|
+
// Get the final response
|
|
35
|
+
this.result = await this.llmService.generateText(finalInstructions, this.createSystemPrompt());
|
|
36
|
+
return this.result;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
console.error(`Error executing instructions: ${error}`);
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
getResult() {
|
|
44
|
+
return this.result;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.Agent = Agent;
|
|
48
|
+
class PraisonAIAgents {
|
|
49
|
+
constructor(config) {
|
|
50
|
+
this.agents = config.agents;
|
|
51
|
+
this.tasks = config.tasks;
|
|
52
|
+
this.verbose = config.verbose || false;
|
|
53
|
+
this.process = config.process || 'sequential';
|
|
54
|
+
}
|
|
55
|
+
async start() {
|
|
56
|
+
if (this.verbose) {
|
|
57
|
+
console.log('Starting PraisonAI Agents execution...');
|
|
58
|
+
}
|
|
59
|
+
let results;
|
|
60
|
+
if (this.process === 'parallel') {
|
|
61
|
+
results = await Promise.all(this.tasks.map((task, index) => this.agents[index].execute()));
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
results = await this.executeSequential();
|
|
65
|
+
}
|
|
66
|
+
if (this.verbose) {
|
|
67
|
+
console.log('PraisonAI Agents execution completed.');
|
|
68
|
+
results.forEach((result, index) => {
|
|
69
|
+
console.log(`\nResult from Agent ${index + 1}:`);
|
|
70
|
+
console.log(result);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return results;
|
|
74
|
+
}
|
|
75
|
+
async executeSequential() {
|
|
76
|
+
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);
|
|
80
|
+
results.push(result);
|
|
81
|
+
previousResult = result;
|
|
82
|
+
}
|
|
83
|
+
return results;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.PraisonAIAgents = PraisonAIAgents;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export interface TaskConfig {
|
|
2
|
+
name: string;
|
|
3
|
+
description: string;
|
|
4
|
+
expected_output: string;
|
|
5
|
+
agent?: any;
|
|
6
|
+
dependencies?: Task[];
|
|
7
|
+
}
|
|
8
|
+
export declare class Task {
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
expected_output: string;
|
|
12
|
+
agent: any;
|
|
13
|
+
dependencies: Task[];
|
|
14
|
+
result: any;
|
|
15
|
+
constructor(config: TaskConfig);
|
|
16
|
+
}
|
|
17
|
+
export interface TaskAgentConfig {
|
|
18
|
+
name: string;
|
|
19
|
+
role: string;
|
|
20
|
+
goal: string;
|
|
21
|
+
backstory: string;
|
|
22
|
+
verbose?: boolean;
|
|
23
|
+
llm?: string;
|
|
24
|
+
markdown?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare class Agent {
|
|
27
|
+
private name;
|
|
28
|
+
private role;
|
|
29
|
+
private goal;
|
|
30
|
+
private backstory;
|
|
31
|
+
private verbose;
|
|
32
|
+
private llm;
|
|
33
|
+
private markdown;
|
|
34
|
+
private result;
|
|
35
|
+
constructor(config: TaskAgentConfig);
|
|
36
|
+
execute(task: Task, dependencyResults?: any[]): Promise<any>;
|
|
37
|
+
}
|
|
38
|
+
export interface TaskPraisonAIAgentsConfig {
|
|
39
|
+
agents: Agent[];
|
|
40
|
+
tasks: Task[];
|
|
41
|
+
verbose?: boolean;
|
|
42
|
+
process?: 'sequential' | 'parallel' | 'hierarchical';
|
|
43
|
+
manager_llm?: string;
|
|
44
|
+
}
|
|
45
|
+
export declare class PraisonAIAgents {
|
|
46
|
+
private agents;
|
|
47
|
+
private tasks;
|
|
48
|
+
private verbose;
|
|
49
|
+
private process;
|
|
50
|
+
private manager_llm;
|
|
51
|
+
constructor(config: TaskPraisonAIAgentsConfig);
|
|
52
|
+
start(): Promise<any[]>;
|
|
53
|
+
private executeSequential;
|
|
54
|
+
private executeHierarchical;
|
|
55
|
+
}
|
|
56
|
+
export type { TaskAgentConfig as AgentConfig };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PraisonAIAgents = exports.Agent = exports.Task = void 0;
|
|
4
|
+
const openai_1 = require("../llm/openai");
|
|
5
|
+
const logger_1 = require("../utils/logger");
|
|
6
|
+
class Task {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.name = config.name;
|
|
9
|
+
this.description = config.description;
|
|
10
|
+
this.expected_output = config.expected_output;
|
|
11
|
+
this.agent = config.agent || null;
|
|
12
|
+
this.dependencies = config.dependencies || [];
|
|
13
|
+
this.result = null;
|
|
14
|
+
logger_1.Logger.debug(`Task created: ${this.name}`, { config });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.Task = Task;
|
|
18
|
+
class Agent {
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.name = config.name;
|
|
21
|
+
this.role = config.role;
|
|
22
|
+
this.goal = config.goal;
|
|
23
|
+
this.backstory = config.backstory;
|
|
24
|
+
this.verbose = config.verbose || false;
|
|
25
|
+
this.llm = new openai_1.OpenAIService(config.llm || 'gpt-4o-mini');
|
|
26
|
+
this.markdown = config.markdown || true;
|
|
27
|
+
this.result = '';
|
|
28
|
+
logger_1.Logger.debug(`Agent created: ${this.name}`, { config });
|
|
29
|
+
}
|
|
30
|
+
async execute(task, dependencyResults) {
|
|
31
|
+
logger_1.Logger.debug(`Agent ${this.name} executing task: ${task.name}`, {
|
|
32
|
+
task,
|
|
33
|
+
dependencyResults
|
|
34
|
+
});
|
|
35
|
+
const systemPrompt = `You are ${this.name}, a ${this.role}.
|
|
36
|
+
Your goal is to ${this.goal}.
|
|
37
|
+
Background: ${this.backstory}
|
|
38
|
+
|
|
39
|
+
You must complete the following task:
|
|
40
|
+
Name: ${task.name}
|
|
41
|
+
Description: ${task.description}
|
|
42
|
+
Expected Output: ${task.expected_output}
|
|
43
|
+
|
|
44
|
+
Respond ONLY with the expected output. Do not include any additional text, explanations, or pleasantries.`;
|
|
45
|
+
let prompt = '';
|
|
46
|
+
if (dependencyResults && dependencyResults.length > 0) {
|
|
47
|
+
prompt = `Here are the results from previous tasks that you should use as input:
|
|
48
|
+
${dependencyResults.map((result, index) => `Task ${index + 1} Result:\n${result}`).join('\n\n')}
|
|
49
|
+
|
|
50
|
+
Based on these results, please complete your task.`;
|
|
51
|
+
logger_1.Logger.debug('Using dependency results for prompt', { dependencyResults });
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
prompt = 'Please complete your task.';
|
|
55
|
+
}
|
|
56
|
+
logger_1.Logger.debug('Preparing LLM request', {
|
|
57
|
+
systemPrompt,
|
|
58
|
+
prompt
|
|
59
|
+
});
|
|
60
|
+
if (this.verbose) {
|
|
61
|
+
logger_1.Logger.info(`\nExecuting task for ${this.name}...`);
|
|
62
|
+
logger_1.Logger.info(`Task: ${task.name}`);
|
|
63
|
+
logger_1.Logger.info('Generating response (streaming)...\n');
|
|
64
|
+
}
|
|
65
|
+
// Reset result
|
|
66
|
+
this.result = '';
|
|
67
|
+
// Stream the response and collect it
|
|
68
|
+
await this.llm.streamText(prompt, systemPrompt, 0.7, (token) => {
|
|
69
|
+
if (this.verbose) {
|
|
70
|
+
process.stdout.write(token);
|
|
71
|
+
}
|
|
72
|
+
this.result += token;
|
|
73
|
+
});
|
|
74
|
+
if (this.verbose) {
|
|
75
|
+
console.log('\n'); // Add newline after streaming
|
|
76
|
+
}
|
|
77
|
+
logger_1.Logger.debug(`Agent ${this.name} completed task: ${task.name}`, {
|
|
78
|
+
result: this.result
|
|
79
|
+
});
|
|
80
|
+
return this.result;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.Agent = Agent;
|
|
84
|
+
class PraisonAIAgents {
|
|
85
|
+
constructor(config) {
|
|
86
|
+
this.agents = config.agents;
|
|
87
|
+
this.tasks = config.tasks;
|
|
88
|
+
this.verbose = config.verbose || false;
|
|
89
|
+
this.process = config.process || 'sequential';
|
|
90
|
+
this.manager_llm = config.manager_llm || 'gpt-4o-mini';
|
|
91
|
+
logger_1.Logger.debug('PraisonAIAgents initialized', { config });
|
|
92
|
+
}
|
|
93
|
+
async start() {
|
|
94
|
+
logger_1.Logger.info('Starting PraisonAI Agents execution...');
|
|
95
|
+
logger_1.Logger.debug('Starting with process mode:', this.process);
|
|
96
|
+
let results;
|
|
97
|
+
switch (this.process) {
|
|
98
|
+
case 'parallel':
|
|
99
|
+
logger_1.Logger.debug('Executing tasks in parallel');
|
|
100
|
+
results = await Promise.all(this.tasks.map(task => {
|
|
101
|
+
if (!task.agent)
|
|
102
|
+
throw new Error(`No agent assigned to task: ${task.name}`);
|
|
103
|
+
return task.agent.execute(task);
|
|
104
|
+
}));
|
|
105
|
+
break;
|
|
106
|
+
case 'hierarchical':
|
|
107
|
+
logger_1.Logger.debug('Executing tasks hierarchically');
|
|
108
|
+
results = await this.executeHierarchical();
|
|
109
|
+
break;
|
|
110
|
+
default:
|
|
111
|
+
logger_1.Logger.debug('Executing tasks sequentially');
|
|
112
|
+
results = await this.executeSequential();
|
|
113
|
+
}
|
|
114
|
+
if (this.verbose) {
|
|
115
|
+
logger_1.Logger.info('\nPraisonAI Agents execution completed.');
|
|
116
|
+
results.forEach((result, index) => {
|
|
117
|
+
logger_1.Logger.info(`\nFinal Result from Task ${index + 1}:`);
|
|
118
|
+
console.log(result);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
logger_1.Logger.debug('Execution completed', { results });
|
|
122
|
+
return results;
|
|
123
|
+
}
|
|
124
|
+
async executeSequential() {
|
|
125
|
+
logger_1.Logger.debug('Starting sequential execution');
|
|
126
|
+
const results = [];
|
|
127
|
+
for (const task of this.tasks) {
|
|
128
|
+
if (!task.agent)
|
|
129
|
+
throw new Error(`No agent assigned to task: ${task.name}`);
|
|
130
|
+
logger_1.Logger.debug(`Executing task: ${task.name}`);
|
|
131
|
+
const result = await task.agent.execute(task);
|
|
132
|
+
results.push(result);
|
|
133
|
+
task.result = result;
|
|
134
|
+
logger_1.Logger.debug(`Completed task: ${task.name}`, { result });
|
|
135
|
+
}
|
|
136
|
+
return results;
|
|
137
|
+
}
|
|
138
|
+
async executeHierarchical() {
|
|
139
|
+
logger_1.Logger.debug('Starting hierarchical execution');
|
|
140
|
+
const results = [];
|
|
141
|
+
for (const task of this.tasks) {
|
|
142
|
+
if (!task.agent)
|
|
143
|
+
throw new Error(`No agent assigned to task: ${task.name}`);
|
|
144
|
+
logger_1.Logger.debug(`Executing task: ${task.name}`, {
|
|
145
|
+
dependencies: task.dependencies.map(d => d.name)
|
|
146
|
+
});
|
|
147
|
+
const depResults = task.dependencies.map(dep => dep.result);
|
|
148
|
+
logger_1.Logger.debug(`Dependency results for task ${task.name}`, { depResults });
|
|
149
|
+
const result = await task.agent.execute(task, depResults);
|
|
150
|
+
results.push(result);
|
|
151
|
+
task.result = result;
|
|
152
|
+
logger_1.Logger.debug(`Completed task: ${task.name}`, { result });
|
|
153
|
+
}
|
|
154
|
+
return results;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
exports.PraisonAIAgents = PraisonAIAgents;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
// Export all public modules
|
|
18
|
+
__exportStar(require("./agent"), exports);
|
|
19
|
+
__exportStar(require("./knowledge"), exports);
|
|
20
|
+
__exportStar(require("./llm"), exports);
|
|
21
|
+
__exportStar(require("./memory"), exports);
|
|
22
|
+
__exportStar(require("./process"), exports);
|
|
23
|
+
__exportStar(require("./tools"), exports);
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface Knowledge {
|
|
2
|
+
id: string;
|
|
3
|
+
type: string;
|
|
4
|
+
content: any;
|
|
5
|
+
metadata: Record<string, any>;
|
|
6
|
+
}
|
|
7
|
+
export interface KnowledgeBase {
|
|
8
|
+
addKnowledge(knowledge: Knowledge): void;
|
|
9
|
+
getKnowledge(id: string): Knowledge | undefined;
|
|
10
|
+
searchKnowledge(query: string): Knowledge[];
|
|
11
|
+
updateKnowledge(id: string, knowledge: Partial<Knowledge>): boolean;
|
|
12
|
+
deleteKnowledge(id: string): boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare class BaseKnowledgeBase implements KnowledgeBase {
|
|
15
|
+
private knowledge;
|
|
16
|
+
constructor();
|
|
17
|
+
addKnowledge(knowledge: Knowledge): void;
|
|
18
|
+
getKnowledge(id: string): Knowledge | undefined;
|
|
19
|
+
searchKnowledge(query: string): Knowledge[];
|
|
20
|
+
updateKnowledge(id: string, update: Partial<Knowledge>): boolean;
|
|
21
|
+
deleteKnowledge(id: string): boolean;
|
|
22
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseKnowledgeBase = void 0;
|
|
4
|
+
class BaseKnowledgeBase {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.knowledge = new Map();
|
|
7
|
+
}
|
|
8
|
+
addKnowledge(knowledge) {
|
|
9
|
+
this.knowledge.set(knowledge.id, knowledge);
|
|
10
|
+
}
|
|
11
|
+
getKnowledge(id) {
|
|
12
|
+
return this.knowledge.get(id);
|
|
13
|
+
}
|
|
14
|
+
searchKnowledge(query) {
|
|
15
|
+
// Basic implementation - should be enhanced with proper search logic
|
|
16
|
+
return Array.from(this.knowledge.values()).filter(k => JSON.stringify(k).toLowerCase().includes(query.toLowerCase()));
|
|
17
|
+
}
|
|
18
|
+
updateKnowledge(id, update) {
|
|
19
|
+
const existing = this.knowledge.get(id);
|
|
20
|
+
if (!existing)
|
|
21
|
+
return false;
|
|
22
|
+
this.knowledge.set(id, { ...existing, ...update });
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
deleteKnowledge(id) {
|
|
26
|
+
return this.knowledge.delete(id);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.BaseKnowledgeBase = BaseKnowledgeBase;
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|