The requested module '@langchain/core/messages' does not provide an export named 'isToolMessage' #269

Closed
opened 2026-02-15 18:15:19 -05:00 by yindo · 1 comment
Owner

Originally created by @kangchuming on GitHub (May 27, 2025).

Checked other resources

  • This is a bug, not a usage question. For questions, please use GitHub Discussions.
  • I added a clear and detailed title that summarizes the issue.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.

Example Code

import { TavilySearchResults } from "@langchain/community/tools/tavily_search";
import { ChatOpenAI } from "@langchain/openai";
import { HumanMessage, AIMessage } from "@langchain/core/messages";
import { ToolNode } from "@langchain/langgraph/prebuilt";
import { StateGraph, MessagesAnnotation } from "@langchain/langgraph";

// Define the tools for the agent to use
const tools = [new TavilySearchResults({ maxResults: 3 })];
const toolNode = new ToolNode(tools);

// Create a model and give it access to the tools
const model = new ChatOpenAI({
  model: "gpt-4o-mini",
  temperature: 0,
}).bindTools(tools);

// Define the function that determines whether to continue or not
function shouldContinue({ messages }: typeof MessagesAnnotation.State) {
  const lastMessage = messages[messages.length - 1] as AIMessage;

  // If the LLM makes a tool call, then we route to the "tools" node
  if (lastMessage.tool_calls?.length) {
    return "tools";
  }
  // Otherwise, we stop (reply to the user) using the special "__end__" node
  return "__end__";
}

// Define the function that calls the model
async function callModel(state: typeof MessagesAnnotation.State) {
  const response = await model.invoke(state.messages);

  // We return a list, because this will get added to the existing list
  return { messages: [response] };
}

// Define a new graph
const workflow = new StateGraph(MessagesAnnotation)
  .addNode("agent", callModel)
  .addEdge("__start__", "agent") // __start__ is a special name for the entrypoint
  .addNode("tools", toolNode)
  .addEdge("tools", "agent")
  .addConditionalEdges("agent", shouldContinue);

// Finally, we compile it into a LangChain Runnable.
const app = workflow.compile();

// Use the agent
const finalState = await app.invoke({
  messages: [new HumanMessage("what is the weather in sf")],
});
console.log(finalState.messages[finalState.messages.length - 1].content);

const nextState = await app.invoke({
  // Including the messages from the previous run gives the LLM context.
  // This way it knows we're asking about the weather in NY
  messages: [...finalState.messages, new HumanMessage("what about ny")],
});
console.log(nextState.messages[nextState.messages.length - 1].content);

Error Message and Stack Trace (if applicable)

file:///D:/code/paper_generation/src/server/node_modules/.pnpm/@langchain+langgraph@0.2.57_74c00b83a584f8020ab221a65b02c2c2/node_modules/@langchain/langgraph/dist/pregel/messages.js:2
import { AIMessageChunk, isBaseMessage, isBaseMessageChunk, isToolMessage, } from "@langchain/core/messages";
                                                            ^^^^^^^^^^^^^
SyntaxError: The requested module '@langchain/core/messages' does not provide an export named 'isToolMessage'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:191:5)
    at async ModuleLoader.import (node:internal/modules/esm/loader:337:24)
    at async loadESM (node:internal/process/esm_loader:34:7)
    at async handleMainPromise (node:internal/modules/run_main:106:12)

Node.js v18.20.8

Description

GitHub Issue 描述(英文)

Title: SyntaxError: The requested module '@langchain/core/messages' does not provide an export named 'isToolMessage' when using LangGraph tutorial code

Body:

I followed the LangGraph.js Quickstart guide (specifically the Customizing agent behavior section) and encountered an error during execution. Here are the details:


Error Message:

file:///D:/code/paper_generation/src/server/node_modules/.pnpm/@langchain+langgraph@0.2.57_74c00b83a584f8020ab221a65b02c2c2/node_modules/@langchain/langgraph/dist/pregel/messages.js:2
import { AIMessageChunk, isBaseMessage, isBaseMessageChunk, isToolMessage, } from "@langchain/core/messages";
                                                            ^^^^^^^^^^^^^
SyntaxError: The requested module '@langchain/core/messages' does not provide an export named 'isToolMessage'

Environment:

  • Node.js version: 18 or newer
  • Dependency versions:
    "dependencies": {
      "@langchain/community": "^0.3.36",
      "@langchain/core": "0.3.0",
      "@langchain/langgraph": "^0.2.57",
      "@langchain/openai": "^0.4.5"
    }
    

Relevant Code:

// agent.ts
import { TavilySearchResults } from "@langchain/community/tools/tavily_search";
import { ChatOpenAI } from "@langchain/openai";
import { HumanMessage, AIMessage } from "@langchain/core/messages";
import { ToolNode } from "@langchain/langgraph/prebuilt";
import { StateGraph, MessagesAnnotation } from "@langchain/langgraph";

// Define tools and model
const tools = [new TavilySearchResults({ maxResults: 3 })];
const toolNode = new ToolNode(tools);
const model = new ChatOpenAI({ temperature: 0 }).bindTools(tools);

// Custom logic for agent flow
function shouldContinue({ messages }: typeof MessagesAnnotation.State) {
  const lastMessage = messages[messages.length - 1] as AIMessage;
  if (lastMessage.tool_calls?.length) {
    return "tools";
  }
  return "__end__";
}

async function callModel(state: typeof MessagesAnnotation.State) {
  const response = await model.invoke(state.messages);
  return { messages: [response] };
}

// Build the graph
const workflow = new StateGraph(MessagesAnnotation)
  .addNode("agent", callModel)
  .addEdge("__start__", "agent")
  .addNode("tools", toolNode)
  .addEdge("tools", "agent")
  .addConditionalEdges("agent", shouldContinue);

const app = workflow.compile();

// Run the agent
const finalState = await app.invoke({
  messages: [new HumanMessage("what is the weather in sf")],
});
console.log(finalState.messages[finalState.messages.length - 1].content);

Steps to Reproduce:

  1. Follow the LangGraph Quickstart guide.
  2. Use the "Customizing agent behavior" code example.
  3. Run the script with Node.js.

Expected Behavior:
The agent should execute without errors and return weather information for San Francisco and New York.


Actual Behavior:
A SyntaxError occurs because @langchain/langgraph attempts to import isToolMessage from @langchain/core/messages, but this export does not exist in @langchain/core@0.3.0.


Additional Context:

  • I suspect this might be a version mismatch between @langchain/core and @langchain/langgraph. The isToolMessage utility may have been renamed, removed, or moved in core@0.3.0.
  • I tried downgrading @langchain/core to earlier versions (e.g., 0.2.x) but ran into other compatibility issues.

Questions:

  1. Is there a known version compatibility matrix for @langchain/core and @langchain/langgraph?
  2. How can I resolve this error while keeping the tutorial code functional?

System Info

Node.js v18.20.8

Originally created by @kangchuming on GitHub (May 27, 2025). ### Checked other resources - [x] This is a bug, not a usage question. For questions, please use GitHub Discussions. - [x] I added a clear and detailed title that summarizes the issue. - [x] I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example). - [x] I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue. ### Example Code ```python import { TavilySearchResults } from "@langchain/community/tools/tavily_search"; import { ChatOpenAI } from "@langchain/openai"; import { HumanMessage, AIMessage } from "@langchain/core/messages"; import { ToolNode } from "@langchain/langgraph/prebuilt"; import { StateGraph, MessagesAnnotation } from "@langchain/langgraph"; // Define the tools for the agent to use const tools = [new TavilySearchResults({ maxResults: 3 })]; const toolNode = new ToolNode(tools); // Create a model and give it access to the tools const model = new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0, }).bindTools(tools); // Define the function that determines whether to continue or not function shouldContinue({ messages }: typeof MessagesAnnotation.State) { const lastMessage = messages[messages.length - 1] as AIMessage; // If the LLM makes a tool call, then we route to the "tools" node if (lastMessage.tool_calls?.length) { return "tools"; } // Otherwise, we stop (reply to the user) using the special "__end__" node return "__end__"; } // Define the function that calls the model async function callModel(state: typeof MessagesAnnotation.State) { const response = await model.invoke(state.messages); // We return a list, because this will get added to the existing list return { messages: [response] }; } // Define a new graph const workflow = new StateGraph(MessagesAnnotation) .addNode("agent", callModel) .addEdge("__start__", "agent") // __start__ is a special name for the entrypoint .addNode("tools", toolNode) .addEdge("tools", "agent") .addConditionalEdges("agent", shouldContinue); // Finally, we compile it into a LangChain Runnable. const app = workflow.compile(); // Use the agent const finalState = await app.invoke({ messages: [new HumanMessage("what is the weather in sf")], }); console.log(finalState.messages[finalState.messages.length - 1].content); const nextState = await app.invoke({ // Including the messages from the previous run gives the LLM context. // This way it knows we're asking about the weather in NY messages: [...finalState.messages, new HumanMessage("what about ny")], }); console.log(nextState.messages[nextState.messages.length - 1].content); ``` ### Error Message and Stack Trace (if applicable) ```shell file:///D:/code/paper_generation/src/server/node_modules/.pnpm/@langchain+langgraph@0.2.57_74c00b83a584f8020ab221a65b02c2c2/node_modules/@langchain/langgraph/dist/pregel/messages.js:2 import { AIMessageChunk, isBaseMessage, isBaseMessageChunk, isToolMessage, } from "@langchain/core/messages"; ^^^^^^^^^^^^^ SyntaxError: The requested module '@langchain/core/messages' does not provide an export named 'isToolMessage' at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21) at async ModuleJob.run (node:internal/modules/esm/module_job:191:5) at async ModuleLoader.import (node:internal/modules/esm/loader:337:24) at async loadESM (node:internal/process/esm_loader:34:7) at async handleMainPromise (node:internal/modules/run_main:106:12) Node.js v18.20.8 ``` ### Description ### GitHub Issue 描述(英文) **Title:** `SyntaxError: The requested module '@langchain/core/messages' does not provide an export named 'isToolMessage'` when using LangGraph tutorial code **Body:** I followed the LangGraph.js Quickstart guide (specifically the [Customizing agent behavior](https://langchain-ai.github.io/langgraphjs/tutorials/quickstart/#customizing-agent-behavior) section) and encountered an error during execution. Here are the details: --- **Error Message:** ``` file:///D:/code/paper_generation/src/server/node_modules/.pnpm/@langchain+langgraph@0.2.57_74c00b83a584f8020ab221a65b02c2c2/node_modules/@langchain/langgraph/dist/pregel/messages.js:2 import { AIMessageChunk, isBaseMessage, isBaseMessageChunk, isToolMessage, } from "@langchain/core/messages"; ^^^^^^^^^^^^^ SyntaxError: The requested module '@langchain/core/messages' does not provide an export named 'isToolMessage' ``` --- **Environment:** - Node.js version: 18 or newer - Dependency versions: ```json "dependencies": { "@langchain/community": "^0.3.36", "@langchain/core": "0.3.0", "@langchain/langgraph": "^0.2.57", "@langchain/openai": "^0.4.5" } ``` --- **Relevant Code:** ```ts // agent.ts import { TavilySearchResults } from "@langchain/community/tools/tavily_search"; import { ChatOpenAI } from "@langchain/openai"; import { HumanMessage, AIMessage } from "@langchain/core/messages"; import { ToolNode } from "@langchain/langgraph/prebuilt"; import { StateGraph, MessagesAnnotation } from "@langchain/langgraph"; // Define tools and model const tools = [new TavilySearchResults({ maxResults: 3 })]; const toolNode = new ToolNode(tools); const model = new ChatOpenAI({ temperature: 0 }).bindTools(tools); // Custom logic for agent flow function shouldContinue({ messages }: typeof MessagesAnnotation.State) { const lastMessage = messages[messages.length - 1] as AIMessage; if (lastMessage.tool_calls?.length) { return "tools"; } return "__end__"; } async function callModel(state: typeof MessagesAnnotation.State) { const response = await model.invoke(state.messages); return { messages: [response] }; } // Build the graph const workflow = new StateGraph(MessagesAnnotation) .addNode("agent", callModel) .addEdge("__start__", "agent") .addNode("tools", toolNode) .addEdge("tools", "agent") .addConditionalEdges("agent", shouldContinue); const app = workflow.compile(); // Run the agent const finalState = await app.invoke({ messages: [new HumanMessage("what is the weather in sf")], }); console.log(finalState.messages[finalState.messages.length - 1].content); ``` --- **Steps to Reproduce:** 1. Follow the [LangGraph Quickstart](https://langchain-ai.github.io/langgraphjs/tutorials/quickstart/) guide. 2. Use the "Customizing agent behavior" code example. 3. Run the script with Node.js. --- **Expected Behavior:** The agent should execute without errors and return weather information for San Francisco and New York. --- **Actual Behavior:** A `SyntaxError` occurs because `@langchain/langgraph` attempts to import `isToolMessage` from `@langchain/core/messages`, but this export does not exist in `@langchain/core@0.3.0`. --- **Additional Context:** - I suspect this might be a version mismatch between `@langchain/core` and `@langchain/langgraph`. The `isToolMessage` utility may have been renamed, removed, or moved in `core@0.3.0`. - I tried downgrading `@langchain/core` to earlier versions (e.g., `0.2.x`) but ran into other compatibility issues. --- **Questions:** 1. Is there a known version compatibility matrix for `@langchain/core` and `@langchain/langgraph`? 2. How can I resolve this error while keeping the tutorial code functional? ### System Info Node.js v18.20.8
yindo closed this issue 2026-02-15 18:15:19 -05:00
Author
Owner

@dqbd commented on GitHub (May 28, 2025):

Hello @kangchuming! Looking at the package.json, I believe that you're running an outdated version of @langchain/core. Please upgrade to @langchain/core>0.3.40

@dqbd commented on GitHub (May 28, 2025): Hello @kangchuming! Looking at the `package.json`, I believe that you're running an outdated version of `@langchain/core`. Please upgrade to `@langchain/core>0.3.40`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#269