Find answers from the community

Updated 2 months ago

Langchain

How to force my agent to use a certain tool?

I have a web searcher tool:

Plain Text
        tools.append(Tool(
            name="Search",
            func=search.run,
            description="Always use this tool first!",
            return_direct=True
        ))

        agent_chain = initialize_agent(tools, llm, agent="conversational-react-description", memory=memory,
                                       verbose=True, return_intermediate_steps=True)


But when I ask: "When was gpt-4 released?"

I see in logs that the agent is not using the tool:

Plain Text
Thought: Do I need to use a tool? No
AI: As of now, there is no official release date for GPT-4. OpenAI has not announced any plans to release it yet. However, they have been working on improving GPT-3 and releasing new versions of it.
L
p
3 comments
I don't think there's a way to force the tool, other than writing a better description lol

"Always use this tool first. If you are asking yourself to use a tool, use this one"

But even then, that might be flakey.

Maybe you should run the tool yourself, and then use that as input to the agent?
Hi @Logan M . Actually, I will not Always run this tool lol. The original description was something like: Use this tool when you are unsure of the answer or want to perform web-search. But with that description it did not use it, so I substituted it with Always use this tool first!, which did not help as well.

I switched it to Assistant needs to use this tool when he is not sure about the answer. This tool performs Web-search and it works now!

I've noticed that when I use the word Assistant ,it somehow follows the instructions (I used the same word on other tools too πŸ™‚
Ooooo good to know! πŸ’ͺ
Add a reply
Sign up and join the conversation on Discord