raiseValueError("API key must be provided either as argument or as an environment variable named 'API_KEY'.")
#the bossNode is responsible for creating and executing tasks using the BABYAGI model
#it takes a lm a vectorstore for memory and agent_executor for task exeuction, and a maximum number of iterations, for the babyagi model
def__init__(self,
objective,
vectorstore,
boss_system_prompt:Optional[str]="You are a boss planer in a swarm who is an expert at coming up with a todo list for a given objective and then creating a worker to help you accomplish your task. Rate every task on the importance of it's probability to complete the main objective on a scale from 0 to 1, an integer. Come up with a todo list for this objective: {objective} and then spawn a worker agent to complete the task for you. Always spawn a worker agent after creating a plan and pass the objective and plan to the worker agent.",
api_key=None,
worker_node=None,
llm_class=OpenAI,
max_iterations=5,
verbose=False
):
self.api_key=api_keyoros.getenv("OPENAI_API_KEY")
self.vectorstore=vectorstore
self.worker_node=worker_node
self.boss_system_prompt=boss_system_prompt
self.llm_class=llm_class
self.max_iterations=max_iterations
self.verbose=verbose
ifnotself.api_key:
raiseValueError("[BossNode][ValueError][API KEY must be provided either as an argument or as an environment variable API_KEY]")
self.llm=self.initialize_llm(self.llm_class)
llm=BossNode.initialize_llm(llm_class)# This function should be defined elsewhere
todo_prompt=PromptTemplate.from_template("You are a boss planer in a swarm who is an expert at coming up with a todo list for a given objective and then creating a worker to help you accomplish your task. Rate every task on the importance of it's probability to complete the main objective on a scale from 0 to 1, an integer. Come up with a todo list for this objective: {objective} and then spawn a worker agent to complete the task for you. Always spawn a worker agent after creating a plan and pass the objective and plan to the worker agent.")
tools=[
todo_chain=LLMChain(llm=llm,prompt=todo_prompt)
Tool(name="TODO",func=todo_chain.run,description="useful for when you need to come up with todo lists. Input: an objective to create a todo list for your objective. Note create a todo list then assign a ranking from 0.0 to 1.0 to each task, then sort the tasks based on the tasks most likely to achieve the objective. The Output: a todo list for that objective with rankings for each step from 0.1 Please be very clear what the objective is!"),
self.worker_node
]
suffix="""Question: {task}\n{agent_scratchpad}"""
prefix="""You are an Boss in a swarm who performs one task based on the following objective: {objective}. Take into account these previously completed tasks: {context}.\n"""
Tool(name="TODO",func=todo_chain.run,description="useful for when you need to come up with todo lists. Input: an objective to create a todo list for your objective. Note create a todo list then assign a ranking from 0.0 to 1.0 to each task, then sort the tasks based on the tasks most likely to achieve the objective. The Output: a todo list for that objective with rankings for each step from 0.1 Please be very clear what the objective is!"),
prefix="""You are an Boss in a swarm who performs one task based on the following objective: {objective}. Take into account these previously completed tasks: {context}.\n"""