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

llm = OpenAI(temperature=0)
llm_math_chain = LLMMathChain.from_llm(llm=llm, verbose=True)
tools = [
    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)


if __name__ == "__main__":
    agent.run(
        "Who is Leo DiCaprio's girlfriend? What is her current age raised to the 0.43 power?"
    )

langchain.chains.LLMMathChain.from_llm langchain.llms.OpenAI langchain.chat_models.ChatOpenAI 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
[((292, 313), 'langchain.llms.OpenAI', 'OpenAI', ([], {'temperature': '(0)'}), '(temperature=0)\n', (298, 313), False, 'from langchain.llms import OpenAI\n'), ((331, 375), 'langchain.chains.LLMMathChain.from_llm', 'LLMMathChain.from_llm', ([], {'llm': 'llm', 'verbose': '(True)'}), '(llm=llm, verbose=True)\n', (352, 375), False, 'from langchain.chains import LLMMathChain\n'), ((553, 578), 'langchain.chat_models.ChatOpenAI', 'ChatOpenAI', ([], {'temperature': '(0)'}), '(temperature=0)\n', (563, 578), False, 'from langchain.chat_models import ChatOpenAI\n'), ((590, 614), 'langchain_experimental.plan_and_execute.load_chat_planner', 'load_chat_planner', (['model'], {}), '(model)\n', (607, 614), False, 'from langchain_experimental.plan_and_execute import PlanAndExecute, load_agent_executor, load_chat_planner\n'), ((626, 673), 'langchain_experimental.plan_and_execute.load_agent_executor', 'load_agent_executor', (['model', 'tools'], {'verbose': '(True)'}), '(model, tools, verbose=True)\n', (645, 673), False, 'from langchain_experimental.plan_and_execute import PlanAndExecute, load_agent_executor, load_chat_planner\n'), ((682, 746), 'langchain_experimental.plan_and_execute.PlanAndExecute', 'PlanAndExecute', ([], {'planner': 'planner', 'executor': 'executor', 'verbose': '(True)'}), '(planner=planner, executor=executor, verbose=True)\n', (696, 746), False, 'from langchain_experimental.plan_and_execute import PlanAndExecute, load_agent_executor, load_chat_planner\n'), ((390, 514), '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", (394, 514), False, 'from langchain.agents.tools import Tool\n')]