LangChain / Vercel AI SDK — AI Web

AI frameworks such as the Vercel AI SDK (the ai package 7, October 2026) and LangChain.js (langchain 1.5) are libraries that wrap the code you have already…

Anyone who has ground spices by hand knows what's in a ready-made spice paste. They can judge when the paste is worth it, and they can still cook when there is no packet. You have done the grinding: in the earlier lessons you wrote, by hand, the code for each provider's different request format, stream parsing (splitting a stream into events), the tool loop, chat state and the RAG steps. AI frameworks such as the Vercel AI SDK and LangChain.js are the paste: libraries that already contain the code for those jobs. This lesson compares hand-written code, the Vercel AI SDK and LangChain.js on the same Bookshop jobs.

What a framework wraps

Job By hand (earlier lessons) Vercel AI SDK LangChain.js
Calling a model, any provider fetch to /v1/responses or /v1/messages, different JSON shapes generateText({ model: openai("gpt-6-luna") }) initChatModel("openai:gpt-6-luna")
Streaming readSSE, TextDecoder, each provider's event names streamText(...).textStream model.stream(...)
The tool loop function_call, call_id, a round cap tool({...}) + stopWhen: isStepCount(3) createAgent({ tools })
Chat state in React an array of messages, statuses, AbortController useChat() from @ai-sdk/react useStream() from @langchain/react
RAG chunk, embed, cosine, top k embedMany, cosineSimilarity RecursiveCharacterTextSplitter, MemoryVectorStore
Confirming write tools an awaiting_confirmation status toolApproval humanInTheLoopMiddleware

Versions on npm as of October 2026: the Vercel AI SDK's main package, ai, 7.0.137 (major 7, the first number of the version, released 25 June 2026), @ai-sdk/react 4.0.140, @ai-sdk/openai 4.0.91; langchain 1.5.16 and @langchain/core 1.2.17. None of them is installed in the Bookshop project, so the Lab shows the framework code but runs the hand-written version.

Vercel AI SDK

The Vercel AI SDK is a TypeScript library from Vercel for web apps. It gives the same set of functions for many providers (through the packages @ai-sdk/openai, @ai-sdk/anthropic and others), plus React hooks (functions such as useState). Here is the assistant's route with one tool, following the AI SDK 7 docs:

import { streamText, tool, isStepCount, convertToModelMessages, createUIMessageStreamResponse, toUIMessageStream } from "ai";
import { openai } from "@ai-sdk/openai";
import { z } from "zod";

export async function POST(req) {
  const { messages } = await req.json();
  const result = streamText({
    model: openai("gpt-6-luna"),
    providerOptions: { openai: { reasoningEffort: "none" } },
    instructions: RULES,
    messages: await convertToModelMessages(messages),
    tools: {
      checkStock: tool({
        description: "Check a book's stock and price at the Bookshop.",
        inputSchema: z.object({ title: z.string().min(1).max(100) }),
        execute: async ({ title }) => (await fetch(`https://api.bookshop.test/books?q=${encodeURIComponent(title)}`)).json(),
      }),
    },
    stopWhen: isStepCount(3),
  });
  return createUIMessageStreamResponse({ stream: toUIMessageStream({ stream: result.stream }) });
}

In a React component, the chat needs only one hook:

import { useChat } from "@ai-sdk/react";
import { DefaultChatTransport } from "ai";

const { messages, sendMessage, status, stop, regenerate } = useChat({
  transport: new DefaultChatTransport({ api: "/api/assistant" }),
});

LangChain.js

LangChain.js is a bigger framework. It focuses on agents and on components that plug together: models, prompts, tools, retrievers (they fetch the relevant chunks of your documents) and vector stores (places that store vectors). An agent is a model plus tools, running in a loop until the model can answer. Its docs (October 2026) present createAgent as the main entry point, LangGraph for low-level orchestration (you control every step yourself), and Deep Agents for more complete agents. Install it with npm install langchain @langchain/core (Node 22 or later), plus a provider package such as @langchain/openai.

Here is the Bookshop assistant in LangChain.js. checkStock is your function that gets the stock from the Bookshop API:

import { createAgent, tool } from "langchain";
import * as z from "zod";

const stockTool = tool(checkStock, { name: "checkStock", description: "Check a book's stock and price.", schema: z.object({ title: z.string().min(1).max(100) }) });
const agent = createAgent({ model: "openai:gpt-6-luna", tools: [stockTool], systemPrompt: RULES });
const result = await agent.invoke({ messages: [{ role: "user", content: "Is The Rainbow Troops still in stock?" }] });
console.log(result.messages.at(-1)?.text);

For RAG, the components just plug together:

import { RecursiveCharacterTextSplitter } from "@langchain/textsplitters";
import { OpenAIEmbeddings } from "@langchain/openai";
import { MemoryVectorStore } from "@langchain/classic/vectorstores/memory";

const splitter = new RecursiveCharacterTextSplitter({ chunkSize: 1000, chunkOverlap: 200 });
const store = new MemoryVectorStore(new OpenAIEmbeddings({ model: "text-embedding-3-small" }));
await store.addDocuments(await splitter.splitDocuments(documents));
const sources = await store.similaritySearch("Is there a novel about a school on Belitung?", 2);

Switching provider: measured, not claimed

The hand-written tool loop of the Bookshop assistant is 16 lines long. If you move from gpt-6-luna (OpenAI) to claude-haiku-5-5 (Anthropic), how many lines change: about 1, about 3, or more than 10? And if the loop is written with the Vercel AI SDK? Guess before you look at the table.

The Lab compares the OpenAI version and the Anthropic version of the same tool loop, line by line. A comparison like this is called a diff:

Style Lines Switching to Anthropic
By hand 16 10 lines removed, 11 added: the URL, headers, input_schema, tool_use, tool_result, how the text is read
Vercel AI SDK 13 3 removed, 2 added: the provider import, the model line, and the OpenAI-only providerOptions
LangChain.js 6 1 removed, 1 added: the model text, plus npm install @langchain/anthropic

So the hand-written version changes by more than 10 lines, and the AI SDK version by about 3. For RAG, all three ways keep OpenAI embeddings, because the "Embeddings" page in Anthropic's docs says Anthropic doesn't offer its own embedding model, and its example uses Voyage AI (another provider of embedding models).

When to use no framework

A framework is worth it when you use many of its parts. No framework makes more sense when:

⚠️ Stale examples and the false comfort of a framework

TL;DR: AI frameworks such as the Vercel AI SDK (the ai package 7, October 2026) and LangChain.js (langchain 1.5) are libraries that wrap the code you have already written by hand: each provider's format, streaming (streamText, model.stream), the tool loop (tool + stopWhen: isStepCount(n), createAgent), chat state (useChat from @ai-sdk/react with sendMessage, status, stop, regenerate) and RAG (embedMany + cosineSimilarity, or a document splitter + a vector store). The AI SDK's strength is abstractions (wrappers that hide the details) for streaming, chat state and switching providers. Moving the tool loop from OpenAI to Anthropic: the AI SDK removes 3 lines and adds 2, by hand you remove 10 and add 11. LangChain composes AI components (models, prompts, tools, retrievers that fetch chunks of documents) into agents (a model plus tools in a loop) and pipelines. Use no framework for small endpoints, backends that aren't JavaScript, and looking for bugs in the layer underneath (the code a framework wraps). Validation, permissions, confirming write tools and keeping the API key on the server are still your job.

⚡ A ready-made paste for AI code

Meaning: AI frameworks such as the Vercel AI SDK and LangChain.js are libraries that wrap the code you have already written by hand: each provider's request format, stream parsing (splitting a stream into events), the tool loop, chat state and the RAG steps. A framework is like a ready-made spice paste, and hand-written code is like spices you grind yourself. Because you know what's inside, you can judge when a framework is worth it.

⚡ One hook for the whole chat

Write:

import { useChat } from "@ai-sdk/react";
import { DefaultChatTransport } from "ai";

const { messages, sendMessage, status, stop, regenerate } = useChat({
  transport: new DefaultChatTransport({ api: "/api/assistant" }),
});

Meaning: This is Vercel AI SDK code in a React component. useChat is a hook (a React function such as useState) that handles the message list, the status, sending (sendMessage), Stop (stop) and Try again (regenerate). Through DefaultChatTransport, the hook calls the route /api/assistant. In that route, streamText (it calls the model with streaming) with tool and stopWhen: isStepCount(3) (at most 3 model calls) replaces your tool loop.

⚡ Switching provider

Guess first: the Bookshop assistant's hand-written tool loop is 16 lines long. Moving from gpt-6-luna (OpenAI) to claude-haiku-5-5 (Anthropic), how many lines change?

More than 10: 10 lines removed, 11 added, because the two providers' requests and responses have different shapes. With the Vercel AI SDK, only 3 removed and 2 added, because the provider package handles the difference.

Meaning: That is the Vercel AI SDK's strength: abstractions (wrappers that hide the details) for streaming, chat state and switching providers. LangChain.js composes AI components (models, prompts, tools, retrievers that fetch chunks of documents) into agents (a model plus tools in a loop) and pipelines.

⚡ When to use no framework

Meaning: Use no framework for a small endpoint with one provider, a backend that isn't JavaScript, or when you look for a bug in the layer underneath (the code a framework wraps). Validation, permissions, confirming write tools and keeping the API key on the server are still your job.

What you will learn