Skip to main content

Welcome to AgentLIB

AgentLIB is a type-safe, composable AI agent framework for Node.js. Build production-ready AI agents with pluggable reasoning engines, memory providers, tool calling, middleware, and full observability — all with a clean, fluent TypeScript API.

Quick Example

Here’s a simple weather agent in under 20 lines:
import { createAgent, defineTool } from '@agentlib/core'
import { openai } from '@agentlib/openai'

const weatherTool = defineTool({
  schema: {
    name: 'get_weather',
    description: 'Get the current weather for a location.',
    parameters: {
      type: 'object',
      properties: { location: { type: 'string' } },
      required: ['location'],
    },
  },
  async execute({ location }) {
    return { location, temperature: 22, condition: 'sunny' }
  },
})

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

const result = await agent.run('What is the weather in Tokyo?')
console.log(result.output)

Get Started

Quickstart

Build your first agent in 5 minutes

Core Concepts

Learn about agents, tools, memory, and reasoning

API Reference

Explore the complete API documentation

Examples

Browse working examples and use cases

Key Features

Fluent Builder API

Chain configuration methods for a clean, readable agent setup:
const agent = createAgent({ name: 'assistant' })
  .provider(openai({ apiKey: process.env.OPENAI_API_KEY! }))
  .tool(weatherTool)
  .memory(new BufferMemory({ maxMessages: 20 }))
  .reasoning('react')
  .use(loggingMiddleware)

Type-Safe Throughout

Full generics for agent state (AgentInstance<TData>) and typed tool arguments:
interface UserContext {
  userId: string
  preferences: Record<string, any>
}

const agent = createAgent<UserContext>({
  name: 'personal-assistant',
  data: { userId: 'user-123', preferences: {} }
})

Pluggable Reasoning Engines

Swap reasoning strategies without changing agent code:

ReAct

Tool-using agents with Thought → Action → Observation loops

Chain of Thought

Step-by-step reasoning for complex math and logic

Planner

Multi-step task decomposition and execution

Reflect

Self-critique and revision for accuracy-critical tasks

Autonomous

Long-horizon open-ended task execution

Custom

Implement the ReasoningEngine interface

Persistent Memory

Multiple strategies for conversation history management:
  • BufferMemory — Keep last N messages in memory
  • SlidingWindowMemory — Token-aware eviction
  • SummarizingMemory — Compress old context with LLM
  • CompositeMemory — Chain providers together

Middleware System

Intercept any lifecycle event for logging, rate limiting, or custom logic:
agent.use({
  name: 'rate-limiter',
  scope: 'run:before',
  async run(mCtx, next) {
    await checkRateLimit(mCtx.ctx.data.userId)
    await next()
  },
})
Available scopes: run:before, run:after, step:before, step:after, tool:before, tool:after

Event Emitter

Lightweight pub/sub for observability:
agent.on('run:start', ({ input }) => console.log('Starting:', input))
agent.on('tool:after', ({ tool, result }) => console.log(`${tool} →`, result))
agent.on('step:reasoning', (step) => {
  if (step.type === 'thought') console.log('💭', step.content)
})
agent.on('error', (err) => console.error('Agent error:', err))

Session Support

Multi-user memory isolation via sessionId:
// Each user gets their own conversation history
await agent.run({ input: 'Hello!', sessionId: 'user-1' })
await agent.run({ input: 'What is my name?', sessionId: 'user-1' })

Policy Enforcement

Stop runs before hitting cost or safety limits:
const agent = createAgent({
  name: 'safe-agent',
  policy: {
    maxSteps: 10,
    tokenBudget: 50_000,
    allowedTools: ['search', 'calculator'],
    timeout: 30_000,
  },
})

Architecture

AgentLIB is built as a modular monorepo with focused packages:
PackageDescription
@agentlib/coreCore runtime — Agent, types, tool system, events, middleware
@agentlib/openaiOpenAI model provider (GPT-4o, o1, o3-mini, any OpenAI-compatible API)
@agentlib/memoryMemory providers — Buffer, SlidingWindow, Summarizing, Composite
@agentlib/reasoningReasoning engines — ReAct, Planner, CoT, Reflect, Autonomous
@agentlib/loggerStructured logging middleware with timing and custom transports
All packages require Node.js 18.0.0 or higher and are fully compatible with TypeScript 5.4+.

Next Steps

Installation

Install AgentLIB and set up your environment

Quickstart Guide

Build your first agent step-by-step

Build docs developers (and LLMs) love