LLM bind_tools force no response #30015
Replies: 1 comment 2 replies
-
Hey @blafab-hg! I'm here to help you with any bugs, questions, or contributions. Let's tackle this issue together. Currently, there isn't a built-in way in LangChain to configure the LLM to suppress responses when no tool calls are made. The def agent_tool_node(state):
question = state["question"]
llm = get_llm()
model_with_tools = llm.bind_tools(self.get_tools())
messages = [("user", question)]
response = model_with_tools.invoke(messages)
# Check if any tool calls are suggested
if response.tool_calls:
return {"messages": [response]}
else:
# Return an empty response or handle it as needed
return {"messages": []} This way, you can ensure that the LLM only returns a response if a tool call is suggested, potentially reducing unnecessary costs. To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am using the following code inside of a langgraph node to decide if any tool calls are needed:
Later on in my graph I am performing a RAG search with documents that I retrieved from a vector store. The issue inside the
agent_tool_node
is that if the invocation ofmodel_with_tools
if the LLM thinks no tool is called, it tries to answer the users query.Can I somehow tell the LLM to either respond with a message with tool_calls or nothing at all? This would cut down on cost immensely.
Beta Was this translation helpful? Give feedback.
All reactions