yoheinakajima / babyagi

https://babyagi.org/
20.4k stars 2.68k forks source link

Ability for the agents to stop the loop and return #131

Closed rohanikshvaku closed 1 month ago

rohanikshvaku commented 1 year ago

Added the ability for the agent to stop the loop and return the completed tasks if they think all the tasks have been completed.

Here's how I implemented it:

  1. Added STOP_KEYWORD constant: Defined a constant STOP_KEYWORD that holds the keyword which, when encountered as a task, will stop the main loop of the program.
  2. Introduced completed_tasks dictionary: Initialized an empty dictionary called completed_tasks to store completed tasks during the main loop.
  3. Updated the main loop with STOP_KEYWORD check: Modified the main loop to check for the presence of STOP_KEYWORD in the current task's name, and break the loop if the keyword is encountered.
  4. Stored completed tasks in completed_tasks dictionary: After each successful execution of a task, updated the completed_tasks dictionary with the task ID, task name, and result.
  5. Added return_results parameter: Introduced a new parameter, return_results, to the run_program() function, allowing the user to control whether or not the function should return the completed tasks as a dictionary when the program stops.
  6. Returned completed_tasks if return_results is True: Modified the run_program() function to return the completed_tasks dictionary if the return_results parameter is set to True.
davidbyttow commented 1 year ago

Nice, in your experimentation, how often did this happen? How long did it take? Would be good to understand how this changes behavior @rohanikshvaku

rohanikshvaku commented 1 year ago

@davidbyttow there's a better way to do this that's inbuilt into the agents by langchain. Please wait, I'm looking into it and will try to add the functionality and initiate a new pull request.