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): Full fix for CLI breakage introduced in cf00c33

Reinier van der Leer898317c16c43
diff --git a/autogpts/autogpt/autogpt/app/main.py b/autogpts/autogpt/autogpt/app/main.py
index 8db146ec9a..9ff086369c 100644
--- a/autogpts/autogpt/autogpt/app/main.py
+++ b/autogpts/autogpt/autogpt/app/main.py
@@ -102,6 +102,7 @@ async def run_auto_gpt(
level=log_level,
log_format=log_format,
log_file_format=log_file_format,
+ config=config.logging,
tts_config=config.tts_config,
)
@@ -389,6 +390,7 @@ async def run_auto_gpt_server(
level=log_level,
log_format=log_format,
log_file_format=log_file_format,
+ config=config.logging,
tts_config=config.tts_config,
)
@@ -486,12 +488,13 @@ async def run_interaction_loop(
legacy_config = agent.legacy_config
ai_profile = agent.ai_profile
logger = logging.getLogger(__name__)
- config = LoggingConfig.from_env()
cycle_budget = cycles_remaining = _get_cycle_budget(
legacy_config.continuous_mode, legacy_config.continuous_limit
)
- spinner = Spinner("Thinking...", plain_output=config.plain_console_output)
+ spinner = Spinner(
+ "Thinking...", plain_output=legacy_config.logging.plain_console_output
+ )
stop_reason = None
def graceful_agent_interrupt(signum: int, frame: Optional[FrameType]) -> None:
diff --git a/autogpts/autogpt/autogpt/config/config.py b/autogpts/autogpt/autogpt/config/config.py
index 2ee39afc9b..4ea94fc77d 100644
--- a/autogpts/autogpt/autogpt/config/config.py
+++ b/autogpts/autogpt/autogpt/config/config.py
@@ -24,6 +24,7 @@ from autogpt.core.resource.model_providers.openai import (
OpenAIModelName,
)
from autogpt.file_storage import FileStorageBackendName
+from autogpt.logs.config import LoggingConfig
from autogpt.plugins.plugins_config import PluginsConfig
from autogpt.speech import TTSConfig
@@ -58,6 +59,7 @@ class Config(SystemSettings, arbitrary_types_allowed=True):
)
# TTS configuration
+ logging: LoggingConfig = LoggingConfig()
tts_config: TTSConfig = TTSConfig()
# File storage
diff --git a/autogpts/autogpt/autogpt/logs/config.py b/autogpts/autogpt/autogpt/logs/config.py
index 4a849736af..007aeb3f16 100644
--- a/autogpts/autogpt/autogpt/logs/config.py
+++ b/autogpts/autogpt/autogpt/logs/config.py
@@ -81,12 +81,14 @@ def configure_logging(
log_format: Optional[LogFormatName | str] = None,
log_file_format: Optional[LogFormatName | str] = None,
plain_console_output: Optional[bool] = None,
+ config: Optional[LoggingConfig] = None,
tts_config: Optional[TTSConfig] = None,
) -> None:
"""Configure the native logging module, based on the environment config and any
specified overrides.
Arguments override values specified in the environment.
+ Overrides are also applied to `config`, if passed.
Should be usable as `configure_logging(**config.logging.dict())`, where
`config.logging` is a `LoggingConfig` object.
@@ -111,14 +113,16 @@ def configure_logging(
elif not isinstance(log_file_format, LogFormatName):
raise ValueError(f"Unknown log format '{log_format}'")
- config = LoggingConfig.from_env()
+ config = config or LoggingConfig.from_env()
- # Aggregate arguments + env config
- level = logging.DEBUG if debug else level or config.level
- log_dir = log_dir or config.log_dir
- log_format = log_format or (LogFormatName.DEBUG if debug else config.log_format)
- log_file_format = log_file_format or log_format or config.log_file_format
- plain_console_output = (
+ # Aggregate env config + arguments
+ config.level = logging.DEBUG if debug else level or config.level
+ config.log_dir = log_dir or config.log_dir
+ config.log_format = log_format or (
+ LogFormatName.DEBUG if debug else config.log_format
+ )
+ config.log_file_format = log_file_format or log_format or config.log_file_format
+ config.plain_console_output = (
plain_console_output
if plain_console_output is not None
else config.plain_console_output
@@ -127,17 +131,17 @@ def configure_logging(
# Structured logging is used for cloud environments,
# where logging to a file makes no sense.
if log_format == LogFormatName.STRUCTURED:
- plain_console_output = True
- log_file_format = None
+ config.plain_console_output = True
+ config.log_file_format = None
# create log directory if it doesn't exist
- if not log_dir.exists():
- log_dir.mkdir()
+ if not config.log_dir.exists():
+ config.log_dir.mkdir()
log_handlers: list[logging.Handler] = []
- if log_format in (LogFormatName.DEBUG, LogFormatName.SIMPLE):
- console_format_template = TEXT_LOG_FORMAT_MAP[log_format]
+ if config.log_format in (LogFormatName.DEBUG, LogFormatName.SIMPLE):
+ console_format_template = TEXT_LOG_FORMAT_MAP[config.log_format]
console_formatter = AutoGptFormatter(console_format_template)
else:
console_formatter = StructuredLoggingFormatter()
@@ -145,7 +149,7 @@ def configure_logging(
# Console output handlers
stdout = logging.StreamHandler(stream=sys.stdout)
- stdout.setLevel(level)
+ stdout.setLevel(config.level)
stdout.addFilter(BelowLevelFilter(logging.WARNING))
stdout.setFormatter(console_formatter)
stderr = logging.StreamHandler()
@@ -162,7 +166,7 @@ def configure_logging(
user_friendly_output_logger = logging.getLogger(USER_FRIENDLY_OUTPUT_LOGGER)
user_friendly_output_logger.setLevel(logging.INFO)
user_friendly_output_logger.addHandler(
- typing_console_handler if not plain_console_output else stdout
+ typing_console_handler if not config.plain_console_output else stdout
)
if tts_config:
user_friendly_output_logger.addHandler(TTSHandler(tts_config))
@@ -170,22 +174,26 @@ def configure_logging(
user_friendly_output_logger.propagate = False
# File output handlers
- if log_file_format is not None:
- if level < logging.ERROR:
- file_output_format_template = TEXT_LOG_FORMAT_MAP[log_file_format]
+ if config.log_file_format is not None:
+ if config.level < logging.ERROR:
+ file_output_format_template = TEXT_LOG_FORMAT_MAP[config.log_file_format]
file_output_formatter = AutoGptFormatter(
file_output_format_template, no_color=True
)
# INFO log file handler
- activity_log_handler = logging.FileHandler(log_dir / LOG_FILE, "a", "utf-8")
- activity_log_handler.setLevel(level)
+ activity_log_handler = logging.FileHandler(
+ config.log_dir / LOG_FILE, "a", "utf-8"
+ )
+ activity_log_handler.setLevel(config.level)
activity_log_handler.setFormatter(file_output_formatter)
log_handlers += [activity_log_handler]
user_friendly_output_logger.addHandler(activity_log_handler)
# ERROR log file handler
- error_log_handler = logging.FileHandler(log_dir / ERROR_LOG_FILE, "a", "utf-8")
+ error_log_handler = logging.FileHandler(
+ config.log_dir / ERROR_LOG_FILE, "a", "utf-8"
+ )
error_log_handler.setLevel(logging.ERROR)
error_log_handler.setFormatter(
AutoGptFormatter(DEBUG_LOG_FORMAT, no_color=True)
@@ -196,7 +204,7 @@ def configure_logging(
# Configure the root logger
logging.basicConfig(
format=console_format_template,
- level=level,
+ level=config.level,
handlers=log_handlers,
)