langchain · difficulty ◆◆
Parallel Tool Calls in bind_tools
One round-trip, several tool calls.
Your agent used to wait in line. Now it fires in parallel.
$ model.bind_tools(tools, parallel_tool_calls=True)What it does
The langchain-openrouter==0.2.4 update surfaces parallel_tool_calls=True on bind_tools. This tells the underlying LLM it may invoke multiple tool calls in a single response. Models like Claude 3.5, GPT-4o, and Gemini 1.5 support parallel function calling, and the output type switches from a single AIMessage tool call to a list of ToolCall objects inside one AIMessage.
Why it matters
A customer-service agent often needs account balance, recent transactions, and policy details at once. Without parallel tool calls you need sequential chat turns, which are slow, expensive, and error-prone. With the flag, the model fires all three in a single turn, slashing latency and token usage.
Example
$ model = ChatOpenRouter(model="anthropic/claude-3-5-sonnet", openrouter_api_key="your-api-key")
bound = model.bind_tools([WeatherTool, DateTool], parallel_tool_calls=True, strict=True)
resp = bound.invoke([HumanMessage(content="Weather in Tokyo and today's date?")])
print(f"Tool calls: {len(resp.tool_calls)}")
for tc in resp.tool_calls:
print(f" Tool: {tc['name']} | Args: {tc['args']}")Number of tool calls: 2
Tool: WeatherTool | Args: {'city': 'Tokyo'}
Tool: DateTool | Args: {'format': '%Y-%m-%d'}Exact tool names and args depend on the model’s interpretation of your prompt.
Common flags
- bind_tools
- Binds a Pydantic tool schema to a chat model
- strict=True
- Enforces tool call format validation
- parallel_tool_calls
- Allows multiple tool calls in one response
History
From sequential to parallel
Parallel function calling existed in frontier models, but LangChain’s OpenRouter integration did not expose it. PR #38214 added the knob, and a related fix in langchain==1.3.11 stopped strict=True from being applied to all providers, which had broken non-OpenAI models.
Fun facts
Pros & cons
pros
- + Dramatically lower latency
- + Fewer round-trips and tokens
- + Clean batch of ToolCall objects
cons
- − Depends on underlying model support
- − Not all prompts trigger parallelism
Takeaways
- 1parallel_tool_calls=True is a one-line flag on bind_tools.
- 2The output becomes a list of ToolCall objects.
- 3Pair with strict=True only where the provider supports it.