Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Agents · Const

Tool choice

tool_choice controls whether a model must call a bound tool. In the JavaScript workflow, tool_choice: "any" forces a tool call for a dedicated agent step.

How it works

Tool choice configures how a model uses bound tools. In the documented JavaScript workflow, passing tool_choice: "any" to bindTools forces the model to select a tool, which is useful when a workflow step must perform a tool operation before continuing.

Syntax

model.bindTools(tools, { tool_choice: "any" })

Parameters

NameTypeDescription
tool_choicestringTool-choice policy passed to the model binding; the documented JavaScript example uses "any" to force a tool call.

Returns

A model response produced after applying the selected tool-choice policy; with "any", the invocation requires a tool call.

Key points

  • Tool choice is model-dependent: only models that expose this capability can honor a requested selection policy.
  • The JavaScript example uses the any value to require that the model call a tool.
  • A workflow can place mandatory tool operations in separate nodes instead of relying on one general-purpose agent step.
  • Dedicated tool-call nodes also allow prompts to be tailored to the exact operation being performed.

Common mistakes

  • The documented setting forces the model to make a tool call rather than allowing a direct text response.

Example: Require a tool call

const llmWithTools = model.bindTools([getSchemaTool], {
  tool_choice: "any",
});
const response = await llmWithTools.invoke(state.messages);

Binds a model to a tool and requires a tool call when invoking it.

When to use it

Force schema inspection

A workflow stage must retrieve database schema before generating a query.

Constrain workflow stages

A multi-stage agent needs mandatory tool operations at selected points.

Customize per-step prompts

Different steps require different instructions while using tools.

Interview questions

QWhat does tool_choice: "any" do?

tool_choice controls whether and how a model selects among tools bound to it. In the JavaScript example, "any" requires a tool call for that invocation.

Follow-up: How can a workflow guarantee a particular operation? Use a dedicated node with only the required tool bound, then invoke the model with an appropriate forced tool-choice setting.

QHow is tool choice used in the JavaScript workflow?

The model is first bound to the relevant tool with bindTools, and the resulting model is then invoked with the current message state. This keeps tool selection inside the workflow node.

Follow-up: Why use a dedicated node? It lets the workflow force tool calls at specific stages and customize the prompt for each stage.

QWhy place forced tool calls in dedicated nodes?

Dedicated nodes can force tool calls when needed and customize prompts associated with each step. The search result documents this pattern for listing tables, retrieving schema, generating a query, and checking it.

Follow-up: What is the broader design benefit? Explicit stages provide finer control than leaving the entire sequence to one unconstrained agent loop.

  • bindTools
  • ToolNode
  • tool calling
  • dedicated nodes

Source: Build a custom SQL agent. Checked 2026-10-15.