0

Is there a way to force a LangChain agent to always use a tool?

(my specific use case: I need the agent to look for information in my database as opposed to generally accessible information and my tool searches through my database)

gosia
  • 29
  • 3

2 Answers2

1

When running an agent query, you can explicitly mention about the custom tool.

agent(
         "Using Custom Tool please calculate result of 5"
     )

Also, in your _run() function, you add custom log for tracking when custom tool is been called.

ZKS
  • 817
  • 3
  • 16
  • 31
-1

You can do this by setting the allowed_tools property of the agent to a list that only contains the name of the tool that you want the agent to use.

from langchain import Agent

agent = Agent()
agent.allowed_tools = ["Your Tool"]

or

from langchain.agents import load_tools, initialize_agent, AgentType

# load your tool and initilize an agent with the tool list
tools = load_tools(["Your Tool"], llm=llm)
agent = initialize_agent(tools, 
                         llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, 
                         verbose=True)
Codemaker2015
  • 12,190
  • 6
  • 97
  • 81
  • The answer is generated by Google Bard. I got very similar answer when copy the question inside the Google Bart. It also failed by bot test https://www.zerogpt.com/ and https://gptzero.me/ – Hongbo Miao Sep 02 '23 at 22:58