LLM object must define bindTools method when using createSupervisor with ChatOpenAI #262

Closed
opened 2026-02-15 18:15:12 -05:00 by yindo · 18 comments
Owner

Originally created by @sid-js on GitHub (May 24, 2025).

Description

When attempting to run the supervisor example from LangGraph documentation using a ChatOpenAI instance, the following error occurs:

Error: llm [object Object] must define bindTools method.
    at getModelRunnable (/node_modules/@langchain/langgraph/src/prebuilt/react_agent_executor.ts:510:15)
    at async RunnableCallable.callModel (/node_modules/@langchain/langgraph/src/prebuilt/react_agent_executor.ts:591:27) {
  pregelTaskId: '51ba37fb-7cb6-5322-b038-755f006e0347'
}

Reproduction Steps

  1. Use the Quickstart example provided in Langgraph repository
const model = new ChatOpenAI({
  model: "gpt-3.5-turbo",
});
const add = tool(async (args) => args.a + args.b, {
  name: "add",
  description: "Add two numbers.",
  schema: z.object({
    a: z.number(),
    b: z.number(),
  }),
});

const multiply = tool(async (args) => args.a * args.b, {
  name: "multiply",
  description: "Multiply two numbers.",
  schema: z.object({
    a: z.number(),
    b: z.number(),
  }),
});

const webSearch = tool(
  async (args) => {
    return (
      "Here are the headcounts for each of the FAANG companies in 2024:\n" +
      "1. **Facebook (Meta)**: 67,317 employees.\n" +
      "2. **Apple**: 164,000 employees.\n" +
      "3. **Amazon**: 1,551,000 employees.\n" +
      "4. **Netflix**: 14,000 employees.\n" +
      "5. **Google (Alphabet)**: 181,269 employees."
    );
  },
  {
    name: "web_search",
    description: "Search the web for information.",
    schema: z.object({
      query: z.string(),
    }),
  }
);

const mathAgent = createReactAgent({
  llm: model,
  tools: [add, multiply],
  name: "math_expert",
  prompt: "You are a math expert. Always use one tool at a time.",
});

const researchAgent = createReactAgent({
  llm: model,
  tools: [webSearch],
  name: "research_expert",
  prompt:
    "You are a world class researcher with access to web search. Do not do any math.",
});

// Create supervisor workflow
const workflow = createSupervisor({
  agents: [researchAgent, mathAgent],
  llm: model,
  prompt:
    "You are a team supervisor managing a research expert and a math expert. " +
    "For current events, use research_agent. " +
    "For math problems, use math_agent.",
});

// Compile and run
const app = workflow.compile();
const result = await app.invoke({
  messages: [
    {
      role: "user",
      content: "what's the combined headcount of the FAANG companies in 2024??",
    },
  ],
});

Expected Behavior

The supervisor example should work with any LLM that implements the required interface, including ChatOpenAI instances. The supervisor should be able to coordinate between the specialized agents (math and research) to answer complex questions.

Actual Behavior

The code throws an error indicating that the LLM object must define a bindTools method, which appears to be missing from the ChatOpenAI implementation. This prevents the supervisor from properly initializing and coordinating the agents.

Environment

  • Node.js version: v23.11.0
  • @langchain/langgraph version: 0.2.73
  • @langchain/openai version: 0.5.11
  • @langchain/core version: 0.3.57
  • @langchain/langgraph-supervisor version: 0.0.12

Additional Context

This issue appears to be related to the integration between LangGraph's supervisor implementation and the ChatOpenAI class. The error suggests that there might be a missing interface implementation or a version mismatch between the packages. This is particularly problematic as it affects the core functionality of the supervisor pattern, which is a key feature of LangGraph.

Originally created by @sid-js on GitHub (May 24, 2025). ## Description When attempting to run the supervisor example from LangGraph documentation using a ChatOpenAI instance, the following error occurs: ``` Error: llm [object Object] must define bindTools method. at getModelRunnable (/node_modules/@langchain/langgraph/src/prebuilt/react_agent_executor.ts:510:15) at async RunnableCallable.callModel (/node_modules/@langchain/langgraph/src/prebuilt/react_agent_executor.ts:591:27) { pregelTaskId: '51ba37fb-7cb6-5322-b038-755f006e0347' } ``` ## Reproduction Steps 1. Use the Quickstart example provided in [Langgraph repository](https://github.com/langchain-ai/langgraphjs/tree/main/libs/langgraph-supervisor) ```typescript const model = new ChatOpenAI({ model: "gpt-3.5-turbo", }); const add = tool(async (args) => args.a + args.b, { name: "add", description: "Add two numbers.", schema: z.object({ a: z.number(), b: z.number(), }), }); const multiply = tool(async (args) => args.a * args.b, { name: "multiply", description: "Multiply two numbers.", schema: z.object({ a: z.number(), b: z.number(), }), }); const webSearch = tool( async (args) => { return ( "Here are the headcounts for each of the FAANG companies in 2024:\n" + "1. **Facebook (Meta)**: 67,317 employees.\n" + "2. **Apple**: 164,000 employees.\n" + "3. **Amazon**: 1,551,000 employees.\n" + "4. **Netflix**: 14,000 employees.\n" + "5. **Google (Alphabet)**: 181,269 employees." ); }, { name: "web_search", description: "Search the web for information.", schema: z.object({ query: z.string(), }), } ); const mathAgent = createReactAgent({ llm: model, tools: [add, multiply], name: "math_expert", prompt: "You are a math expert. Always use one tool at a time.", }); const researchAgent = createReactAgent({ llm: model, tools: [webSearch], name: "research_expert", prompt: "You are a world class researcher with access to web search. Do not do any math.", }); // Create supervisor workflow const workflow = createSupervisor({ agents: [researchAgent, mathAgent], llm: model, prompt: "You are a team supervisor managing a research expert and a math expert. " + "For current events, use research_agent. " + "For math problems, use math_agent.", }); // Compile and run const app = workflow.compile(); const result = await app.invoke({ messages: [ { role: "user", content: "what's the combined headcount of the FAANG companies in 2024??", }, ], }); ``` ## Expected Behavior The supervisor example should work with any LLM that implements the required interface, including ChatOpenAI instances. The supervisor should be able to coordinate between the specialized agents (math and research) to answer complex questions. ## Actual Behavior The code throws an error indicating that the LLM object must define a `bindTools` method, which appears to be missing from the ChatOpenAI implementation. This prevents the supervisor from properly initializing and coordinating the agents. ## Environment - Node.js version: v23.11.0 - @langchain/langgraph version: 0.2.73 - @langchain/openai version: 0.5.11 - @langchain/core version: 0.3.57 - @langchain/langgraph-supervisor version: 0.0.12 ## Additional Context This issue appears to be related to the integration between LangGraph's supervisor implementation and the ChatOpenAI class. The error suggests that there might be a missing interface implementation or a version mismatch between the packages. This is particularly problematic as it affects the core functionality of the supervisor pattern, which is a key feature of LangGraph.
yindo added the bug label 2026-02-15 18:15:12 -05:00
yindo closed this issue 2026-02-15 18:15:12 -05:00
Author
Owner

@sid-js commented on GitHub (May 24, 2025):

Update: I tested the same code with @langchain/openai version 0.5.10 and it works perfectly fine, suggesting this is an issue in version 0.5.11.

@sid-js commented on GitHub (May 24, 2025): Update: I tested the same code with `@langchain/openai version 0.5.10` and it works perfectly fine, suggesting this is an issue in version 0.5.11.
Author
Owner

@sp-aaflalo commented on GitHub (Jun 3, 2025):

Can confirm, downgrading to 0.5.10 works for me too.

Any news about this issue ?

@sp-aaflalo commented on GitHub (Jun 3, 2025): Can confirm, downgrading to 0.5.10 works for me too. Any news about this issue ?
Author
Owner

@gyanendrasng commented on GitHub (Jun 4, 2025):

downgrading didnt work for me, I can see that the function is there, still gives the error

@gyanendrasng commented on GitHub (Jun 4, 2025): downgrading didnt work for me, I can see that the function is there, still gives the error
Author
Owner

@0xbadshah commented on GitHub (Jun 5, 2025):

@gyanendrasng Maybe you haven't updated your package-lock.json file. Does npm list show +-- @langchain/openai@0.5.10?

@0xbadshah commented on GitHub (Jun 5, 2025): @gyanendrasng Maybe you haven't updated your package-lock.json file. Does `npm list` show `+-- @langchain/openai@0.5.10`?
Author
Owner

@sp-aaflalo commented on GitHub (Jun 5, 2025):

Maybe @dqbd can help us with this since he seems to be the maintainer of the supervisor package.

@sp-aaflalo commented on GitHub (Jun 5, 2025): Maybe @dqbd can help us with this since he seems to be the maintainer of the supervisor package.
Author
Owner

@inno-odyssean commented on GitHub (Jun 6, 2025):

having same issue with vertex-ai. is it even compatible with this

@inno-odyssean commented on GitHub (Jun 6, 2025): having same issue with vertex-ai. is it even compatible with this
Author
Owner

@simon28082 commented on GitHub (Jun 8, 2025):

Same issue

@simon28082 commented on GitHub (Jun 8, 2025): Same issue
Author
Owner

@jackharrhy commented on GitHub (Jun 9, 2025):

I'm not using createSupervisor, I have a plain const llm = new ChatOpenAI(...) instance, and if I chain it with withConfig, if I pass this llm instance to createReactAgent, I get the same error, without the withConfig, everything is fine.

I initially thought this might have been langgraph being funky, but this exception / guard clause:

if (!("bindTools" in llm) || typeof llm.bindTools !== "function") {
  throw new Error(`llm ${llm} must define bindTools method.`);
}

If I do instead use .withConfig just before the .invoke, things seem fine, but then (in my specific context) streaming broke, not sure if it was because of the feature I was using or using .withConfig in the way I was doing it

Just brain dumping my day for others maybe to pull from

@jackharrhy commented on GitHub (Jun 9, 2025): I'm not using createSupervisor, I have a plain `const llm = new ChatOpenAI(...)` instance, and if I chain it with `withConfig`, if I pass this `llm` instance to `createReactAgent`, I get the same error, without the `withConfig`, everything is fine. I initially thought this might have been langgraph being funky, but this exception / guard clause: ```ts if (!("bindTools" in llm) || typeof llm.bindTools !== "function") { throw new Error(`llm ${llm} must define bindTools method.`); } ``` If I do instead use `.withConfig` just before the `.invoke`, things seem fine, but then (in my specific context) streaming broke, not sure if it was because of the feature I was using or using `.withConfig` in the way I was doing it Just brain dumping my day for others maybe to pull from
Author
Owner

@hpirela commented on GitHub (Jun 18, 2025):

same issue

@hpirela commented on GitHub (Jun 18, 2025): same issue
Author
Owner

@hpirela commented on GitHub (Jun 18, 2025):

My 2 cent contribution,
the issue is when the supervisor handle the specific case of parallel tools for a chatOpenAi model, on that particular case hte supervisor.ts code on line 213-220 overwrite the supervisorLLM variable that originally have the of the provided LL with the return of that llm.bindTool(..) call and that new value dont have a BindTools Method.
if (isChatModelWithBindTools(llm)) {
if (
isChatModelWithParallelToolCallsParam(llm) &&
PROVIDERS_WITH_PARALLEL_TOOL_CALLS_PARAM.has(llm.getName())
) {
supervisorLLM = llm.bindTools(allTools, { parallel_tool_calls: false });

} else {
    supervisorLLM = llm.bindTools(allTools);

}

}
Workaround: I copy the supervisor.ts and handoff.ts code on my project reference to it and comment those lines.
how this can help

@hpirela commented on GitHub (Jun 18, 2025): My 2 cent contribution, the issue is when the supervisor handle the specific case of parallel tools for a chatOpenAi model, on that particular case hte supervisor.ts code on line 213-220 overwrite the supervisorLLM variable that originally have the of the provided LL with the return of that llm.bindTool(..) call and that new value dont have a BindTools Method. if (isChatModelWithBindTools(llm)) { if ( isChatModelWithParallelToolCallsParam(llm) && PROVIDERS_WITH_PARALLEL_TOOL_CALLS_PARAM.has(llm.getName()) ) { **supervisorLLM = llm.bindTools(allTools, { parallel_tool_calls: false });** } else { supervisorLLM = llm.bindTools(allTools); } } Workaround: I copy the supervisor.ts and handoff.ts code on my project reference to it and comment those lines. how this can help
Author
Owner

@bruno353 commented on GitHub (Jun 18, 2025):

For anyone trying to use Gemini with LangGraph and running into bindTools problems:

You can create a temporary monkey-patch that wraps the bindTools function and returns a version that still supports tool calling. The underlying issue is that, when the Supervisor helper runs, it calls

llm.bindTools(allTools, { parallel_tool_calls: false });

but @langchain/google-genai currently accepts only a single argument. Because of that mismatch, LangGraph assumes the model doesn’t support tool calls and continues without them.

I work around this by creating a patch like:

// patchGemini.ts
import { ChatGoogleGenerativeAI } from "@langchain/google-genai";

export function patchGemini(llm: ChatGoogleGenerativeAI) {
  if (typeof llm.bindTools !== "function") {
    llm.bindTools = () => llm;
  }

  const original = llm.bindTools;
  llm.bindTools = function (tools: any, opts?: any) {
    console.log(
      "[patchGemini] bindTools called:",
      Array.isArray(tools) ? tools.map(t => t.name || t).join(", ") : Object.keys(tools || {}),
      opts ?? "-"
    );
    const out = original.call(this, tools, opts);
    out.bindTools = llm.bindTools;
    return out;
  };
  return llm;
}

Then, when instantiating the model, do something like:

  protected readonly llm = patchGemini(
    new ChatGoogleGenerativeAI({
      model: "gemini-2.5-flash",
      apiKey: process.env.GEMINI_API_KEY,
    })
  );
@bruno353 commented on GitHub (Jun 18, 2025): For anyone trying to use Gemini with LangGraph and running into bindTools problems: You can create a temporary monkey-patch that wraps the bindTools function and returns a version that still supports tool calling. The underlying issue is that, when the Supervisor helper runs, it calls `llm.bindTools(allTools, { parallel_tool_calls: false }); ` but @langchain/google-genai currently accepts only a single argument. Because of that mismatch, LangGraph assumes the model doesn’t support tool calls and continues without them. I work around this by creating a patch like: ``` // patchGemini.ts import { ChatGoogleGenerativeAI } from "@langchain/google-genai"; export function patchGemini(llm: ChatGoogleGenerativeAI) { if (typeof llm.bindTools !== "function") { llm.bindTools = () => llm; } const original = llm.bindTools; llm.bindTools = function (tools: any, opts?: any) { console.log( "[patchGemini] bindTools called:", Array.isArray(tools) ? tools.map(t => t.name || t).join(", ") : Object.keys(tools || {}), opts ?? "-" ); const out = original.call(this, tools, opts); out.bindTools = llm.bindTools; return out; }; return llm; } ``` Then, when instantiating the model, do something like: ``` protected readonly llm = patchGemini( new ChatGoogleGenerativeAI({ model: "gemini-2.5-flash", apiKey: process.env.GEMINI_API_KEY, }) ); ```
Author
Owner

@sachanritik1 commented on GitHub (Jun 22, 2025):

for me it worked with "@langchain/openai": "^0.4.5" version.

maybe because this version is of same time when supervisor just came out.

@sachanritik1 commented on GitHub (Jun 22, 2025): for me it worked with "@langchain/openai": "^0.4.5" version. maybe because this version is of same time when supervisor just came out.
Author
Owner

@suvasishm commented on GitHub (Jun 30, 2025):

Facing the same problem. Downgrading to "@langchain/openai": "^0.4.9" worked. What is wrong with 0.5.*? Any fix in line? @langchain-ai @bracesproul

@suvasishm commented on GitHub (Jun 30, 2025): Facing the same problem. Downgrading to `"@langchain/openai": "^0.4.9"` worked. What is wrong with `0.5.*`? Any fix in line? @langchain-ai @bracesproul
Author
Owner

@RishikeshDarandale commented on GitHub (Jul 1, 2025):

Facing the same problem. Downgrading to "@langchain/openai": "^0.4.9" worked. What is wrong with 0.5.*? Any fix in line? @langchain-ai @bracesproul

works with 0.5.10 as mentioned by @sid-js , @sp-aaflalo , but not with latest 0.5.16!

@RishikeshDarandale commented on GitHub (Jul 1, 2025): > Facing the same problem. Downgrading to `"@langchain/openai": "^0.4.9"` worked. What is wrong with `0.5.*`? Any fix in line? [@langchain-ai](https://github.com/langchain-ai) [@bracesproul](https://github.com/bracesproul) works with `0.5.10` as mentioned by @sid-js , @sp-aaflalo , but not with latest `0.5.16`!
Author
Owner

@g-abani commented on GitHub (Jul 1, 2025):

Will it be addressed in the upcoming v1 release? How safe it is to consider LangGraph for a production use case, considering Supervisor pattern is the ideal pattern for our use case. With the ongoing issue in createSupervisor implementation (Azure OpenAI), I am bit sceptical to explore LangGrpah further. @langchain-ai

@g-abani commented on GitHub (Jul 1, 2025): Will it be addressed in the upcoming v1 release? How safe it is to consider LangGraph for a production use case, considering Supervisor pattern is the ideal pattern for our use case. With the ongoing issue in ```createSupervisor``` implementation (Azure OpenAI), I am bit sceptical to explore **LangGrpah** further. @langchain-ai
Author
Owner

@hitmands commented on GitHub (Jul 7, 2025):

Error: llm [object Object] must define bindTools method.

this issue persists on 0.5.18 as well, wouldn't it make sense to revert?
unable to onboard any patch until this is fixed.

@hitmands commented on GitHub (Jul 7, 2025): ``` Error: llm [object Object] must define bindTools method. ``` this issue persists on `0.5.18` as well, wouldn't it make sense to revert? unable to onboard any patch until this is fixed.
Author
Owner

@dqbd commented on GitHub (Jul 7, 2025):

Hello! Sorry about the issue. Cut @langchain/langgraph-supervisor@0.0.15 that should fix the issue for @langchain/openai>=0.5.11.

@dqbd commented on GitHub (Jul 7, 2025): Hello! Sorry about the issue. Cut `@langchain/langgraph-supervisor@0.0.15` that should fix the issue for `@langchain/openai>=0.5.11`.
Author
Owner

@g-abani commented on GitHub (Jul 9, 2025):

thank you for the fix. verified with @langchain/langgraph-supervisor@0.0.15 and Azure Chat Open AI. It worked with out any issue.

"dependencies": {
    "@langchain/langgraph-supervisor": "^0.0.15",
    "@langchain/openai": "^0.5.18",
    "dotenv": "^17.1.0",
    "langchain": "^0.3.29",
    "openai": "^5.8.3"
  }
@g-abani commented on GitHub (Jul 9, 2025): thank you for the fix. verified with `@langchain/langgraph-supervisor@0.0.15` and `Azure Chat Open AI`. It worked with out any issue. ``` "dependencies": { "@langchain/langgraph-supervisor": "^0.0.15", "@langchain/openai": "^0.5.18", "dotenv": "^17.1.0", "langchain": "^0.3.29", "openai": "^5.8.3" } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#262