> ## Documentation Index
> Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# JavaScript AI Agents Framework

> A production-ready Multi AI Agents framework for JavaScript

PraisonAI is a production-ready Multi AI Agents framework for JavaScript, designed to create AI Agents to automate and solve problems ranging from simple tasks to complex challenges. It provides a low-code solution to streamline the building and management of multi-agent LLM systems, emphasising simplicity, customisation, and effective human-agent collaboration.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    %% Define the main flow
    Start([▶ Start]) --> Agent1
    Agent1 --> Process[⚙ Process]
    Process --> Agent2
    Agent2 --> Output([✓ Output])
    Process -.-> Agent1
    
    %% Define subgraphs for agents and their tasks
    subgraph Agent1[ ]
        Task1[📋 Task]
        AgentIcon1[🤖 AI Agent]
        Tools1[🔧 Tools]
        
        Task1 --- AgentIcon1
        AgentIcon1 --- Tools1
    end
    
    subgraph Agent2[ ]
        Task2[📋 Task]
        AgentIcon2[🤖 AI Agent]
        Tools2[🔧 Tools]
        
        Task2 --- AgentIcon2
        AgentIcon2 --- Tools2
    end

    classDef input fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef process fill:#189AB4,stroke:#7C90A0,color:#fff
    classDef tools fill:#2E8B57,stroke:#7C90A0,color:#fff
    classDef transparent fill:none,stroke:none

    class Start,Output,Task1,Task2 input
    class Process,AgentIcon1,AgentIcon2 process
    class Tools1,Tools2 tools
    class Agent1,Agent2 transparent
```

<Tabs>
  <Tab title="JavaScript">
    <Steps>
      <Step title="Install Package">
        <CodeGroup>
          ```bash npm theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
          npm install praisonai
          ```

          ```bash yarn theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
          yarn add praisonai
          ```
        </CodeGroup>
      </Step>

      <Step title="Set API Key">
        ```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
        export OPENAI_API_KEY=xxxxxxxxxxxxxxxxxxxxxx
        ```
      </Step>

      <Step title="Create File">
        Create `app.js` file

        ## Code Example

        <CodeGroup>
          ```javascript Single Agent theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
          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');
          ```

          ```javascript Multi Agents theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
          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();
          ```
        </CodeGroup>
      </Step>

      <Step title="Run Script">
        ```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
        node app.js
        ```
      </Step>
    </Steps>
  </Tab>
</Tabs>

## Usage Examples

<AccordionGroup>
  <Accordion title="Single Agent Example" icon="user" defaultOpen>
    Create and run a single agent to perform a specific task:

    ```javascript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    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));

    ```
  </Accordion>

  <Accordion title="Multi-Agent Example" icon="users" defaultOpen>
    Create and run multiple agents working together:

    ```javascript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    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));
    ```
  </Accordion>

  <Accordion title="Task-Based Agent Example" icon="list-check" defaultOpen>
    Create agents with specific tasks and dependencies:

    ```javascript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    const { Agent, Task } = require('praisonai');

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

    // Create a task with dependencies
    const mainTask = new Task({
      name: "Write Blog Post",
      description: "Write a blog post about artificial intelligence",
      expected_output: "A complete blog post",
      dependencies: []
    });

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

## Running the Examples

<Steps>
  <Step title="Set Environment Variables">
    ```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    export OPENAI_API_KEY='your-api-key'
    ```
  </Step>

  <Step title="Create Example File">
    Create a new JavaScript file (e.g., `app.js`) with any of the above examples.
  </Step>

  <Step title="Run the Example">
    ```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    node app.js
    ```
  </Step>
</Steps>
