Controller model for the BabyAGI agent.
| 140 | return execution_chain.run(objective=objective, context=context, task=task) |
| 141 | |
| 142 | class BabyAGI(Chain, BaseModel): |
| 143 | """Controller model for the BabyAGI agent.""" |
| 144 | |
| 145 | task_list: deque = Field(default_factory=deque) |
| 146 | task_creation_chain: TaskCreationChain = Field(...) |
| 147 | task_prioritization_chain: TaskPrioritizationChain = Field(...) |
| 148 | initial_task_creation_chain: InitialTaskCreationChain = Field(...) |
| 149 | execution_chain: AgentExecutor = Field(...) |
| 150 | task_id_counter: int = Field(1) |
| 151 | vectorstore: VectorStore = Field(init=False) |
| 152 | max_iterations: Optional[int] = None |
| 153 | |
| 154 | class Config: |
| 155 | """Configuration for this pydantic object.""" |
| 156 | arbitrary_types_allowed = True |
| 157 | |
| 158 | def add_task(self, task: Dict): |
| 159 | self.task_list.append(task) |
| 160 | |
| 161 | def print_task_list(self): |
| 162 | print("\033[95m\033[1m" + "\n*****TASK LIST*****\n" + "\033[0m\033[0m") |
| 163 | for t in self.task_list: |
| 164 | print(str(t["task_id"]) + ": " + t["task_name"]) |
| 165 | |
| 166 | def print_next_task(self, task: Dict): |
| 167 | print("\033[92m\033[1m" + "\n*****NEXT TASK*****\n" + "\033[0m\033[0m") |
| 168 | print(str(task["task_id"]) + ": " + task["task_name"]) |
| 169 | |
| 170 | def print_task_result(self, result: str): |
| 171 | print("\033[93m\033[1m" + "\n*****TASK RESULT*****\n" + "\033[0m\033[0m") |
| 172 | print(result) |
| 173 | |
| 174 | @property |
| 175 | def input_keys(self) -> List[str]: |
| 176 | return ["objective"] |
| 177 | |
| 178 | @property |
| 179 | def output_keys(self) -> List[str]: |
| 180 | return [] |
| 181 | |
| 182 | def _call(self, inputs: Dict[str, Any]) -> Dict[str, Any]: |
| 183 | """Run the agent.""" |
| 184 | # not an elegant implementation, but it works for the first task |
| 185 | objective = inputs['objective'] |
| 186 | first_task = inputs.get("first_task", self.initial_task_creation_chain.run(objective=objective))# self.task_creation_chain.llm(initial_task_prompt)) |
| 187 | |
| 188 | self.add_task({"task_id": 1, "task_name": first_task}) |
| 189 | num_iters = 0 |
| 190 | while True: |
| 191 | if self.task_list: |
| 192 | self.print_task_list() |
| 193 | |
| 194 | # Step 1: Pull the first task |
| 195 | task = self.task_list.popleft() |
| 196 | self.print_next_task(task) |
| 197 | |
| 198 | # Step 2: Execute the task |
| 199 | result = execute_task( |
nothing calls this directly
no outgoing calls
no test coverage detected