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
| Concern | NestJS + LangChain | HazelJS |
|---|---|---|
| Scope | Web framework + AI library | Full AI-native TypeScript backend |
| Mental model | Two: Nest modules + LCEL/runnables | One: modules, decorators, DI |
| Agent runtime | LangGraph or custom loops | @hazeljs/agent (AgentGraph, Supervisor, HITL) |
| Durable workflows | LangGraph / external | @hazeljs/flow WAIT/resume + Prisma option |
| RAG | LangChain retrievers + stores | @hazeljs/rag (GraphRAG, loaders, memory) |
| Fluent pipelines | LCEL | HCEL inside @hazeljs/ai |
| HTTP surface | Nest controllers | HazelJS controllers (same app) |
| Production hardening | You compose resilience | Gateway, resilience, auth, audit packages |
| Observability | Split HTTP vs LLM tooling | Inspector 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
| Situation | Recommendation |
|---|---|
| Greenfield AI backend in TypeScript | HazelJS |
| Nest monorepo, AI is 5% of surface | Stay Nest; add thin LLM SDK or LangChain |
| Nest monorepo, AI is becoming the product | Pilot HazelJS vertical (agent + RAG) or full migrate |
| Need LangGraph-style durable agent graphs and HTTP | HazelJS AgentGraph + @hazeljs/flow |
| Heavy LangChain Hub / Python research pipelines | LangChain; 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
- HazelJS vs NestJS — framework-only view
- HazelJS vs LangChain — AI library view (coming in this cluster)
- Support agent example — production pattern reference
Next steps
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.