Skip to main content

Installation

AgentLIB is distributed as a set of focused npm packages. Install only what you need.

Core Packages

Essential Installation

At minimum, you need @agentlib/core and a model provider:
npm install @agentlib/core @agentlib/openai

Available Packages

PackageDescriptionVersion
@agentlib/coreCore runtime — Agent, types, tool system, events, middlewarenpm
@agentlib/openaiOpenAI model provider (GPT-4o, o1, o3-mini, any OpenAI-compatible API)npm
@agentlib/memoryMemory providers — Buffer, SlidingWindow, Summarizing, Compositenpm
@agentlib/reasoningReasoning engines — ReAct, Planner, CoT, Reflect, Autonomousnpm
@agentlib/loggerStructured logging middleware with timing and custom transportsnpm

Optional Packages

Memory Providers

Install if you want conversation history:
npm install @agentlib/memory
Provides BufferMemory, SlidingWindowMemory, SummarizingMemory, and CompositeMemory.

Reasoning Engines

Install if you want advanced reasoning strategies:
npm install @agentlib/reasoning
Provides ReactEngine, PlannerEngine, ChainOfThoughtEngine, ReflectEngine, and AutonomousEngine.

Logging Middleware

Install if you want structured logging:
npm install @agentlib/logger

Peer Dependencies

Environment Variables (Optional)

All packages accept dotenv as an optional peer dependency for loading .env files:
npm install dotenv
Then load variables at the top of your entry file:
import 'dotenv/config'
dotenv is marked as optional in peerDependenciesMeta, so you can skip it if you load environment variables another way.

OpenAI SDK

The @agentlib/openai package depends on the official OpenAI SDK (openai ^4.52.0), which is installed automatically as a direct dependency.

System Requirements

Node.js Version

All packages require Node.js 18.0.0 or higher:
"engines": {
  "node": ">=18.0.0"
}
Check your Node version:
node --version
If you’re on an older version, upgrade using nvm or fnm:
nvm install 18
nvm use 18
AgentLIB is written in TypeScript and ships with full type definitions. For the best experience, use TypeScript 5.4.0 or higher:
npm install --save-dev typescript

Package Manager

The source repository uses pnpm 9.0.0+ for workspaces, but published packages work with npm, yarn, or pnpm.

Environment Setup

Create .env File

Copy the example environment file from the repository:
cp .env.example .env
Or create one manually:
.env
# OpenAI
OPENAI_API_KEY=sk-...
OPENAI_BASE_URL=https://api.openai.com/
OPENAI_MODEL=gpt-4o
OPENAI_MODEL_SUMMARIZER=gpt-4o-mini
OPENAI_MODEL_REASONING=o3-mini

# Anthropic (if using @agentlib/anthropic in the future)
ANTHROPIC_API_KEY=sk-ant-...

# Google Gemini (if using @agentlib/gemini in the future)
GOOGLE_GENERATIVE_AI_API_KEY=...

# Groq (if using @agentlib/groq in the future)
GROQ_API_KEY=gsk_...

# Mistral (if using @agentlib/mistral in the future)
MISTRAL_API_KEY=...
Never commit .env files to version control. Add .env to your .gitignore.

Load Environment Variables

At the top of your entry file (e.g., index.ts or main.ts):
import 'dotenv/config'
import { createAgent } from '@agentlib/core'
import { openai } from '@agentlib/openai'

const agent = createAgent({ name: 'assistant' })
  .provider(openai({ apiKey: process.env.OPENAI_API_KEY! }))

Verify Installation

Create a simple test file to verify everything works:
test.ts
import 'dotenv/config'
import { createAgent, defineTool } from '@agentlib/core'
import { openai } from '@agentlib/openai'

const echoTool = defineTool({
  schema: {
    name: 'echo',
    description: 'Echoes back the input',
    parameters: {
      type: 'object',
      properties: { message: { type: 'string' } },
      required: ['message'],
    },
  },
  async execute({ message }) {
    return { echo: message }
  },
})

const agent = createAgent({ name: 'test' })
  .provider(openai({ apiKey: process.env.OPENAI_API_KEY! }))
  .tool(echoTool)

const result = await agent.run('Echo "Hello, AgentLIB!"')
console.log(result.output)
Run it:
npx tsx test.ts
If you see output from the agent, you’re ready to go!

Monorepo Development

If you want to contribute or run the examples from the source repository:
# Clone the repository
git clone https://github.com/sammwy/agentlib.git
cd agentlib

# Install dependencies (requires pnpm 9.0.0+)
pnpm install

# Build all packages
pnpm build

# Run an example
pnpm example example/basic-agent.ts
pnpm example example/chat-history.ts
pnpm example example/reasoning/react.ts

# Watch mode (rebuild on changes)
pnpm dev
The monorepo uses Turborepo for build orchestration and pnpm workspaces for dependency management.

Next Steps

Quickstart Guide

Build your first agent in 5 minutes

Core Concepts

Learn about agents, tools, memory, and reasoning

Build docs developers (and LLMs) love