DocumentationReference

Production AI Agents in Node.js with HazelJS

Build stateful, tool-using AI agents in TypeScript/Node.js with human-in-the-loop, memory, RAG, and HTTP — without bolting LangChain onto Express or Nest.

Quick Reference

  • Purpose: Intent guide for “production AI agents Node.js” / “TypeScript agent backend”.
  • When to use: You need agents that pause, resume, call tools safely, and sit behind real APIs.
  • Key concepts: @Agent, @Tool, Agent Runtime, memory, RAG, approvals, Agent OS, Skillgate.
  • Dependencies: @hazeljs/core, @hazeljs/agent, optionally @hazeljs/rag, @hazeljs/ai, @hazeljs/testing, @hazeljs/skillgate.
  • Related: Agent package, Agent OS, Skillgate, Support agent example, vs LangGraph.

What “production” means here

Demo chatbotProduction agent (HazelJS)
Stateless prompt loopRich agent state + optional Redis persistence
Unrestricted tools@Tool + requiresApproval
No retrievalenableRAG / @hazeljs/rag
No HTTP identityControllers + auth packages
Manual eval@hazeljs/eval + describeAgent
HopeAgent OS loops, policies, contracts, Inspector

Minimal production agent

import { Agent, Tool } from '@hazeljs/agent';

@Agent({
  name: 'support-desk',
  systemPrompt: 'Resolve customer issues. Prefer tools over guessing.',
  enableMemory: true,
  enableRAG: true,
})
export class SupportDeskAgent {
  @Tool({
    description: 'Fetch order status',
    parameters: [{ name: 'orderId', type: 'string', required: true }],
  })
  async getOrder(input: { orderId: string }) {
    return { orderId: input.orderId, status: 'in_transit' };
  }

  @Tool({
    description: 'Open a refund request',
    requiresApproval: true,
    parameters: [
      { name: 'orderId', type: 'string', required: true },
      { name: 'amount', type: 'number', required: true },
    ],
  })
  async refund(input: { orderId: string; amount: number }) {
    return { status: 'pending_approval', ...input };
  }
}

Serve it from an API

Agents are providers in the same DI graph as controllers. Pattern:

  1. Register agent class on @HazelModule
  2. Inject / resolve Agent Runtime
  3. POST /agents/:name/run with user message + tenant/user metadata

Concrete CSR routes and streaming: Support agent example.

Add orchestration

PatternUse
HCEL .agent(...)Fluent pipelines with prompt + RAG + agent
@DelegatePeer agent calls as tools
AgentGraphDAG / conditional multi-step agents
SupervisorAgentLLM-driven routing across specialists
@hazeljs/flowDurable business WAIT/resume (orders, approvals)

Agent OS (beyond a single run)

When you need confidence loops, policies, contracts, recovery, DNA, durable HITL, and CI:

Agent OS guide

When you need curated REST → agent skills:

Skillgate guide

Example shape (from the product docs):

await runtime.execute('support-desk', message, {
  loop: { maxIterations: 4, successScore: 90 },
  contract: { name: 'support-slo', maxLatencyMs: 30_000, fallbackAgent: 'safe-desk' },
  recovery: { maxRetries: 2, fallbackAgent: 'safe-desk' },
});

Production checklist

  • Tool schemas explicit; dangerous tools require approval
  • Memory scoped per user/session
  • RAG corpus versioned; retrieval evaluated
  • Auth on HTTP entrypoints
  • Timeouts, retries, circuit breakers (@hazeljs/resilience)
  • Traces / Inspector timelines for LLM steps
  • Golden tests with @hazeljs/testing / eval

Stack comparisons

Next steps

  1. Installation
  2. Agent package
  3. Build a TypeScript RAG API
  4. GitHub