from langchain.chat_models import ChatOpenAI
from langchain_experimental.plan_and_execute import PlanAndExecute, load_agent_executor, load_chat_planner
from langchain.llms import OpenAI
from langchain import SerpAPIWrapper
from langchain.agents.tools import Tool
from langchain import LLMMathChain

search = SerpAPIWrapper()
llm = OpenAI(temperature=0)
llm_math_chain = LLMMathChain.from_llm(llm=llm, verbose=True)
tools = [
    Tool(
        name = "Search",
        func=search.run,
        description="useful for when you need to answer questions about current events"
    ),
    Tool(
        name="Calculator",
        func=llm_math_chain.run,
        description="useful for when you need to answer questions about math"
    ),
]
model = ChatOpenAI(temperature=0)
planner = load_chat_planner(model)
executor = load_agent_executor(model, tools, verbose=True)
agent = PlanAndExecute(planner=planner, executor=executor, verbose=True)

agent.run("中国前2的特种磨具陶瓷企业，生产1000份磨具陶瓷需要多少钱?")
langchain.llms.OpenAI langchain.chat_models.ChatOpenAI langchain.LLMMathChain.from_llm langchain.SerpAPIWrapper langchain_experimental.plan_and_execute.load_chat_planner langchain_experimental.plan_and_execute.PlanAndExecute langchain.agents.tools.Tool langchain_experimental.plan_and_execute.load_agent_executor
[((308, 324), 'langchain.SerpAPIWrapper', 'SerpAPIWrapper', ([], {}), '()\n', (322, 324), False, 'from langchain import SerpAPIWrapper\n'), ((331, 352), 'langchain.llms.OpenAI', 'OpenAI', ([], {'temperature': '(0)'}), '(temperature=0)\n', (337, 352), False, 'from langchain.llms import OpenAI\n'), ((370, 414), 'langchain.LLMMathChain.from_llm', 'LLMMathChain.from_llm', ([], {'llm': 'llm', 'verbose': '(True)'}), '(llm=llm, verbose=True)\n', (391, 414), False, 'from langchain import LLMMathChain\n'), ((745, 770), 'langchain.chat_models.ChatOpenAI', 'ChatOpenAI', ([], {'temperature': '(0)'}), '(temperature=0)\n', (755, 770), False, 'from langchain.chat_models import ChatOpenAI\n'), ((781, 805), 'langchain_experimental.plan_and_execute.load_chat_planner', 'load_chat_planner', (['model'], {}), '(model)\n', (798, 805), False, 'from langchain_experimental.plan_and_execute import PlanAndExecute, load_agent_executor, load_chat_planner\n'), ((817, 864), 'langchain_experimental.plan_and_execute.load_agent_executor', 'load_agent_executor', (['model', 'tools'], {'verbose': '(True)'}), '(model, tools, verbose=True)\n', (836, 864), False, 'from langchain_experimental.plan_and_execute import PlanAndExecute, load_agent_executor, load_chat_planner\n'), ((873, 937), 'langchain_experimental.plan_and_execute.PlanAndExecute', 'PlanAndExecute', ([], {'planner': 'planner', 'executor': 'executor', 'verbose': '(True)'}), '(planner=planner, executor=executor, verbose=True)\n', (887, 937), False, 'from langchain_experimental.plan_and_execute import PlanAndExecute, load_agent_executor, load_chat_planner\n'), ((429, 551), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Search"""', 'func': 'search.run', 'description': '"""useful for when you need to answer questions about current events"""'}), "(name='Search', func=search.run, description=\n    'useful for when you need to answer questions about current events')\n", (433, 551), False, 'from langchain.agents.tools import Tool\n'), ((584, 708), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Calculator"""', 'func': 'llm_math_chain.run', 'description': '"""useful for when you need to answer questions about math"""'}), "(name='Calculator', func=llm_math_chain.run, description=\n    'useful for when you need to answer questions about math')\n", (588, 708), False, 'from langchain.agents.tools import Tool\n')]