Installation

Set up Better Agent in your project.

Install Better Agent in your TypeScript project.

Packages

CoreAgents, tools, events, and runtime primitives.
ClientTyped HTTP client plus framework hooks for React, Vue, Svelte, Solid, and Preact.
ProvidersAdapters for model APIs such as OpenAI, Anthropic, and xAI.
PluginsGuards, lifecycle hooks, middleware, and runtime extensions.
AdaptersFramework adapters for Express, Fastify, and future server integrations.
CLIType generation for typed client packages and app definitions.

Installation

Automatic

Terminal
npm create better-agent

Use the create CLI to scaffold a new Better Agent app or patch Better Agent into an existing project.

It detects your framework, generates the Better Agent files, lets you choose providers and plugins, and writes the required env vars and package entries.

Manual

Use the manual setup if you want full control over the project structure or prefer to integrate Better Agent by hand.

01Create your project
Create a TypeScript project if you do not have one already.
Terminal
mkdir my-agent && cd my-agent
npm init -y
npm install typescript -D
npx tsc --init
02Install the packages
Install the core packages first. Add @better-agent/client for typed frontends.
Terminal
npm install @better-agent/core @better-agent/providers
03Create the app
Create a provider, define an agent, and export the Better Agent app.
server.ts
import { betterAgent, defineAgent } from "@better-agent/core";
import { createOpenAI } from "@better-agent/providers/openai";

const openai = createOpenAI({
  apiKey: process.env.OPENAI_API_KEY,
});

const helloAgent = defineAgent({
  name: "helloAgent",
  model: openai.text("gpt-5-mini"),
  instruction: "You are a friendly assistant. Keep answers short.",
});

const app = betterAgent({
  agents: [helloAgent],
  baseURL: "/api",
  secret: "dev-secret",
});

export default app;
Continue to Usage to add a typed client and UI.