Human as a tool#

Human are AGI so they can certainly be used as a tool to help out AI agent when it is confused.

import sys
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,
)

In the above code you can see the tool takes input directly from command line. You can customize prompt_func and input_func according to your need.

agent_chain.run("What is Eric Zhu's birthday?")
# Answer with "last week"
> Entering new AgentExecutor chain...
I don't know Eric Zhu, so I should ask a human for guidance.
Action: Human
Action Input: "Do you know when Eric Zhu's birthday is?"

Do you know when Eric Zhu's birthday is?
last week

Observation: last week
Thought:That's not very helpful. I should ask for more information.
Action: Human
Action Input: "Do you know the specific date of Eric Zhu's birthday?"

Do you know the specific date of Eric Zhu's birthday?
august 1st

Observation: august 1st
Thought:Now that I have the date, I can check if it's a leap year or not.
Action: Calculator
Action Input: "Is 2021 a leap year?"
Observation: Answer: False

Thought:I have all the information I need to answer the original question.
Final Answer: Eric Zhu's birthday is on August 1st and it is not a leap year in 2021.

> Finished chain.
"Eric Zhu's birthday is on August 1st and it is not a leap year in 2021."