langchain · difficulty ◆◆
Parallel Tool Calls on OpenRouter
Set it on the model, not just the binding.
You can set parallelism at the model level, not just per binding.
$ ChatOpenRouter(..., parallel_tool_calls=True)What it does
bind_tools on the OpenRouter integration exposes parallel_tool_calls=True as a native option. When enabled, the model can fire multiple tool calls in a single response turn instead of a back-and-forth loop. LangChain handles the streaming chunks internally and merges them into complete tool call sequences.
Why it matters
A research agent that fetches a weather API and a news feed at the same time would otherwise serialize those calls, doubling latency. parallel_tool_calls=True lets the model decide when to act in parallel, and LangChain reassembles the chunks automatically.
Example
$ llm = ChatOpenRouter(model="anthropic/claude-3.5-sonnet", openrouter_api_key="<your-key>", parallel_tool_calls=True)
bound = llm.bind_tools([get_weather, get_news])
resp = bound.invoke("Weather in Vienna and top news in AI?")
for call in resp.tool_calls:
print(f" -> {call['name']}({call['args']})")Tool calls made:
-> get_weather({'city': 'Vienna'})
-> get_news({'topic': 'AI'})Both tools are called in a single model round-trip.
Common flags
- ChatOpenRouter.bind_tools
- Bind tools with optional parallel_tool_calls kwarg
- create_openai_functions_chain
- Converts tool definitions into an OpenAI-format function-calling chain
- create_taggingChain
- Structured output via Pydantic schema, an alternative to tool calling
History
A knob finally surfaced
Many OpenRouter models supported parallel tool execution, but LangChain had not exposed the switch for them. This release surfaced it on the constructor and bind_tools, with chunk reassembly handled automatically.
Fun facts
Pros & cons
pros
- + Model-level toggle
- + Automatic chunk reassembly
- + Transparent over streaming
cons
- − Behavior varies by model
- − Requires langchain-openrouter 0.2.4+
Takeaways
- 1parallel_tool_calls=True is also settable on the ChatOpenRouter constructor.
- 2Chunk reassembly is automatic.
- 3Different models decide differently whether to parallelize.