github langchain-ai/langchainjs langchain==1.0.0-alpha.4

latest releases: langchain==0.3.33, @langchain/core==0.3.74, @langchain/openai==0.6.11...
pre-release3 days ago

Release range: langchain==0.3.30langchain==1.0.0-alpha.1
Compare: langchain==0.3.30...langchain==1.0.0-alpha.1


💥 Breaking changes

  • Require Node.js ≥ 20
    Langchain packages now require Node 20+ (.nvmrc is on Node 24 for development). Update your engines and CI accordingly. (GitHub)

    // package.json
    { "engines": { "node": ">=20" } }
  • Removed legacy subpath exports (cleaner surface area)

    • langchain/schema/prompt_templateuse langchain/prompts. (GitHub, api.js.langchain.com)

      - import { PromptTemplate } from "langchain/schema/prompt_template";
      + import { PromptTemplate } from "langchain/prompts";
    • langchain/schema/query_constructoruse langchain/chains/query_constructor. (GitHub, v03.api.js.langchain.com, Langchain)

      - import type { AttributeInfo } from "langchain/schema/query_constructor";
      + import type { AttributeInfo } from "langchain/chains/query_constructor";
    • langchain/runnables/remote export removed. If you used this entrypoint, migrate off this subpath (no 1:1 replacement export in langchain package). (GitHub)

    • langchain/smith export path removed from langchain. Use the separate langsmith package and opt-in (see below). (GitHub)

  • Callbacks removed from langchain
    The ./callbacks entrypoint is gone. Prefer LCEL observability (runnables), agent/tool messages, or provider-native hooks instead. (GitHub)

    - import { ... } from "langchain/callbacks";
    // Replace with runnable config / tracing via LangSmith (optional) or agent nodes.

✨ Features

  • langchain now exports most important user primitives
    The langchain package now exports the most important user primitives, including tool, HumanMessage, AIMessage, SystemMessage, ToolNode, createAgent, and more.

    import { tool, HumanMessage, createAgent } from "langchain";
  • createAgent is now part of core langchain
    The React-style agent lives under the langchain project (with examples + tests). Import directly from langchain. (GitHub)

    import { createAgent, HumanMessage, tool } from "langchain";
    import { z } from "zod";
    
    const getWeather = tool({
      name: "getWeather",
      description: "Get current weather by city",
      schema: z.object({ city: z.string() }),
      func: async ({ city }) => `Sunny in ${city}`
    });
    
    const agent = await createAgent({
      // New: pass a model by name (string) or a model instance
      model: "claude-3-5-sonnet-20240620",
      tools: [getWeather],
      responseFormat: z.object({ answer: z.string() }),
    });
    
    const res = await agent.invoke(new HumanMessage("Weather in SF?"));
    console.log(res);

    Now you can pass in a “model as string” option to define the model to use. (GitHub)

  • ToolNode exported from langchain
    Build agent graphs that execute tools as a node. This makes tool execution composable within LCEL/graph flows.

    import { ToolNode, tool, HumanMessage } from "langchain";
    
    const fail = tool({
      name: "alwaysFails",
      description: "Demo failing tool",
      schema: {},
      func: async () => { throw new Error("Boom"); }
    });
    
    const node = new ToolNode([fail]);
    const out = await node.invoke({ messages: [new HumanMessage("Try it")] });
  • Default tool-error handling in agents
    When handleToolErrors is true (default), tool exceptions are caught and converted into a ToolMessage so the agent can recover. Set it to false to surface raw errors for strict workflows. (GitHub)

    import { ToolNode } from "langchain/agents";
    
    // default: handleToolErrors: true → returns a ToolMessage with error text
    const forgiving = new ToolNode([/* tools */]);
    
    // strict: throw on tool error
    const strict = new ToolNode([/* tools */], { handleToolErrors: false });

🐛 Fixes

  • langsmith made optional
    LangSmith is no longer a hard dependency; the package is loaded dynamically only when you use features that need it. If you rely on eval/tracing/hub, add it explicitly:
    pnpm add langsmith (or yarn/npm). (GitHub)

  • Removed js-tiktoken dependency
    The package was dropped from deps; related types are sourced via the relevant provider packages (e.g. @langchain/openai). If you had direct imports, adjust accordingly. (GitHub)


🧹 Chores / Internal

  • New tsdown-based build system (faster, simpler internal builds). (GitHub)
  • Repo migrated to pnpm (lockfile + scripts updated). (GitHub)
  • Rearranged packages and updated CI/workflows. (GitHub)
  • Removed experimental and unused files/exports (./indexes, ./document_transformers/openai_functions, agents cleanup). User-visible API impact covered above via export removals; the rest is housekeeping to keep the surface tight. (GitHub)
  • Environment tests rewritten in TS and expanded to verify export maps across bundlers/runtimes. (GitHub)

🧭 Migration quick-guide

  1. Node version

    • Set engines.node to >=20 and update CI runners. (GitHub)
  2. Imports / subpaths

    • schema/prompt_templatelangchain/prompts (e.g., PromptTemplate). (GitHub, api.js.langchain.com)
    • schema/query_constructorlangchain/chains/query_constructor (IR types, translators, etc.). (GitHub, v03.api.js.langchain.com, Langchain)
    • Remove langchain/runnables/remote usage; no longer exported. (GitHub)
    • Remove langchain/smith import; install and import from langsmith if needed. (GitHub)
  3. Agents

    • Import prebuilt agents from langchain directly, e.g. import { createAgent } from "langchain".
    • You can pass model as a model name string to createAgent. (GitHub)
      const agent = createAgent({
        model: "openai:gpt-4o-mini",
        tools: [/* tools */],
        responseFormat: z.object({ answer: z.string() }),
      });
    • Use ToolNode to encapsulate tool execution in graphs.
    • Decide on error policy: default soft-handling vs strict throws in ToolNode via handleToolErrors. (GitHub)
  4. LangSmith & tokenization

    • Add langsmith explicitly if you use tracing/eval/hub. (GitHub)
    • If you previously relied on js-tiktoken, remove it from your app unless you need it directly. (GitHub)

Don't miss a new langchainjs release

NewReleases is sending notifications on new releases.