Files
langchain/docs/examples/agents/react.ipynb
2022-11-22 18:02:20 -08:00

2.1 KiB

ReAct

This notebook showcases using an agent to implement the ReAct logic.

In [1]:
from langchain import OpenAI, Wikipedia
from langchain.agents import initialize_agent, Tool
from langchain.agents.react.base import DocstoreExplorer
docstore=DocstoreExplorer(Wikipedia())
tools = [
    Tool(
        name="Search",
        func=docstore.search
    ),
    Tool(
        name="Lookup",
        func=docstore.lookup
    )
]

llm = OpenAI(temperature=0)
react = initialize_agent(tools, llm, agent="react-docstore", verbose=True)
In [ ]:
question = "Author David Chanoff has collaborated with a U.S. Navy admiral who served as the ambassador to the United Kingdom under which President?"
react.run(question)
Author David Chanoff has collaborated with a U.S. Navy admiral who served as the ambassador to the United Kingdom under which President?
Thought 1:
In [ ]: