Make LangChain agent ask clarifying question
Asked Answered
S

1

5

I'm trying to implement a langchain agent that is able to ask clarifying questions in case some information is missing. Is this at all possible? A simple example would be

Input: "Please give me a recipe for a cake"
Agent: "Certainly. What kind of cake do you have in mind?"
Input: "A chocolate cake"
Agent: "Certainly, here is a recipe for a chocolate cake..."
Shaylynn answered 4/5, 2023 at 7:4 Comment(0)
S
10

Found it in the docs

from langchain.chat_models import ChatOpenAI
from langchain.llms import OpenAI
from langchain.agents import load_tools, initialize_agent
from langchain.agents import AgentType

llm = ChatOpenAI(temperature=0.0)
math_llm = OpenAI(temperature=0.0)
tools = load_tools(
    ["human", "llm-math"], 
    llm=math_llm,
)

agent_chain = initialize_agent(
    tools,
    llm,
    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
    verbose=True,
)

agent_chain.run("When's my friend Eric's surname?")

which yields

> Entering new AgentExecutor chain...
I don't know Eric's surname, so I should ask a human for guidance.
Action: Human
Action Input: "What is Eric's surname?"

What is Eric's surname?
Shaylynn answered 5/5, 2023 at 19:28 Comment(1)
Updated link: python.langchain.com/docs/integrations/tools/human_toolsRecover

© 2022 - 2024 — McMap. All rights reserved.