π·Workers
Last updated
# import the required packages
from openagi.actions.files import WriteFileAction
from openagi.actions.tools.ddg_search import DuckDuckGoNewsSearch
from openagi.actions.tools.webloader import WebBaseContextTool
from openagi.agent import Admin
from openagi.llms.azure import AzureChatOpenAIModel
from openagi.memory import Memory
from openagi.planner.task_decomposer import TaskPlanner
from openagi.worker import Worker
# configure the LLM
config = AzureChatOpenAIModel.load_from_env_config()
llm = AzureChatOpenAIModel(config=config)
# Declare the Worker objects
# Initialize the researcher who uses DuckDuckGo to search a topic and extract information from the web pages.
researcher = Worker(
role="Researcher",
instructions="sample instruction.",
actions=[
DuckDuckGoNewsSearch,
WebBaseContextTool,
],
)
# initialize the writer who writes the content of the topic using the tools provided
writer = Worker(
role="Writer",
instructions="sample instruction.",
actions=[
DuckDuckGoNewsSearch,
WebBaseContextTool,
],
)
# initialize the reviewer who reviews the content written by the writer and saves the content into a file using the write file action tool.
reviewer = Worker(
role="Reviewer",
instructions="sample instruction.",
actions=[
DuckDuckGoNewsSearch,
WebBaseContextTool,
WriteFileAction,
],
)
# declare the Admin object with Task Planner, Memory, and LLM
admin = Admin(
planner=TaskPlanner(human_intervene=False),
memory=Memory(),
llm=llm,
)
# Assign sub-tasks to workers
admin.assign_workers([researcher, writer, reviewer])
# run the admin object
res = admin.run(
query="Write a blog post.",
description="sample description.",
)