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.
Node version should be >=22. Any version below 22 will not work.
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.
-
Clone the brain-starter repository:
Terminal window git clone https://github.com/IQAIcom/brain-starter.git my-brain-agentcd my-brain-agent -
Install the dependencies:
Terminal window npm installTerminal window pnpm installTerminal window yarn install -
Start the development server:
Terminal window npm run devTerminal window pnpm run devTerminal window yarn run dev -
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:
-
Set up your project structure:
Terminal window mkdir -p my-brain-agent/{src,data} && cd my-brain-agent -
Setup project
Terminal window npm initTerminal window npm i -D typescript && npx tsc --initTerminal window pnpm add -D typescript && npx tsc --initTerminal window yarn add -D typescript && npx tsc --init -
Create index and env file
Terminal window touch src/index.ts .env -
Install the required Brain Framework packages:
Terminal window Terminal window Terminal window -
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:
- LLM Model Provider: Choose your preferred language model (OpenAI, Claude, etc.) that will power your agentβs intelligence.
- 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.
- 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.
-
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 variablesdotenv.config();async function main() {// Create your agent with basic configurationconst agent = new AgentBuilder().withModelProvider(ModelProviderName.OPENAI, process.env.OPENAI_API_KEY).withDatabase(SqliteAdapter).withClient(DirectClient).build();// Start your agentawait agent.start();console.log("Agent is running! You can test it using the IQAI Console.");}main().catch(console.error); -
Update your
package.json
to support ES modules and scripts:{"type": "module","scripts": {"dev": "node src/index.ts"}} -
Run your agent:
Terminal window npm run devTerminal window pnpm run devTerminal window yarn run dev -
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:
- Explore different options you can pass though Agent
- Add Plugins to extend your agentβs functionality
- Create your own plugins using Plugin Creation Guide
- Deploy your agent to a production environment
- Check out our Examples Repo to see more advanced use cases