Skip to content

Commit e45b844

Browse files
Merge pull request #354 from MervinPraison/develop
Update TypeScript Documentation and Examples with Simplified Agent Wo…
2 parents f37d8fe + 6d6303d commit e45b844

11 files changed

+79
-148
lines changed

docs/js/typescript.mdx

+28-13
Original file line numberDiff line numberDiff line change
@@ -65,31 +65,46 @@ graph LR
6565
```
6666
</Step>
6767
<Step title="Create File">
68-
Create `app.js` file
68+
Create `app.ts` file
6969

7070
## Code Example
7171

7272
<CodeGroup>
7373
```javascript Single Agent
74-
const { Agent } = require('praisonai');
75-
const agent = new Agent({ instructions: 'You are a helpful AI assistant' });
76-
agent.start('Write a movie script about a robot in Mars');
74+
import { Agent } from 'praisonai';
75+
76+
const agent = new Agent({
77+
instructions: `You are a creative writer who writes short stories with emojis.`,
78+
name: "StoryWriter"
79+
});
80+
81+
agent.start("Write a story about a time traveler")
7782
```
7883

7984
```javascript Multi Agents
80-
const { Agent, PraisonAIAgents } = require('praisonai');
85+
import { Agent, PraisonAIAgents } from 'praisonai';
8186

82-
const researchAgent = new Agent({ instructions: 'Research about AI' });
83-
const summariseAgent = new Agent({ instructions: 'Summarise research agent\'s findings' });
87+
const storyAgent = new Agent({
88+
instructions: "Generate a very short story (2-3 sentences) about artificial intelligence with emojis.",
89+
name: "StoryAgent"
90+
});
8491

85-
const agents = new PraisonAIAgents({ agents: [researchAgent, summariseAgent] });
86-
agents.start();
92+
const summaryAgent = new Agent({
93+
instructions: "Summarize the provided AI story in one sentence with emojis.",
94+
name: "SummaryAgent"
95+
});
96+
97+
const agents = new PraisonAIAgents({
98+
agents: [storyAgent, summaryAgent]
99+
});
100+
101+
agents.start()
87102
```
88103
</CodeGroup>
89104
</Step>
90105
<Step title="Run Script">
91106
```bash
92-
node app.js
107+
npx ts-node app.ts
93108
```
94109
</Step>
95110
</Steps>
@@ -103,7 +118,7 @@ agents.start();
103118
Create and run a single agent to perform a specific task:
104119

105120
```typescript
106-
import { Agent } from '../../src/agent/simple';
121+
import { Agent } from 'praisonai';
107122

108123
// Single agent example - Science Explainer
109124
const agent = new Agent({
@@ -129,7 +144,7 @@ agent.start("Why is the sky blue?")
129144
Create and run multiple agents working together:
130145

131146
```typescript
132-
import { Agent, PraisonAIAgents } from '../../src/agent/simple';
147+
import { Agent, PraisonAIAgents } from 'praisonai';
133148

134149
// Create story agent
135150
const storyAgent = new Agent({
@@ -168,7 +183,7 @@ agents.start()
168183
Create agents with specific tasks and dependencies:
169184

170185
```typescript
171-
import { Agent, PraisonAIAgents } from '../../src/agent/simple';
186+
import { Agent, PraisonAIAgents } from 'praisonai';
172187

173188
// Create recipe agent
174189
const recipeAgent = new Agent({
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,17 @@
11
import { Agent, PraisonAIAgents } from 'praisonai';
22

3-
// Create story agent
43
const storyAgent = new Agent({
5-
instructions: "You are a storyteller. Write a very short story (2-3 sentences) about a given topic.",
6-
name: "StoryAgent",
7-
verbose: true
4+
instructions: "Generate a very short story (2-3 sentences) about artificial intelligence with emojis.",
5+
name: "StoryAgent"
86
});
97

10-
// Create summary agent
118
const summaryAgent = new Agent({
12-
instructions: "You are an editor. Create a one-sentence summary of the given story.",
13-
name: "SummaryAgent",
14-
verbose: true
9+
instructions: "Summarize the provided AI story in one sentence with emojis.",
10+
name: "SummaryAgent"
1511
});
1612

17-
// Create and start agents
1813
const agents = new PraisonAIAgents({
19-
agents: [storyAgent, summaryAgent],
20-
tasks: [
21-
"Write a short story about a cat",
22-
"{previous_result}" // This will be replaced with the story
23-
],
24-
verbose: true
14+
agents: [storyAgent, summaryAgent]
2515
});
2616

27-
agents.start()
28-
.then(results => {
29-
console.log('\nStory:', results[0]);
30-
console.log('\nSummary:', results[1]);
31-
})
32-
.catch(error => console.error('Error:', error));
17+
agents.start()
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
import { Agent } from 'praisonai';
22

3-
// Single agent example - Science Explainer
43
const agent = new Agent({
5-
instructions: `You are a science expert who explains complex phenomena in simple terms.
6-
Provide clear, accurate, and easy-to-understand explanations.`,
7-
name: "ScienceExplainer",
8-
verbose: true
4+
instructions: `You are a creative writer who writes short stories with emojis.`,
5+
name: "StoryWriter"
96
});
107

11-
agent.start("Why is the sky blue?")
12-
.then(response => {
13-
console.log('\nExplanation:');
14-
console.log(response);
15-
})
16-
.catch(error => {
17-
console.error('Error:', error);
18-
});
8+
agent.start("Write a story about a time traveler")
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,21 @@
11
import { Agent, PraisonAIAgents } from 'praisonai';
22

3-
// Create recipe agent
43
const recipeAgent = new Agent({
5-
instructions: `You are a professional chef and nutritionist. Create 5 healthy food recipes that are both nutritious and delicious.
6-
Each recipe should include:
7-
1. Recipe name
8-
2. List of ingredients with quantities
9-
3. Step-by-step cooking instructions
10-
4. Nutritional information
11-
5. Health benefits
12-
13-
Format your response in markdown.`,
14-
name: "RecipeAgent",
15-
verbose: true
4+
instructions: `You are a professional chef and nutritionist. Create 1 healthy food recipes that are both nutritious and delicious.`,
5+
name: "RecipeAgent"
166
});
177

18-
// Create blog agent
198
const blogAgent = new Agent({
20-
instructions: `You are a food and health blogger. Write an engaging blog post about the provided recipes.
21-
The blog post should:
22-
1. Have an engaging title
23-
2. Include an introduction about healthy eating
24-
3. Discuss each recipe and its unique health benefits
25-
4. Include tips for meal planning and preparation
26-
5. End with a conclusion encouraging healthy eating habits
27-
28-
Here are the recipes to write about:
29-
{previous_result}
30-
31-
Format your response in markdown.`,
32-
name: "BlogAgent",
33-
verbose: true
9+
instructions: `You are a food and health blogger. Write an engaging blog post about the provided recipes`,
10+
name: "BlogAgent"
3411
});
3512

36-
// Create PraisonAIAgents instance with tasks
3713
const agents = new PraisonAIAgents({
3814
agents: [recipeAgent, blogAgent],
3915
tasks: [
40-
"Create 5 healthy and delicious recipes",
41-
"Write a blog post about the recipes"
42-
],
43-
verbose: true
16+
"Create 1 healthy and delicious recipes in 5 lines with emojis",
17+
"Write a blog post about the recipes in 5 lines with emojis"
18+
]
4419
});
4520

46-
// Start the agents
47-
agents.start()
48-
.then(results => {
49-
console.log('\nFinal Results:');
50-
console.log('\nRecipe Task Results:');
51-
console.log(results[0]);
52-
console.log('\nBlog Task Results:');
53-
console.log(results[1]);
54-
})
55-
.catch(error => {
56-
console.error('Error:', error);
57-
});
21+
agents.start()

src/praisonai-ts/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "praisonai",
3-
"version": "1.0.14",
3+
"version": "1.0.15",
44
"description": "PraisonAI TypeScript AI Agents Framework - Node.js, npm, and Javascript AI Agents Framework",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/praisonai-ts/src/agent/simple.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ export class PraisonAIAgents {
147147
await Logger.debug(`Running agent ${i + 1}: ${agent.name}`);
148148
await Logger.debug(`Task: ${task}`);
149149

150-
const result = await agent.start(task, previousResult);
150+
// For first agent, use task directly
151+
// For subsequent agents, append previous result to their instructions
152+
const prompt = i === 0 ? task : `${task}\n\nHere is the input: ${previousResult}`;
153+
const result = await agent.start(prompt, previousResult);
151154
results.push(result);
152155
previousResult = result;
153156
}

src/praisonai-ts/src/llm/openai.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async function getOpenAIClient(): Promise<OpenAI> {
3030
openAIInstance = new OpenAI({
3131
apiKey: process.env.OPENAI_API_KEY
3232
});
33-
await Logger.success('OpenAI client initialized');
33+
await Logger.debug('OpenAI client initialized');
3434
}
3535
return openAIInstance;
3636
}
@@ -157,7 +157,7 @@ export class OpenAIService {
157157
onToken(token);
158158
}
159159

160-
await Logger.success('Stream completed successfully');
160+
await Logger.debug('Stream completed successfully');
161161
} catch (error) {
162162
await Logger.error('Error in text stream', error);
163163
throw error;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Agent, PraisonAIAgents } from '../../src/agent/proxy';
2+
3+
const storyAgent = new Agent({
4+
instructions: "Generate a very short story (2-3 sentences) about artificial intelligence developing emotions and creativity with emojis.",
5+
name: "StoryAgent"
6+
});
7+
8+
const summaryAgent = new Agent({
9+
instructions: "Summarize the provided AI story in one sentence. Do not ask for input - the story will be automatically provided to you with emojis.",
10+
name: "SummaryAgent"
11+
});
12+
13+
const agents = new PraisonAIAgents({
14+
agents: [storyAgent, summaryAgent]
15+
});
16+
17+
agents.start()

src/praisonai-ts/tests/simple/multi-agents-detailed.ts

+3-19
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,15 @@ import { Agent, PraisonAIAgents } from '../../src/agent/simple';
22

33
// Create research agent
44
const researchAgent = new Agent({
5-
instructions: `You are an AI research expert. Conduct comprehensive research about artificial intelligence,
6-
focusing on:
7-
1. Current state of AI technology
8-
2. Major breakthroughs and developments
9-
3. Key applications and use cases
10-
4. Future trends and predictions
11-
5. Ethical considerations
12-
13-
Format your response in markdown with clear sections and bullet points.`,
5+
instructions: `You are an AI research expert. Conduct comprehensive research about artificial intelligence`,
146
name: "ResearchAgent",
157
verbose: true,
168
pretty: true
179
});
1810

1911
// Create summarize agent
2012
const summarizeAgent = new Agent({
21-
instructions: `You are a professional technical writer. Create a concise executive summary of the research findings about AI.
22-
The summary should:
23-
1. Highlight key points and insights
24-
2. Be clear and accessible to non-technical readers
25-
3. Include actionable takeaways
26-
4. Be no more than 500 words
27-
28-
Here is the research to summarize:
29-
{previous_result}`,
13+
instructions: `You are a professional technical writer. Create a concise executive summary of the research findings about AI`,
3014
name: "SummarizeAgent",
3115
verbose: true,
3216
pretty: true
@@ -35,7 +19,7 @@ Here is the research to summarize:
3519
// Create PraisonAIAgents instance
3620
const agents = new PraisonAIAgents({
3721
agents: [researchAgent, summarizeAgent],
38-
tasks: ["Research current state and future of AI", "Create executive summary"],
22+
tasks: ["Research current state and future of AI with emojis", "Create executive summary with emojis"],
3923
process: 'sequential', // Run agents one after another
4024
verbose: true,
4125
pretty: true
+3-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
import { Agent } from '../../src/agent/proxy';
22

3-
// Single agent example - Short Story Writer
43
const agent = new Agent({
54
instructions: `You are a creative writer who writes short stories.
6-
Keep stories brief (max 100 words) and engaging.`,
7-
name: "StoryWriter",
8-
verbose: true,
9-
pretty: true, // Enable pretty logging
10-
stream: true // Enable streaming output
5+
Keep stories brief (max 50 words) and engaging with emojis.`,
6+
name: "StoryWriter"
117
});
128

13-
// Write a very short story
14-
agent.start("Write a 100-word story about a time traveler")
15-
.catch(error => {
16-
console.error('Error:', error);
17-
});
9+
agent.start("Write a story about a time traveler")

src/praisonai-ts/tests/simple/task-based-agent.ts

+4-23
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,14 @@ import { Agent, PraisonAIAgents } from '../../src/agent/simple';
22

33
// Create recipe agent
44
const recipeAgent = new Agent({
5-
instructions: `You are a professional chef and nutritionist. Create 5 healthy food recipes that are both nutritious and delicious.
6-
Each recipe should include:
7-
1. Recipe name
8-
2. List of ingredients with quantities
9-
3. Step-by-step cooking instructions
10-
4. Nutritional information
11-
5. Health benefits
12-
13-
Format your response in markdown.`,
5+
instructions: `You are a professional chef and nutritionist. Create 1 healthy food recipes that are both nutritious and delicious.`,
146
name: "RecipeAgent",
157
verbose: true
168
});
179

1810
// Create blog agent
1911
const blogAgent = new Agent({
20-
instructions: `You are a food and health blogger. Write an engaging blog post about the provided recipes.
21-
The blog post should:
22-
1. Have an engaging title
23-
2. Include an introduction about healthy eating
24-
3. Discuss each recipe and its unique health benefits
25-
4. Include tips for meal planning and preparation
26-
5. End with a conclusion encouraging healthy eating habits
27-
28-
Here are the recipes to write about:
29-
{previous_result}
30-
31-
Format your response in markdown.`,
12+
instructions: `You are a food and health blogger. Write an engaging blog post about the provided recipes`,
3213
name: "BlogAgent",
3314
verbose: true
3415
});
@@ -37,8 +18,8 @@ Format your response in markdown.`,
3718
const agents = new PraisonAIAgents({
3819
agents: [recipeAgent, blogAgent],
3920
tasks: [
40-
"Create 1 healthy and delicious recipes",
41-
"Write a blog post about the recipes"
21+
"Create 1 healthy and delicious recipes in 5 lines with emojis",
22+
"Write a blog post about the recipes in 5 lines with emojis"
4223
],
4324
verbose: true
4425
});

0 commit comments

Comments
 (0)