Skip to content

Commit

Permalink
fix: change on how to invoke multiple commands
Browse files Browse the repository at this point in the history
  • Loading branch information
yangkyeongmo committed May 14, 2023
1 parent 02383f7 commit d1fc167
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions autogpt/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
from autogpt.workspace import Workspace


class EndOfConversation(Exception):
"""Exception raised when the conversation ends"""
...


class Agent:
"""Agent class for interacting with Auto-GPT.
Expand Down Expand Up @@ -85,9 +90,6 @@ def start_interaction_loop(self):
# Interaction Loop
cfg = Config()
self.cycle_count = 0
command_name = None
arguments = None
user_input = ""

while True:
# Discontinue if continuous limit is reached
Expand Down Expand Up @@ -146,11 +148,28 @@ def start_interaction_loop(self):
NEXT_ACTION_FILE_NAME,
)

loop = asyncio.get_running_loop()
for command_name, arguments in commands:
loop.run_in_executor(None, self.run_command, cfg, assistant_reply_json, command_name, arguments)
async def run_commands(_commands):
loop = asyncio.get_event_loop()
await asyncio.gather(
*[
loop.run_in_executor(
None,
self.run_command,
cfg,
assistant_reply_json,
command_name,
arguments,
)
for command_name, arguments in _commands
]
)
try:
asyncio.run(run_commands(commands))
except EndOfConversation:
break

def run_command(self, cfg, assistant_reply_json, command_name, arguments):
user_input = ""
if not cfg.continuous_mode and self.next_action_count == 0:
# ### GET USER AUTHORIZATION TO EXECUTE COMMAND ###
# Get key press: Prompt the user to press enter to continue or escape
Expand Down Expand Up @@ -235,7 +254,7 @@ def run_command(self, cfg, assistant_reply_json, command_name, arguments):
)
elif user_input == "EXIT":
logger.info("Exiting...")
break
raise EndOfConversation
else:
# Print command
logger.typewriter_log(
Expand Down

0 comments on commit d1fc167

Please sign in to comment.