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
Section titled “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
Section titled “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
Section titled “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
Section titled “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