JavaScript AI Agents Framework

The JavaScript SDK of PraisonAI — build AI agents in Node.js, on hosted or local models including Ollama

PraisonAI runs AI agents on your own computers, even fully offline, so private data never has to leave the building. It is built for highly regulated teams, and free and open source for everyone.

This is the JavaScript SDK of the open-source PraisonAI agent framework. Build single agents, multi-agent workflows, tools and memory in Node.js, on hosted models or on local models such as Ollama. Data stays on your own machines only when the model runs locally too; with a hosted model such as the default OpenAI one, prompts are sent to that provider. The Python framework and the full docs are at github.com/MervinPraison/PraisonAI and praison.ai/docs.

Diagram

📋 Task

🤖 AI Agent

🔧 Tools

📋 Task

🤖 AI Agent

🔧 Tools

▶ Start

⚙ Process

✓ Output

JavaScript

Quick Start

  1. Simple Usage
    npm
    npm install praisonai
    yarn
    yarn add praisonai
  2. With Configuration
    bash
    export OPENAI_API_KEY=xxxxxxxxxxxxxxxxxxxxxx
  3. Create File

    Create app.js file

    ## Code Example

    Single Agent
    const { Agent } = require('praisonai');
    const agent = new Agent({ instructions: 'You are a helpful AI assistant' });
    agent.start('Write a movie script about a robot in Mars');
    Multi Agents
    const { Agent, Agents } = require('praisonai');
    
    const researchAgent = new Agent({ instructions: 'Research about AI' });
    const summariseAgent = new Agent({ instructions: 'Summarise research agent\'s findings' });
    
    const agents = new AgentTeam({ agents: [researchAgent, summariseAgent] });
    agents.start();
  4. Run Script
    bash
    node app.js

Usage Examples

Single Agent Example

Create and run a single agent to perform a specific task:

javascript
const { Agent } = require('praisonai');

// Create a simple science explainer agent
const agent = new Agent({
  instructions: "You are a science expert who explains complex phenomena in simple terms.",
  name: "ScienceExplainer",
  verbose: true
});

// Ask a question
agent.start("Why is the sky blue?")
  .then(response => {
    console.log('\nExplanation:');
    console.log(response);
  })
  .catch(error => console.error('Error:', error));
Multi-Agent Example

Create and run multiple agents working together:

javascript
const { Agents, Agent } = require('praisonai');

// Create a story agent and a summary agent
const storyAgent = new Agent({
  instructions: "You are a creative storyteller. Create engaging stories.",
  name: "Storyteller"
});

const summaryAgent = new Agent({
  instructions: "You summarize stories into brief, engaging summaries.",
  name: "Summarizer"
});

// Create multi-agent system
const agents = new AgentTeam({
  agents: [storyAgent, summaryAgent],
  tasks: [
    "Create a short story about a magical forest",
    "Summarize the story in 2 sentences"
  ]
});

// Run the agents
agents.start()
  .then(responses => {
    console.log('\nStory:');
    console.log(responses[0]);
    console.log('\nSummary:');
    console.log(responses[1]);
  })
  .catch(error => console.error('Error:', error));
Task-Based Agent Example

Create agents with specific tasks and dependencies:

javascript
const { Agent } = require('praisonai');

// Create a task-based agent
const agent = new Agent({
  name: "TaskMaster",
  role: "Assistant",
  goal: "Complete tasks efficiently",
  instructions: "You are an AI assistant that helps complete tasks step by step."
});

// A task is a plain object — agent.execute reads its description
const mainTask = {
  name: "Write Blog Post",
  description: "Write a blog post about artificial intelligence",
  expectedOutput: "A complete blog post"
};

// Execute the task
agent.execute(mainTask)
  .then(response => {
    console.log('\nBlog Post:');
    console.log(response);
  })
  .catch(error => console.error('Error:', error));

Running the Examples

  1. Set Environment Variables
    bash
    export OPENAI_API_KEY='your-api-key'
  2. Create Example File

    Create a new JavaScript file (e.g., app.js) with any of the above examples.

  3. Run the Example
    bash
    node app.js

Related