I’m working with LangGraph, and I want to prevent a specific tool from being executed in parallel
Hi! Can you:
- Confirm if the model provider you’re using supports this?
- Tell me a little more about your use case?
Based on your answers, I can give you more guidance.
Hi Rahul! Thanks for getting back.
I’m currently using GPT-4o mini for my project. My use case is building a natural language to SQL chatbot. I have two tools integrated:
-
Retriever tool → fetches the table schema related to the user’s question.
-
SQL checker → validates the SQL query generated by the LLM and retrieves the data from the database.
The issue I’m facing is that both tools are sometimes being invoked in parallel unnecessarily. In particular, the retriever tool is being triggered multiple times in parallel for the same query, returning duplicate content and increasing token usage.
On the other hand, parallel invocation of the SQL checker can be valid in some cases (for example, when the query requires multiple SQL statements to generate the final result).
What I need is a way to stop the retriever tool from being called in parallel, while still allowing the SQL checker to work as needed.
Unfortunately, with a single model invocation, your only option is to turn off parallel tool calling altogether. However, if you find it useful to call your second tool in parallel, you can separate your code into different model calls, one that has parallel tool calls off followed by one that has them on. If you put these in different LangGraph nodes, the framework can orchestrate going back and forth between them if you anticipate this is going to be an iterative process involving both steps.