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: Nonetype error from command_name.startswith() (#5079)

Lukead18f77e2542
diff --git a/autogpt/app/main.py b/autogpt/app/main.py
index f8ac3ca4b0..e7d51ce636 100644
--- a/autogpt/app/main.py
+++ b/autogpt/app/main.py
@@ -343,23 +343,25 @@ def update_user(
print_assistant_thoughts(ai_config.ai_name, assistant_reply_dict, config)
if command_name is not None:
- if config.speak_mode:
- say_text(f"I want to execute {command_name}", config)
+ if command_name.lower().startswith("error"):
+ logger.typewriter_log(
+ "ERROR: ",
+ Fore.RED,
+ f"The Agent failed to select an action. "
+ f"Error message: {command_name}",
+ )
+ else:
+ if config.speak_mode:
+ say_text(f"I want to execute {command_name}", config)
- # First log new-line so user can differentiate sections better in console
- logger.typewriter_log("\n")
- logger.typewriter_log(
- "NEXT ACTION: ",
- Fore.CYAN,
- f"COMMAND = {Fore.CYAN}{remove_ansi_escape(command_name)}{Style.RESET_ALL} "
- f"ARGUMENTS = {Fore.CYAN}{command_args}{Style.RESET_ALL}",
- )
- elif command_name.lower().startswith("error"):
- logger.typewriter_log(
- "ERROR: ",
- Fore.RED,
- f"The Agent failed to select an action. " f"Error message: {command_name}",
- )
+ # First log new-line so user can differentiate sections better in console
+ logger.typewriter_log("\n")
+ logger.typewriter_log(
+ "NEXT ACTION: ",
+ Fore.CYAN,
+ f"COMMAND = {Fore.CYAN}{remove_ansi_escape(command_name)}{Style.RESET_ALL} "
+ f"ARGUMENTS = {Fore.CYAN}{command_args}{Style.RESET_ALL}",
+ )
else:
logger.typewriter_log(
"NO ACTION SELECTED: ",
diff --git a/tests/integration/test_update_user.py b/tests/integration/test_update_user.py
new file mode 100644
index 0000000000..bc92063175
--- /dev/null
+++ b/tests/integration/test_update_user.py
@@ -0,0 +1,33 @@
+from unittest.mock import MagicMock, patch
+
+from colorama import Fore
+
+from autogpt.app.main import update_user
+
+
+def test_update_user_command_name_is_none() -> None:
+ # Mock necessary objects
+ config = MagicMock()
+ ai_config = MagicMock()
+ assistant_reply_dict = MagicMock()
+
+ # Mock print_assistant_thoughts and logger.typewriter_log
+ with patch(
+ "autogpt.app.main.print_assistant_thoughts"
+ ) as mock_print_assistant_thoughts, patch(
+ "autogpt.app.main.logger.typewriter_log"
+ ) as mock_logger_typewriter_log:
+ # Test the update_user function with None command_name
+ update_user(config, ai_config, None, None, assistant_reply_dict)
+
+ # Check that print_assistant_thoughts was called once
+ mock_print_assistant_thoughts.assert_called_once_with(
+ ai_config.ai_name, assistant_reply_dict, config
+ )
+
+ # Check that logger.typewriter_log was called once with expected arguments
+ mock_logger_typewriter_log.assert_called_once_with(
+ "NO ACTION SELECTED: ",
+ Fore.RED,
+ f"The Agent failed to select an action.",
+ )