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.

Filtering out ANSI escape codes in printed assistant thoughts (#4810)

lukas-eubafcdcea7c89
diff --git a/autogpt/agent/agent.py b/autogpt/agent/agent.py
index fca03a5fb3..c578152a16 100644
--- a/autogpt/agent/agent.py
+++ b/autogpt/agent/agent.py
@@ -17,7 +17,7 @@ from autogpt.log_cycle.log_cycle import (
USER_INPUT_FILE_NAME,
LogCycleHandler,
)
-from autogpt.logs import logger, print_assistant_thoughts
+from autogpt.logs import logger, print_assistant_thoughts, remove_ansi_escape
from autogpt.memory.message_history import MessageHistory
from autogpt.memory.vector import VectorMemory
from autogpt.models.command_registry import CommandRegistry
@@ -185,7 +185,7 @@ class Agent:
logger.typewriter_log(
"NEXT ACTION: ",
Fore.CYAN,
- f"COMMAND = {Fore.CYAN}{command_name}{Style.RESET_ALL} "
+ f"COMMAND = {Fore.CYAN}{remove_ansi_escape(command_name)}{Style.RESET_ALL} "
f"ARGUMENTS = {Fore.CYAN}{arguments}{Style.RESET_ALL}",
)
diff --git a/autogpt/logs.py b/autogpt/logs.py
index 90d006bc8c..8eb4c94a68 100644
--- a/autogpt/logs.py
+++ b/autogpt/logs.py
@@ -249,6 +249,10 @@ def remove_color_codes(s: str) -> str:
return ansi_escape.sub("", s)
+def remove_ansi_escape(s: str) -> str:
+ return s.replace("\x1B", "")
+
+
logger = Logger()
@@ -263,12 +267,16 @@ def print_assistant_thoughts(
assistant_thoughts_criticism = None
assistant_thoughts = assistant_reply_json_valid.get("thoughts", {})
- assistant_thoughts_text = assistant_thoughts.get("text")
+ assistant_thoughts_text = remove_ansi_escape(assistant_thoughts.get("text"))
if assistant_thoughts:
- assistant_thoughts_reasoning = assistant_thoughts.get("reasoning")
- assistant_thoughts_plan = assistant_thoughts.get("plan")
- assistant_thoughts_criticism = assistant_thoughts.get("criticism")
- assistant_thoughts_speak = assistant_thoughts.get("speak")
+ assistant_thoughts_reasoning = remove_ansi_escape(
+ assistant_thoughts.get("reasoning")
+ )
+ assistant_thoughts_plan = remove_ansi_escape(assistant_thoughts.get("plan"))
+ assistant_thoughts_criticism = remove_ansi_escape(
+ assistant_thoughts.get("criticism")
+ )
+ assistant_thoughts_speak = remove_ansi_escape(assistant_thoughts.get("speak"))
logger.typewriter_log(
f"{ai_name.upper()} THOUGHTS:", Fore.YELLOW, f"{assistant_thoughts_text}"
)