How to force llm model(gemini-2.5-flash) to use tool

I am trying to build a coding agent using langgraph. I am currently developing a graph that try to understand the user query and gather the requirement by asking question to user. Currently sometime the llm uses my ‘askUserTool‘ but many times it does not uses the tool and simply frame the question in the response.

My Code is on this github repo: GitHub - ashishkujoy/ai-coding-agent

graph code: ai-coding-agent/src/nodes/requirementGatherer.ts at main · ashishkujoy/ai-coding-agent · GitHub

And the system prompt i am using is here.: ai-coding-agent/src/prompts/requirement-gathering.ts at main · ashishkujoy/ai-coding-agent · GitHub

Output gist: AI coding agent output · GitHub

Kindly someone please help me understand the issue with the prompt or how i am creating graph.

1 Like

Hi,

The bindTools method takes a optional second argument where you can pass a tool_choice stating the name of the tool you want to force the llm to call .

If you want to to always call a tool but don’t want to choose a specific tool to always run you can pass any to this tool_choice and the llm will pick the most appropriate tool depending on the query.

Hope this helps!