Skip to content

Quick Start

In this guide, we’ll create a basic AI agent using Brain Framework from scratch. Before we go further, ensure you have Nodejs installed on your machine. You can download it from here.

Using Brain Starter Template

The fastest way to get started is using our pre-configured starter template which has all the basic setup ready to go.

  1. Clone the brain-starter repository:

    Terminal window
    git clone https://github.com/IQAIcom/brain-starter.git my-brain-agent
    cd my-brain-agent
  2. Install the dependencies:

    Terminal window
    npm install
  3. Start the development server:

    Terminal window
    npm run dev
  4. Test your agent: After starting your agent, visit IQAI Console to interact with it through a ready-to-use interface. This allows you to test your agent without building a custom client application.

Creating a New Project From Scratch

If you prefer to set up your project from scratch, you can follow these steps:

  1. Set up your project structure:

    Terminal window
    mkdir -p my-brain-agent/{src,data} && cd my-brain-agent
  2. Setup project

    Terminal window
    npm init
    Terminal window
    npm i -D typescript && npx tsc --init
  3. Create index and env file

    Terminal window
    touch src/index.ts .env
  4. Install the required Brain Framework packages:

    Terminal window
    npm i @iqai/agent github:elizaos-plugins/adapter-sqlite @elizaos/[email protected] sharp dotenv
  5. Add your OpenAI API key to the .env file:

    OPENAI_API_KEY=your_openai_api_key_here

Creating Your First Agent

To create an agent, you’ll need three key components:

  1. LLM Model Provider: Choose your preferred language model (OpenAI, Claude, etc.) that will power your agent’s intelligence.
  2. Client Interface: Select how users will interact with your agent. Brain Framework supports various client integrations including Discord, Telegram, Twitter, Instagram, WhatsApp and more. In this example, we’ll use the Direct client which provides HTTP endpoints for interaction.
  3. Prompts and Plugins: Define your agent’s behavior through prompts and extend functionality using plugins. In this quickstart example, we’ll use the default prompts that come with the framework. For customizing prompts and adding plugins, check out Agent Creation Guide.
  1. Open src/index.ts in your favorite code editor and add the following code:

    import SqliteAdapter from "@elizaos/adapter-sqlite";
    import DirectClient from "@elizaos/client-direct";
    import { AgentBuilder, ModelProviderName } from "@iqai/agent";
    import dotenv from "dotenv";
    // Load environment variables
    dotenv.config();
    async function main() {
    // Create your agent with basic configuration
    const agent = new AgentBuilder()
    .withModelProvider(ModelProviderName.OPENAI, process.env.OPENAI_API_KEY)
    .withDatabase(SqliteAdapter)
    .withClient(DirectClient)
    .build();
    // Start your agent
    await agent.start();
    console.log("Agent is running! You can test it using the IQAI Console.");
    }
    main().catch(console.error);
  2. Update your package.json to support ES modules and scripts:

    {
    "type": "module",
    "scripts": {
    "dev": "node src/index.ts"
    }
    }
  3. Run your agent:

    Terminal window
    npm run dev
  4. Test your agent: After starting your agent, visit IQAI Console to interact with it through a ready-to-use interface. This allows you to test your agent without building a custom client application.

    For more details on testing your agent, check out Testing Your Agent

Next Steps

Now that you have a basic agent running, you can: