Can we use hardcoded messages in agent tools in langchain?

44 views Asked by At

I am experimenting with langchain agents and I want to make a separate tool for simple greetings. To achieve this, I've developed a Python function with hard-coded messages. It looks something like this:

def Greetings(user_question):
 Generic_statements=[<greetings>]
 Farewell=[<farewells>]
 if any(re.search(fr'\b{response}\b', user_question, re.IGNORECASE) for response in Generic_statements):
    response= "We are here to help! Let me know if I can help you with anything else."
 
 elif any(re.search(fr'\b{response}\b', user_question, re.IGNORECASE) for response in Farewell):
    response="I'm here whenever you need anything. I'll be looking forward to our next conversation. Take care. Goodbye!"
 return response 

And this is how I am making the tool

tools = [
Tool(
    name="Greetings",
    func = lambda string: Greetings(string),
    description="use for general greetings",
   
)
]

This is the result I get enter image description here

I am curious if there is any way that the final answer be the one that I have hardcoded and not the one that the agent think of.

I have tried this in the prompt:

Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action
Observation: the result of the action
Final Answer:the result of the action

and it works fine. But this is part of a general prompt, I do not want this for every tool.

0

There are 0 answers