Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TypeScript documentation and examples for AI agent tools #405

Merged
merged 1 commit into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 98 additions & 10 deletions docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -114,27 +114,53 @@ agents.start()
</Steps>
</Tab>
<Tab title="No Code">
<Tip>
PraisonAI combines PraisonAI Agents, AutoGen, and CrewAI into a low-code solution for building and managing multi-agent LLM systems, focusing on simplicity, customization, and efficient human-agent collaboration.
</Tip>
<Steps>
<Step title="Install Package">
Install the No Code PraisonAI Package:
```bash
pip install praisonai
pip install praisonaiagents
```
</Step>

<Step title="Set API Key">
```bash
export OPENAI_API_KEY=xxxxxxxxxxxxxxxxxxxxxx
export OPENAI_API_KEY=your_openai_key
```
</Step>
<Step title="Auto Mode">
```bash
praisonai --auto create a movie script about Robots in Mars
```

This will automatically create required agents and complete the task
<Step title="Create Config">
Create `agents.yaml`:

<CodeGroup>
```yaml Single Agent
roles:
summarise_agent:
instructions: Summarise Photosynthesis
```

```yaml Multiple Agents
roles:
diet_agent:
instructions: Give me 5 healthy food recipes
blog_agent:
instructions: Write a blog post about the food recipes
```
</CodeGroup>

<Note>
You can automatically create `agents.yaml` using:
```bash
praisonai --init "your task description"
```
</Note>

</Step>

<Step title="Run Agents">
Execute your config:
```bash
praisonai agents.yaml
```
</Step>
</Steps>
</Tab>
Expand Down Expand Up @@ -180,6 +206,68 @@ agents.start();
</Step>
</Steps>
</Tab>
<Tab title="TypeScript">
<Steps>
<Step title="Install Package">
<CodeGroup>
```bash npm
npm install praisonai
```
```bash yarn
yarn add praisonai
```
</CodeGroup>
</Step>
<Step title="Set API Key">
```bash
export OPENAI_API_KEY=xxxxxxxxxxxxxxxxxxxxxx
```
</Step>
<Step title="Create File">
Create `app.ts` file

## Code Example

<CodeGroup>
```javascript Single Agent
import { Agent } from 'praisonai';

const agent = new Agent({
instructions: `You are a creative writer who writes short stories with emojis.`,
name: "StoryWriter"
});

agent.start("Write a story about a time traveler")
```

```javascript Multi Agents
import { Agent, PraisonAIAgents } from 'praisonai';

const storyAgent = new Agent({
instructions: "Generate a very short story (2-3 sentences) about artificial intelligence with emojis.",
name: "StoryAgent"
});

const summaryAgent = new Agent({
instructions: "Summarize the provided AI story in one sentence with emojis.",
name: "SummaryAgent"
});

const agents = new PraisonAIAgents({
agents: [storyAgent, summaryAgent]
});

agents.start()
```
</CodeGroup>
</Step>
<Step title="Run Script">
```bash
npx ts-node app.ts
```
</Step>
</Steps>
</Tab>
</Tabs>

## AI Agents Flow
Expand Down
19 changes: 19 additions & 0 deletions docs/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ pip install praisonai
```bash JavaScript
npm install praisonai
```
```bash TypeScript
npm install praisonai
```
</RequestExample>

<Note>
Expand Down Expand Up @@ -109,6 +112,22 @@ Follow these steps to set up PraisonAI in your development environment.
</Step>
</Steps>
</Tab>
<Tab title="TypeScript">
<Steps>
<Step title="Install PraisonAI">
Install the PraisonAI package:
```bash
npm install praisonai
```
</Step>
<Step title="Set API Key">
Set your OpenAI API key as an environment variable in your terminal:
```bash
export OPENAI_API_KEY=your_openai_key
```
</Step>
</Steps>
</Tab>
</Tabs>

Generate your OpenAI API key from [OpenAI](https://platform.openai.com/api-keys)
Expand Down
62 changes: 62 additions & 0 deletions docs/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,68 @@ agents.start();
</Step>
</Steps>
</Tab>
<Tab title="TypeScript">
<Steps>
<Step title="Install Package">
<CodeGroup>
```bash npm
npm install praisonai
```
```bash yarn
yarn add praisonai
```
</CodeGroup>
</Step>
<Step title="Set API Key">
```bash
export OPENAI_API_KEY=xxxxxxxxxxxxxxxxxxxxxx
```
</Step>
<Step title="Create File">
Create `app.ts` file

## Code Example

<CodeGroup>
```javascript Single Agent
import { Agent } from 'praisonai';

const agent = new Agent({
instructions: `You are a creative writer who writes short stories with emojis.`,
name: "StoryWriter"
});

agent.start("Write a story about a time traveler")
```

```javascript Multi Agents
import { Agent, PraisonAIAgents } from 'praisonai';

const storyAgent = new Agent({
instructions: "Generate a very short story (2-3 sentences) about artificial intelligence with emojis.",
name: "StoryAgent"
});

const summaryAgent = new Agent({
instructions: "Summarize the provided AI story in one sentence with emojis.",
name: "SummaryAgent"
});

const agents = new PraisonAIAgents({
agents: [storyAgent, summaryAgent]
});

agents.start()
```
</CodeGroup>
</Step>
<Step title="Run Script">
```bash
npx ts-node app.ts
```
</Step>
</Steps>
</Tab>
</Tabs>

## Key Features
Expand Down
50 changes: 50 additions & 0 deletions docs/js/customtools.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: "Custom Tools for TypeScript AI Agents"
sidebarTitle: "Custom Tools"
description: "Learn how to create custom tools for TypeScript AI Agents"
icon: "toolbox"
---

## Single Agent

```typescript
import { Agent } from 'praisonai';

async function getWeather(location: string) {
console.log(`Getting weather for ${location}...`);
return `${Math.floor(Math.random() * 30)}°C`;
}

const agent = new Agent({
instructions: `You provide the current weather for requested locations.`,
name: "DirectFunctionAgent",
tools: [getWeather]
});

agent.start("What's the weather in Paris, France?");
```

## Multi Agents

```typescript
import { Agent } from 'praisonai';

async function getWeather(location: string) {
console.log(`Getting weather for ${location}...`);
return `${Math.floor(Math.random() * 30)}°C`;
}

async function getTime(location: string) {
console.log(`Getting time for ${location}...`);
const now = new Date();
return `${now.getHours()}:${now.getMinutes()}`;
}

const agent = new Agent({
instructions: `You provide the current weather and time for requested locations.`,
name: "DirectFunctionAgent",
tools: [getWeather, getTime]
});

agent.start("What's the weather and time in Paris, France and Tokyo, Japan?");
```
65 changes: 0 additions & 65 deletions docs/js/typescript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -268,74 +268,12 @@ agents.start()
## Tool Calls Examples

<AccordionGroup>
<Accordion title="Single Agent Tool Call" icon="wrench" defaultOpen>
Create an agent that can use tools to get information:

```typescript
import { Agent } from 'praisonai';

/**
* Example of a simple agent with tool calling capability
*
* This example demonstrates how to create a simple agent that can use tools
* to get weather information for a location.
*/

// Define a weather tool
const getWeather = {
type: "function",
function: {
name: "get_weather",
description: "Get current temperature for a given location.",
parameters: {
type: "object",
properties: {
location: {
type: "string",
description: "City and country e.g. Bogotá, Colombia"
}
},
required: ["location"],
additionalProperties: false
},
strict: true
}
};

// Make the function globally available
// The agent will automatically find and use this function
(global as any).get_weather = async function(location: string) {
console.log(`Getting weather for ${location}...`);
return `20°C`;
};

// Create an agent with the weather tool
const agent = new Agent({
instructions: `You provide the current weather for requested locations.`,
name: "WeatherAgent",
tools: [getWeather]
});

// Start the agent with a prompt that will trigger tool usage
agent.start("What's the weather in Paris, France?");
```
</Accordion>

<Accordion title="Direct Function Tools" icon="code" defaultOpen>
Create an agent with directly registered function tools:

```typescript
import { Agent } from 'praisonai';

/**
* Example of a simple agent with direct function registration
*
* This example demonstrates how to create a simple agent that uses directly
* registered functions as tools without having to define tool schemas manually
* or make functions globally available.
*/

// Define the functions directly
async function getWeather(location: string) {
console.log(`Getting weather for ${location}...`);
return `${Math.floor(Math.random() * 30)}°C`;
Expand All @@ -347,15 +285,12 @@ async function getTime(location: string) {
return `${now.getHours()}:${now.getMinutes()}`;
}

// Create an agent with directly registered functions
const agent = new Agent({
instructions: `You provide the current weather and time for requested locations.`,
name: "DirectFunctionAgent",
// Register functions directly as an array without needing to make them global
tools: [getWeather, getTime]
});

// Start the agent with a prompt that will trigger tool usage
agent.start("What's the weather and time in Paris, France and Tokyo, Japan?");
```
</Accordion>
Expand Down
9 changes: 8 additions & 1 deletion docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,14 @@
"group": "JavaScript",
"pages": [
"js/js",
"js/typescript",
{
"group": "TypeScript Agents",
"icon": "subscript",
"pages": [
"js/typescript",
"js/customtools"
]
},
"js/nodejs",
"js/typescript-async",
"js/development"
Expand Down
Loading
Loading