New: HCEL — chain prompts, RAG, and agents in native TypeScript Learn more →
HazelJS LogoHazelJS

Comparison

NestJS + LangChain vs HazelJS

The common production path — NestJS for HTTP and LangChain for AI — works, but creates two paradigms. HazelJS unifies APIs, agents, and RAG in one module system.

Updated August 4, 2026

NestJS + LangChain vs HazelJS

TL;DR

  • NestJS + LangChain is the default “production AI backend” recipe for many TypeScript teams.
  • It works — and it creates two frameworks, two config stories, and a lot of glue between HTTP and AI.
  • HazelJS is built so controllers, agents, RAG, memory, and workflows share one module system and DI container.
  • Keep Nest + LangChain if you already invested heavily and AI is a thin layer.
  • Switch (or start new) on HazelJS when agents/RAG are the product.

Who this is for

Teams that:

  • Run NestJS APIs and added LangChain for RAG/agents
  • Feel pain from dual paradigms (Nest providers vs LangChain runnables)
  • Want auth, caching, observability, and agents under one roof

Not ideal if:

  • You only need a few LLM calls in Nest controllers (raw OpenAI SDK may be enough)
  • You depend on LangChain ecosystem plugins HazelJS does not mirror yet
  • You are Python-first (LangChain’s gravity is stronger there)

The glue-code problem

A typical Nest + LangChain setup looks like:

NestJS module
  └─ Controller / Guard / Pipe
       └─ Service
            └─ LangChain chain / agent / retriever
                 └─ Vector store, embeddings, tools, memory

Every new AI feature means bridging:

  • Nest DI ↔ LangChain constructors
  • Nest config ↔ LangChain env/secrets
  • Nest logging/OTel ↔ LangSmith or custom LLM traces
  • Nest auth context ↔ tool execution identity

HazelJS collapses that bridge: agents and HCEL chains are providers in the same graph as your HTTP layer.

Side-by-side

ConcernNestJS + LangChainHazelJS
ScopeWeb framework + AI libraryFull AI-native TypeScript backend
Mental modelTwo: Nest modules + LCEL/runnablesOne: modules, decorators, DI
Agent runtimeLangGraph or custom loops@hazeljs/agent (AgentGraph, Supervisor, HITL)
Durable workflowsLangGraph / external@hazeljs/flow WAIT/resume + Prisma option
RAGLangChain retrievers + stores@hazeljs/rag (GraphRAG, loaders, memory)
Fluent pipelinesLCELHCEL inside @hazeljs/ai
HTTP surfaceNest controllersHazelJS controllers (same app)
Production hardeningYou compose resilienceGateway, resilience, auth, audit packages
ObservabilitySplit HTTP vs LLM toolingInspector timelines + OTel in one stack

Code: glue vs native

Nest service wrapping LangChain (illustrative glue):

// Nest provider manually constructs LangChain pieces
@Injectable()
export class ChatService {
  private chain: any;

  constructor(private config: ConfigService) {
    const model = new ChatOpenAI({ apiKey: this.config.get('OPENAI_API_KEY') });
    const retriever = /* wire vector store */;
    this.chain = RunnableSequence.from([
      /* prompt */,
      retriever,
      model,
    ]);
  }

  async ask(input: string) {
    return this.chain.invoke({ input });
  }
}

HazelJS HCEL in the same DI world:

import { Injectable } from '@hazeljs/core';
import { AIService } from '@hazeljs/ai';

@Injectable()
export class ChatService {
  constructor(private ai: AIService) {}

  async ask(input: string) {
    return this.ai.hazel
      .prompt('Answer using docs: {{input}}')
      .rag('engineering-docs')
      .agent('support-specialist')
      .execute(input);
  }
}

Support agent without a separate executor framework:

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

@Agent({
  name: 'support-desk',
  enableMemory: true,
  enableRAG: true,
  systemPrompt: 'Resolve tickets with tools when needed.',
})
export class SupportDeskAgent {
  @Tool({
    description: 'Create a ticket',
    parameters: [{ name: 'title', type: 'string', required: true }],
  })
  async createTicket(input: { title: string }) {
    return { id: 'T-100', title: input.title };
  }
}

Decision guide

SituationRecommendation
Greenfield AI backend in TypeScriptHazelJS
Nest monorepo, AI is 5% of surfaceStay Nest; add thin LLM SDK or LangChain
Nest monorepo, AI is becoming the productPilot HazelJS vertical (agent + RAG) or full migrate
Need LangGraph-style durable agent graphs and HTTPHazelJS AgentGraph + @hazeljs/flow
Heavy LangChain Hub / Python research pipelinesLangChain; use HazelJS only for the TS API edge

When NestJS + LangChain is better

  • Your org standardized on LangSmith / LangGraph and training is done
  • You need a LangChain integration HazelJS does not ship yet
  • Political cost of introducing another framework exceeds glue-code cost

HazelJS is the better default when time-to-production agent API and one observability/auth story matter more than LangChain ecosystem breadth.

Related comparisons

Next steps

  1. Docs: Agent package
  2. Docs: RAG and RAG vs Agentic RAG
  3. Agent OS guide
  4. Installation
  5. GitHub

FAQ

Why not just use NestJS with LangChain?
It works. The cost is dual DI/config patterns, manual wiring of RAG and agents into controllers, and separate observability for HTTP vs LLM calls. HazelJS collapses that into one stack.
Is HazelJS a LangChain replacement?
For many TypeScript backend use cases yes — HCEL, Agent Runtime, and @hazeljs/rag cover chains, agents, and retrieval. Deep LangChain ecosystem plugins may still be useful in research-heavy setups.
What about LangGraph for durable agents?
HazelJS provides AgentGraph / SupervisorAgent for agent orchestration and @hazeljs/flow for durable WAIT/resume business workflows — in the same framework as your HTTP layer.
Can I migrate incrementally?
Yes. Start with @hazeljs/ai or agent modules for new surfaces while Nest remains elsewhere, or migrate a vertical slice (e.g. support agent) first. Full Nest → HazelJS migration is documented separately.

Docs & next steps

Related comparisons

  • HazelJS vs NestJS

    NestJS is excellent for structured APIs. HazelJS keeps a familiar module/DI model and adds native AI, agents, RAG, and Agent OS in the same stack.

  • HazelJS vs LangChain

    LangChain composes LLM pipelines. HazelJS ships those capabilities inside a production TypeScript backend — controllers, agents, RAG, and ops together.

  • HazelJS vs LangGraph

    LangGraph is a strong agent graph runtime. HazelJS covers agent orchestration, durable business workflows, and your API layer without a separate web framework.

← All comparisons