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 check when loading an existing agent (#7026)

Krzysztof Czerwinski262771a69c78
diff --git a/autogpts/autogpt/autogpt/app/main.py b/autogpts/autogpt/autogpt/app/main.py
index 30ab1120f9..04df5e1a6a 100644
--- a/autogpts/autogpt/autogpt/app/main.py
+++ b/autogpts/autogpt/autogpt/app/main.py
@@ -185,9 +185,12 @@ async def run_auto_gpt(
"Enter the number or name of the agent to run,"
" or hit enter to create a new one:",
)
- if re.match(r"^\d+$", load_existing_agent):
+ if re.match(r"^\d+$", load_existing_agent.strip()) and 0 < int(
+ load_existing_agent
+ ) <= len(existing_agents):
load_existing_agent = existing_agents[int(load_existing_agent) - 1]
- elif load_existing_agent and load_existing_agent not in existing_agents:
+
+ if load_existing_agent not in existing_agents:
logger.info(
f"Unknown agent '{load_existing_agent}', "
f"creating a new one instead.",