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)
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)
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.
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)