Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(agent): Fix resumption from mid-cycle state in CLI mode (#7224)

Reinier van der Leer02dc198a9f48
diff --git a/autogpt/autogpt/app/main.py b/autogpt/autogpt/app/main.py
index 1b413a2c58..bd3ab70e5d 100644
--- a/autogpt/autogpt/app/main.py
+++ b/autogpt/autogpt/app/main.py
@@ -510,22 +510,25 @@ async def run_interaction_loop(
########
handle_stop_signal()
# Have the agent determine the next action to take.
- with spinner:
- try:
- action_proposal = await agent.propose_action()
- except InvalidAgentResponseError as e:
- logger.warning(f"The agent's thoughts could not be parsed: {e}")
- consecutive_failures += 1
- if consecutive_failures >= 3:
- logger.error(
- "The agent failed to output valid thoughts"
- f" {consecutive_failures} times in a row. Terminating..."
- )
- raise AgentTerminated(
- "The agent failed to output valid thoughts"
- f" {consecutive_failures} times in a row."
- )
- continue
+ if not (_ep := agent.event_history.current_episode) or _ep.result:
+ with spinner:
+ try:
+ action_proposal = await agent.propose_action()
+ except InvalidAgentResponseError as e:
+ logger.warning(f"The agent's thoughts could not be parsed: {e}")
+ consecutive_failures += 1
+ if consecutive_failures >= 3:
+ logger.error(
+ "The agent failed to output valid thoughts"
+ f" {consecutive_failures} times in a row. Terminating..."
+ )
+ raise AgentTerminated(
+ "The agent failed to output valid thoughts"
+ f" {consecutive_failures} times in a row."
+ )
+ continue
+ else:
+ action_proposal = _ep.action
consecutive_failures = 0