-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathlesson-08-plan-and-execute-agents.py
41 lines (34 loc) · 1.12 KB
/
lesson-08-plan-and-execute-agents.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Plan and Execute Agents
import os
os.environ["OPENAI_API_KEY"] = "..."
from langchain.llms import OpenAI
from langchain.chat_models import ChatOpenAI
from langchain_experimental.plan_and_execute import (
PlanAndExecute,
load_agent_executor,
load_chat_planner,
)
from langchain import SerpAPIWrapper, LLMMathChain
from langchain.agents.tools import Tool
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(
"Where will the next summer olympics be hosted? What is the population of that country raised to the 0.43 power?"
)